目錄
更改目錄“/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的過程。