1. 程式人生 > >activemq的安裝與使用

activemq的安裝與使用

密碼 jetty 安全配置 user inpu word ber 登錄用戶 dem

一、activemq的安裝

環境:CentOS 6、JDK8
1、 確保系統已安裝了可用的jdk版本
2、 從網上下載 Linux 版的 ActiveMQ( apache-activemq-5.11.1-bin.tar.gz),然後使用xftp上傳到linux虛擬機已經建好的文件夾下

技術分享

3、 解壓安裝
# tar -zxvf apache-activemq-5.11.1-bin.tar.gz
# mv apache-activemq-5.11.1 activemq
如果啟動腳本 activemq 沒有可執行權限,此時則需要授權(此步可選)
# cd activemq/bin/
# chmod 755 ./activemq
4、 防火墻中打開對應的端口
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
5、 啟動
# cd /software/activemq/bin
# ./activemq start
6、 打開管理界面:http://192.168.152.129:8161/ 首次進入默認用戶名和密碼為:admin/admin

技術分享

技術分享

7、 安全配置(消息安全)
ActiveMQ 如果不加入安全機制的話,任何人只要知道消息服務的具體地址(包括 ip,端口,消息地址
[隊列或者主題地址],), 都可以肆無忌憚的 發送、 接收消息。 關 於 ActiveMQ 安裝配置
http://activemq.apache.org/security.html

ActiveMQ 的消息安全配置策略有多種,我們以簡單授權配置為例:
在 conf/activemq.xml 文件中在 broker 標簽最後加入以下內容即可:
# vi /software/activemq/conf/activemq.xml

<plugins>
<simpleAuthenticationPlugin>
<users>
<authenticationUser username="lgs" password="lgs.123" groups="users,admins"/>
</users>
</simpleAuthenticationPlugin>
</plugins>
定義了一個 lgs用戶,密碼為 lgs.123,角色為 users,admins

設置 admin 的用戶名和密碼:
# vi /software/activemq/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 /software/activemq/conf/jetty-realm.properties
# Defines users that can access the web (console, demo, etc.)
# username: password [,rolename ...]
admin: admin, admin
註意:用戶名和密碼的格式是
用戶名 : 密碼 ,角色名

重啟:
# vi /software/activemq/bin/activemq restart
設置開機啟動:
# vi /etc/rc.local
加入以下內容
## ActiveMQ
su - lgs -c ‘/software/activemq/bin/activemq start

activemq的安裝與使用