目录
更改目录“/opt/apache-artemis-2.12.0”的所有权
本文是“企业数据总线系统”研究的一部分。这项特殊的研究将ActiveMQ-Artemis(此后称为Artemis)选为集中式消息中心,供系统中所有进程使用Artemis支持的协议之一相互通信。在本文中,我将讨论在ARM64计算机上运行的Linux Ubuntu 18.04.x OS上安装/配置Artemis的过程。
假设/期望
Linux命令和Vim
我假设本文的读者对Linux shell和命令有一定的了解,并且对所用Linux命令的解释不在本文的讨论范围之内。除非另有说明,否则Linux命令将在终端中运行。
我正在使用vim编辑器进行文本编辑,但是读者可以使用他们想要的任何其他文本编辑器。
“root”用户
本文中的所有命令均由root用户发出。
背景
面向消息的中间件(MoM)
面向消息的中间件(MoM)是在分布式系统之间支持,发送和接收消息的软件或硬件基础结构。
为什么要使用MoM?
MoM允许将应用程序模块分布在异构平台上,并降低了开发跨越多个操作系统\网络协议和编程语言的应用程序的复杂性。MoM通过提供可靠性、事务处理和许多其他功能,使系统中的进程能够通过定义明确的协议之一进行通信。
Apache ActiveMQ Artemis
Apache ActiveMQ Artemis(Artemis)是异步消息传递系统,并且是MoM系统的软件实现。Artemis能够通过正在运行的代理实例协调分布式系统中进程之间的消息传递流量。
Artemis支持的消息协议
Artemis支持以下协议:
- MPQOpenWire
- MQTT
- STOMP
- HornetQ(用于HornetQ客户端)
- Core(Artemis CORE协议)
例如,在三层系统中,可能有一些用Java,C / C ++,Python编写的进程。GoLang,nodejs等在前端,中间层和后端分布式运行。这些进程可以通过将其自身注册到命名队列或主题以发送/接收消息来相互通信(例如,使用STOMP协议)。
系统信息
- 硬件:Odroid N2(ARM 64)
- 操作系统:Ubuntu 18.04.4 LTS(Bionic Beaver)
JAVA(openjdk-11)安装
Artemis需要JRE(至少具有版本8)才能运行。以下是openjdk-11安装/配置的过程。
安装:
sudo apt install openjdk-11-jdk
校验:
which java
/usr/bin/java
java --version
openjdk 11.0.7 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-2ubuntu218.04)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-2ubuntu218.04, mixed mode)
安装后配置:设置JAVA_HOME环境变量
Artemis要求JAVA_HOME设置环境。以下是在/etc/bash.bashrc中进行设置并激活它的步骤。
确定JDK安装目录的绝对路径
在Ubuntu中,jdks安装在/usr/lib/jvm下。jdk构建中的二进制文件是特定于平台的;因此,该JAVA_HOME变量必须指向特定于平台的已安装JDK(在这种情况下,该平台为ARM64)。
这是/usr/lib/jvm应有的样子:
pwd
/usr/lib/jvm
ls
java-1.11.0-openjdk-arm64 java-11-openjdk-arm64 openjdk-11
java-1.11.0-openjdk-arm64 java-11-openjdk-arm64 openjdk-11
因此,JAVA_HOME应将环境变量设置为“/usr/lib/jvm”。
在/etc/bash.bashrc中设置JAVA_HOME
编辑文件/etc/bash.bashrc:
vim /etc/bash.bashrc
添加以下行(在此文件的底部):
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-arm64
源脚本:
source /etc/bash.bashrc
验证变量的值:
echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-arm64
2. ActiveMQ-Artemis安装/配置
从Apache.org下载Artemis
打开Web浏览器并指向以下URL:
http://activemq.apache.org/components/artemis/download/
源包和二进制包的URL:
http://activemq.apache.org/components/artemis/download/
图1:ActiveMQ Artemis下载页面
注意事项:
- 我在本教程中使用了tar包(此示例中的文件位于/media/SDA1中)。
- ActiveMQ服务器及其代理将安装在“/opt ”目录中。
- 我将使用的经纪人名称为`ActiveMQ-Odroid-110`。
提取下载的捆绑包
pwd
/opt
tar -xzf /media/SDA1/apache-artemis-2.12.0-bin.tar.gz
校验:
ls
(among other things…) apache-artemis-2.12.0
创建一个新的Linux用户组`activemq`
addgroup --quiet --system activemq
创建一个新的Linux用户`activemq`
adduser --quiet --system --ingroup activemq \
--no-create-home --disabled-password activemq
更改目录“/opt/apache-artemis-2.12.0”的所有权
chown -R activemq:activemq /opt/activemq
导航到“bin”目录
cd apache-artemis-2.12.0/bin
校验:
./artemis
如果看到以下输出,则表明已准备好安装代理:
usage: artemis <command> [<args>]
The most commonly used artemis commands are:
address Address tools group (create|delete|update|show)
(example ./artemis address create)
browser It will browse messages on an instance
consumer It will consume messages from an instance
create creates a new broker instance
data data tools group (print) (example ./artemis data print)
help Display help information
mask mask a password and print it out
migrate1x Migrates the configuration of a 1.x Artemis Broker
producer It will send messages to an instance
queue Queue tools group (create|delete|update|stat|purge)
(example ./artemis queue create)
See 'artemis help <command>' for more information on a specific command.
创建代理
在此示例中,代理将具有以下属性:
- 名称:ActiveMQ-Odroid-110
- 管理员UID:admin
- 管理员密码:admin
./artemis create ActiveMQ-Odroid-110 --user=admin --password=admin \
--http-host 0.0.0.0 --relax-jolokia
...安装将出现一个额外的提示(只需键入“Y”,然后按Enter):
--allow-anonymous | --require-login: is a mandatory property!
Allow anonymous access?, valid values are Y,N,True,False
Y <--- Enter
其余输出:
Auto tuning journal ...
done! Your system can make 1.61 writes per millisecond,
your journal-buffer-timeout will be 620000
You can now start the broker by executing:
"/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis" run
Or you can run the broker in the background using:
"/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis-service" start
"/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis-service"
Usage: ./artemis-service {start|stop|restart|force-stop|status}
启动代理实例
现在,我们准备运行代理:
测试运行#1:手动启动代理进行测试运行
"/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis" run
现在,打开Web浏览器并将其指向以下网站:
http://<IP of the broker>:8161
如果您看到以下网页,则代理实例已启动并成功运行:
图2:ActiveMQ初始网页
单击“管理控制台”链接以打开登录页面(注意:先前在创建代理程序时指定的用户名= admin,密码= admin)。
图3:ActiveMQ登录页面
ActiveMQ管理控制台初始页:
图4:ActiveMQ管理控制台初始页面
恭喜,您已经成功安装了第一个ActiveMQ代理!
测试运行2:启动代理作为守护程序进程
要将代理作为后台服务运行,请首先杀死代理的当前实例(即,运行代理的控制台上的Ctrl + C),然后运行以下命令:
"/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis-service" start
输出:
Starting artemis-service
artemis-service is now running (14289)
校验:
ps -ef| grep 14289
输出:
root 14289 1 10 18:18 pts/0 00:00:23 /usr/lib/jvm/java-11-openjdk-arm64/bin/java
-XX:+PrintClassHistogram -XX:+UseG1GC -XX:+UseStringDeduplication -Xms512M -Xmx2G
-Dhawtio.realm=activemq -Dhawtio.offline=true -Dhawtio.role=amq
-Dhawtio.rolePrincipalClasses=org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal
-Djolokia.policyLocation=file:/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/etc/jolokia-
access.xml -Xbootclasspath/a:/opt/apache-artemis-2.12.0/lib/jboss-logmanager-2.1.10.Final.jar:
/opt/apache-artemis-2.12.0/lib/wildfly-common-1.5.2.Final.jar
-Djava.security.auth.login.config=/opt
/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/etc/login.config
-classpath /opt/apache-artemis-2.12.0
/lib/artemis-boot.jar -Dartemis.home=/opt/apache-artemis-2.12.0 -Dartemis.instance=/opt/apache-
artemis-2.12.0/bin/ActiveMQ-Odroid-110
-Djava.library.path=/opt/apache-artemis-2.12.0/bin/lib/linux-
aarch64 -Djava.io.tmpdir=/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/tmp -Ddata.dir=/opt
/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/data -Dartemis.instance.etc=/opt/apache-artemis-
2.12.0/bin/ActiveMQ-Odroid-110/etc -Djava.util.logging.manager=org.jboss.logmanager.LogManager
-Dlogging.configuration=file:/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/etc
//logging.properties org.apache.activemq.artemis.boot.Artemis run
再次注销/登录到Web控制台,以确保一切仍然正常。
现在,停止守护进程:
"/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis-service" stop
至此,我们准备为代理实例创建一个新的systemd服务。
为代理创建系统服务
至此,我们已经在地面和守护程序处理模式下测试了代理。但是,在这些模式下,该过程将无法在系统重新启动后继续存在。为了防止每次系统重新启动时手动重新启动代理进程,我们需要创建一个系统服务,并让Linux操作系统自动处理所有启动/停止操作。
创建系统服务脚本
touch /etc/systemd/system/activemq-artemis.service
chmod 644 /etc/systemd/system/activemq-artemis.service
vim /etc/systemd/system/activemq-artemis.service
将以下行添加到文件中:
[Unit]
Description=Apache ActiveMQ Artemis
After=network.target
[Service]
Type=forking
User=activemq
Group=activemq
ExecStart=/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis-service start
ExecStop=/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis-service stop
[Install]
WantedBy=multi-user.target
加载/启动服务:
systemctl daemon-reload
systemctl start activemq-artemis
启用服务(以便它可以在系统重新启动后幸存):
systemctl enable activemq-artemis
输出:
Created symlink /etc/systemd/system/multi-user.target.wants/
activemq-artemis.service → /etc/systemd
/system/activemq-artemis.
通过系统服务进行验证:
systemctl status activemq-artemis
输出应类似于以下内容:
Loaded: loaded (/etc/systemd/system/activemq-artemis.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2020-05-02 16:17:52 UTC; 34s ago
Process: 2894
ExecStart=/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis-service start
(code=exited, sta
Main PID: 2919 (java)
Tasks: 50 (limit: 3838)
CGroup: /system.slice/activemq-odroid-110.service
└─2919 java -XX:+PrintClassHistogram -XX:+UseG1GC
-XX:+UseStringDeduplication -Xms512M -Xmx2G -Dhawtio.realm=
May 02 16:17:30 odroid systemd[1]: Starting Apache ActiveMQ Artemis...
May 02 16:17:30 odroid artemis-service[2894]: Starting artemis-service
May 02 16:17:52 odroid artemis-service[2894]: artemis-service is now running (2919)
May 02 16:17:52 odroid systemd[1]: Started Apache ActiveMQ Artemis.
(可选)使用代理的状态报告进行验证:
/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis-service status
输出应类似于以下内容:
artemis-service is running (16934)
测试系统停止服务:
systemctl stop activemq-odroid-110
通过系统服务进行验证:
systemctl status activemq-odroid-110
在过去的几行输出应该类似于如下:
May 02 16:35:13 odroid artemis-service[4031]: Gracefully Stopping artemis-service
May 02 16:35:14 odroid systemd[1]: activemq-odroid-110.service:
Main process exited, code=exited, status=143/n/a
May 02 16:35:14 odroid systemd[1]: activemq-odroid-110.service:
Failed with result 'exit-code'.
May 02 16:35:14 odroid systemd[1]: Stopped Apache ActiveMQ Artemis.
验证与代理的状态报告:
/opt/apache-artemis-2.12.0/bin/ActiveMQ-Odroid-110/bin/artemis-service status
输出应类似于以下内容:
artemis-service is stopped
关于创建其他代理的说明
Artemis支持在同一主机上同时运行的多个代理,因此可以按照本教程中的过程创建所需的其他代理。
到此结束在Linux Ubuntu / ARM64系统上安装Apache-Artemis的过程。