備忘録

備忘録

CentOSにActiveMQをインストールする方法

Ⅰ. はじめに

タイトルの通り「CentOSActiveMQをインストールする方法」です。

Ⅱ. インストール方法

環境
$ cat /etc/redhat-release 
CentOS Linux release 7.6.1810 (Core)
1. JRE をインストールする
yum install -y java-1.8.0-openjdk
echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | sudo tee -a /etc/profile
source /etc/profile
2. ActiveMQ をダウンロード、展開する

以下から最新版バイナリのURLを取得します
http://activemq.apache.org/download

wget http://ftp.meisei-u.ac.jp/mirror/apache/dist/activemq/5.15.9/apache-activemq-5.15.9-bin.tar.gz
tar zxvf apache-activemq-5.15.9-bin.tar.gz -C /opt
3. systemd ユニットファイルを作成する
sudo ln -s /opt/apache-activemq-5.15.9 /opt/activemq
vim /usr/lib/systemd/system/activemq.service

activemq.service

[Unit]
Description=activemq message queue
After=network.target
[Service]
PIDFile=/opt/activemq/data/activemq.pid
ExecStart=/opt/activemq/bin/activemq start
ExecStop=/opt/activemq/bin/activemq stop
User=root
Group=root
[Install]
WantedBy=multi-user.target

Ⅲ. 動作テスト

1. ActiveMQ を起動する
# systemctl enable activemq.service
systemctl start activemq.service
2. Consumer を起動する
cd /opt/activemq
./bin/activemq consumer --brokerUrl failover://tcp://127.0.0.1:61616 --destination queue://test001
3. Web管理画面を開く

http://127.0.0.1:8161/admin

User admin
Password admin
4. メッセージを送信する

f:id:kagasu:20190408195546p:plain
f:id:kagasu:20190408195618p:plain

5. 実行結果

f:id:kagasu:20190408195831p:plain

FAQ

Q1. Web管理画面の資格情報を変更したい

A. 以下のファイルを変更する

/opt/activemq/conf/jetty-realm.properties
Q2. MessageBroker の資格情報を変更したい

A. 以下のファイルを変更する
/opt/activemq/conf/activemq.xml

<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}">
  <plugins>
    <simpleAuthenticationPlugin anonymousAccessAllowed="false">
      <users>
        <authenticationUser username="admin" password="password1" groups="users,admins"/>
        <authenticationUser username="user" password="password2" groups="users"/>
        <authenticationUser username="guest" password="password3" groups="guests"/>
      </users>
    </simpleAuthenticationPlugin>
  </plugins>
</broker>