安装JDK并配置环境变量(略)html
JAVA_HOME=/home/huangkejie/java/jdk1.8.0_171java
在home/huangkejie下建立activeMQ目录web
$ mkdir activeMQapache
$ cd activeMQ安全
下载Linux版的ActiveMQ(当前最新版apache-activemq-5.11.1-bin.tar.gz)eclipse
$ wget http://apache.fayea.com/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gztcp
解压安装spa
$ tar -zxvf apache-activemq-5.11.1-bin.tar.gzrest
$ mv apache-activemq-5.11.1 activemqxml
若是启动脚本activemq没有可执行权限,此时则须要受权(此步可选)
$ cd /home/huangkejie/activemq/bin/
$ chmod 777 ./activemq
防火墙中打开对应的端口
ActiveMQ须要用到两个端口
一个是消息通信的端口(默认为61616)
一个是管理控制台端口(默认为8161)可在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="0.0.0.0"/>
<property name="port" value="8161"/>
</bean>
# vi /etc/sysconfig/iptables
添加:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 61616 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 8161 -j ACCEPT
重启防火墙:
# service iptables restart
启动
$ cd /home/huangkejie/activemq/bin
$ ./activemq start
打开管理界面:http://192.168.186.134:8161
点击Manage ActiveMQ broker超连接输入默认用户名和密码为:admin/admin
登陆后进入
安全配置(消息安全)
ActiveMQ若是不加入安全机制的话,任何人只要知道消息服务的具体地址(包括ip,端口,消息地址[队列或者主题地址],),均可以肆无忌惮的发送、接收消息。关于ActiveMQ安装配置http://activemq.apache.org/security.html
ActiveMQ的消息安全配置策略有多种,咱们以简单受权配置为例:
在conf/activemq.xml文件中在broker结束标签前加入如下内容便可:
$ vi /home/huangkejie/activemq/conf/activemq.xml
<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="huangkejie" password="huangkejie" groups="users,admins"/>
</users>
</simpleAuthenticationPlugin>
</plugins>
定义了一个huangkejie用户,密码为huangkejie,角色为users,admins
设置admin的用户名和密码:
$ vi /home/wusc/activemq-01/conf/jetty.xml
<bean id="securityConstraint" class="org.eclipse.jetty.util.security.Constraint">
<property name="name" value="BASIC" />
<property name="roles" value="admin" />
<property name="authenticate" value="true" />
</bean>
确保authenticate的值为true(默认)
控制台的登陆用户名密码保存在conf/jetty-realm.properties文件中,内容以下:
$ vi /home/wusc/activemq-01/conf/jetty-realm.properties
# Defines users that can access the web (console, demo, etc.)
# username: password [,rolename ...]
注意:用户名和密码的格式是
用户名 : 密码 ,角色名
以上的截图能够看出我修改了admin的密码为huangkejie,新增了huangkejie的用户,密码为huangkejie,角色为admin
重启:
$ /home/huangkejie/activemq/bin/activemq restart
设置开机启动:
# vi /etc/rc.local
加入如下内容
## ActiveMQ
su - huangkejie -c '/home/huangkejie/activemq/bin/activemq start'