一、安装

1.下载对应版本的ActiveMQ(http://archive.apache.org/dist/activemq/)
2.解压文件(tar -zxvf apache-activemq-5.16.1-bin.tar.gz)
3.将解压后的文件夹移动到需要的目录

mv  apache-activemq-5.16.1 /usr/local/

4.进入bin下即可启动(./activemq start)

./activemq start

二、配置

1.远程访问

1.修改配置文件中的host地址(conf/jetty.xml)

<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
             <!-- the default port number for the web console -->
        <property name="host" value="127.0.0.0"/>
        <property name="port" value="8161"/>
    </bean>

修改host对应的ip地址。也可以改成0.0.0.0(创建docker镜像的时候改为0.0.0.0,否则无法从外部浏览器查看消息队列)

2.开放防火墙对应端口

//8161是管理的端口
firewall-cmd --zone=public --add-port=8161/tcp --permanent
//61616是通信的端口
firewall-cmd --zone=public --add-port=61616/tcp --permanent
//重新载入
firewall-cmd --reload
//查看是否设置成功
firewall-cmd --zone=public --list-ports

3.重启activemq服务

./activemq restart
至此,可以在其他电脑上通过http://ip:8161访问当前电脑上的activemq了。

2.设置activemq开机自启动

1.创建脚本

vim /etc/init.d/activemq

2.编辑脚本(注意修改JAVA_HOME和MQ_HOME的值

#!/bin/bash
# chkconfig: 2345 10 90 
# description: activemq ....
prog=activemq
JAVA_HOME=/home/xxxx/SoftWare/jdk1.8.0_40
export JAVA_HOME
MQ_HOME=/usr/local/apache-activemq-5.16.1
export MQ_HOME 
case "$1" in
start)
   echo "Starting $prog..."
   $MQ_HOME/bin/activemq start
   ;;
stop)
  echo "Stopping $prog..."
   $MQ_HOME/bin/activemq stop
   ;;
restart)
   echo "Stopping $prog..."
   $MQ_HOME/bin/activemq stop
   sleep 2
   echo
   echo "Starting $prog..."
   $MQ_HOME/bin/activemq start
   ;;
*)
   echo "Usage: $prog {start|stop|restart}"
   ;;
esac
exit

3.赋予该脚本可执行权限

chmod +x /etc/init.d/activemq

4.添加到开机启动

chkconfig  --add activemq
#软链接
ln -s /etc/init.d/activemq    /etc/rc3.d/activemq

5.操作ActiveMQ

    # service activemq start
    # service activemq status
    # service activemq stop
    
chkconfig和service命令的区别
chkconfig是当前不生效,Linux重启之后才生效的命令(开机自启动项)
service是即使生效,重启后失效的命令