メモ
前提
- Java がインストール済みである
手順
-
ActiveMQ の実行用ユーザを作成する
# useradd activemq
-
必要なディレクトリを作成する
# mkdir -p /var/log/activemq /var/lib/activemq
-
ActiveMQ のバイナリをあらかじめダウンロードしておくか、次のコマンドでダウンロードする
# curl -LkvOf https://archive.apache.org/dist/activemq/5.15.14/apache-activemq-5.15.14-bin.tar.gz
-
展開する
# tar zxvf apache-activemq-5.15.14-bin.tar.gz -C /opt/
-
シンボリックリンクをはっておく
# ln -s /opt/apache-activemq-5.15.14 /opt/activemq
-
ログファイルの出力先を変更します。
# vi /opt/activemq/conf/log4j.properties
実行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
-
設定ファイルを編集
# 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 #作成したディレクトリ内に配置するように変更
...
```
-
環境変数を一部変更
# 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" #作成したディレクトリ内に配置するように変更
-
各種ファイルなどの所有者を実行用ユーザに変更する
# chown -R activemq:activemq /opt/activemq/ /var/log/activemq/ /var/lib/activemq/
-
ActiveMQ 用のサービスファイルを作成する
# 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.target
-
サービスファイルを読み込んで起動する
# systemctl daemon-reload \
&& systemctl start activemq
```