ActiveMQ のインストール (Ubuntu)
はじめに
このページでは ActiveMQ のインストール手順について説明します。
以下は、 Ubuntu 18.04 にて実施した手順を紹介します。
1.JAVA_HOME 環境変数の設定
JAVA_HOME を設定していない場合は、次のコマンドを実行して JAVA_HOME の環境変数を設定します。
実行コマンド
$ echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:/bin/java::")" | sudo tee -a /etc/profile \
&& source /etc/profile2.実行用ユーザの作成
次のコマンドで activemq の実行用ユーザを作成します。
実行コマンド
$ sudo useradd activemq3.ActiveMQ のインストール
ActiveMQ のログとデータディレクトリを作成します
実行コマンド
$ sudo mkdir -p /var/log/activemq \
&& sudo mkdir -p /var/lib/activemqActiveMQ の TAR ファイルをダウンロードします。
実行コマンド
$ sudo curl -LkOf https://archive.apache.org/dist/activemq/5.15.14/apache-activemq-5.15.14-bin.tar.gz破損がないか確認します。(ハッシュ値は ダウンロードページ に記載されています)
実行コマンド
$ sha512sum apache-activemq-5.15.14-bin.tar.gz実行結果
5708ed926988e4796a8badaed3dafd32bcbc47890169df2712568ad706858370b20e5cd9a4e3298521692151e63a5ac6d06866b3ad188aa0e36b28e370240d5c apache-activemq-5.15.14-bin.tar.gzTAR ファイルを展開します
実行コマンド
$ sudo tar zxvf apache-activemq-5.15.14-bin.tar.gz -C /opt/シンボリックリンクを作成します
実行コマンド
$ sudo ln -s /opt/apache-activemq-5.15.14 /opt/activemqログ出力先を変更します
実行コマンド
$ sudo vi /opt/activemq/conf/log4j.propertiesvi コマンド実行後に実施するVimコマンド
:%s/${activemq.data}/\/var\/log\/activemq/g編集内容
# File appender
log4j.appender.logfile=org.apache.log4j.RollingFileAppender
log4j.appender.logfile.file=/var/log/activemq/activemq.log ←変更
log4j.appender.logfile.maxFileSize=1024KB
log4j.appender.logfile.maxBackupIndex=5
log4j.appender.logfile.append=true
log4j.appender.logfile.layout=org.apache.log4j.PatternLayout
log4j.appender.logfile.layout.ConversionPattern=%d | %-5p | %m | %c | %t%n
###########
# Audit log
###########
log4j.additivity.org.apache.activemq.audit=false
log4j.logger.org.apache.activemq.audit=INFO, audit
log4j.appender.audit=org.apache.log4j.RollingFileAppender
log4j.appender.audit.file=/var/log/activemq/audit.log ←変更
log4j.appender.audit.maxFileSize=1024KB
log4j.appender.audit.maxBackupIndex=5
log4j.appender.audit.append=true
log4j.appender.audit.layout=org.apache.log4j.PatternLayout
log4j.appender.audit.layout.ConversionPattern=%-5p | %m | %t%nログ及びデータ格納先を変更します
実行コマンド
$ sudo vi /opt/activemq/bin/linux-x86-64/wrapper.conf編集内容
#********************************************************************
# Wrapper Properties
#********************************************************************
#wrapper.debug=TRUE
set.default.ACTIVEMQ_HOME=../..
set.default.ACTIVEMQ_BASE=../..
set.default.ACTIVEMQ_CONF=%ACTIVEMQ_BASE%/conf
set.default.ACTIVEMQ_DATA=/var/lib/activemq ←変更
wrapper.working.dir=.
(中略)
#********************************************************************
# Wrapper Logging Properties
#********************************************************************
# Format of output for the console. (See docs for formats)
wrapper.console.format=PM
# Log Level for console output. (See docs for log levels)
wrapper.console.loglevel=INFO
# Log file to use for wrapper output logging.
wrapper.logfile=/var/log/activemq/wrapper.log ←変更
(省略)env ファイルを編集して、実行ユーザ及び pid ファイルの設定を追記します
実行コマンド
$ sudo vi /opt/activemq/bin/env編集内容
# Configure a user with non root privileges, if no user is specified do not change user
# (the entire activemq installation should be owned by this user)
ACTIVEMQ_USER="activemq" ←変更
# location of the pidfile
ACTIVEMQ_PIDFILE="/opt/activemq/data/activemq.pid" ←変更所有者を実行ユーザに変更します
実行コマンド
$ sudo chown -R activemq:activemq /opt/activemq/ /var/log/activemq/ /var/lib/activemq/サービスファイルを作成します
実行コマンド
$ sudo vi /etc/systemd/system/activemq.service編集内容
[Unit]
Description=ActiveMQ message queue service
After=network.target
[Service]
User=activemq
Group=activemq
PIDFile=/opt/activemq/data/activemq.pid
ExecStart=/opt/activemq/bin/activemq start
ExecStop=/opt/activemq/bin/activemq stop
[Install]
WantedBy=multi-user.targetActiveMQ を起動します
実行コマンド
$ sudo systemctl daemon-reload \
&& sudo systemctl start activemqActiveMQ の自動起動を設定します
実行コマンド
$ sudo systemctl enable activemq