【1】下载二进制安装包

下载地址:​​http://activemq.apache.org/activemq-5152-release.html​

CentOS7下安装ActiveMQ并注册服务设置开机启动_linux


【2】解压安装

上传到服务器/usr/local路径下,解压:

tar -zxvf apache-activemq-5.15.2-bin.tar.gz

CentOS7下安装ActiveMQ并注册服务设置开机启动_apache_02


进入文件夹,其内容如下:

CentOS7下安装ActiveMQ并注册服务设置开机启动_开机启动_03


【3】启动ActiveMQ

bin目录启动:

bin/activemq start

CentOS7下安装ActiveMQ并注册服务设置开机启动_centos_04


如果提示没权限,使用如下命令:

chmod 755 ../../

【4】测试安装

ActiveMQ默认使用61616作为服务端口,8161作为管理监听端口。

终端使用命令测试:

CentOS7下安装ActiveMQ并注册服务设置开机启动_linux_05


本地使用浏览器访问管理地址:

CentOS7下安装ActiveMQ并注册服务设置开机启动_apache_06

默认用户名密码为: admin admin

如果浏览器访问不了,试试在防火墙上面开启端口8161。


【5】添加用户

参考页面:​​http://activemq.apache.org/security.html​

修改activemq.xml:

在broker标签内部添加配置如下:

<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="hh_mq" password="hh_mq@123456" groups="users,admins"/>
</users>
</simpleAuthenticationPlugin>
</plugins>

CentOS7下安装ActiveMQ并注册服务设置开机启动_开机启动_07

重新启动ActiveMQ。


【6】添加软链,任意位置启动ActiveMQ

命令如下:

ln -s /usr/local/apache-activemq-5.15.2/bin/activemq /usr/bin/

【7】注册服务并设置开机启动

在/etc/init.d/下添加activemq文件:

#!/bin/sh
#
# /etc/init.d/activemq
# chkconfig: 345 63 37
# description: activemq servlet container.
# processname: activemq 5.15.2

# Source function library.
#. /etc/init.d/functions
# source networking configuration.
#. /etc/sysconfig/network

export JAVA_HOME=/usr/local/jdk1.8.0_144
export ACTIVEMQ_HOME=/usr/local/apache-activemq-5.15.2

case $1 in
start)
sh $ACTIVEMQ_HOME/bin/activemq start
;;
stop)
sh $ACTIVEMQ_HOME/bin/activemq stop
;;
status)
sh $ACTIVEMQ_HOME/bin/activemq status
;;
restart)
sh $ACTIVEMQ_HOME/bin/activemq stop
sleep 1
sh $ACTIVEMQ_HOME/bin/activemq start
;;

esac
exit 0

对文件赋予权限:

chmod 777 /etc/init.d/activemq

设置开机启动:

chkconfig activemq on

查看开机启动服务列表:

chkconfig –list

CentOS7下安装ActiveMQ并注册服务设置开机启动_apache_08


关闭开机启动:

chkconfig activemq off

启动activemq:

service activemq start

关闭activemq:

service activemq stop

查看activemq状态:

service activemq status

重启activemq:

service activemq restart

测试开机启动:

reboot