ActiveMQ的安裝與使用

轉自吳水成視頻

ActiveMQ 的安裝與使用(單節點)

IP:192.168.4.101

 

環境:CentOS 6.6、JDK7

 

 

1、 安裝 JDK 並配置環境變量(略)

 

JAVA_HOME=/usr/local/java/jdk1.7.0_72

 

 

2、 下載 Linux 版的 ActiveMQ(當前最新版 apache-activemq-5.11.1-bin.tar.gz

 

wget http://apache.fayea.com/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gz

 

 

3、 解壓安裝

 

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

 

mv apache-activemq-5.11.1 activemq-01

 

如果啓動腳本 activemq 沒有可執行權限,此時則需要授權(此步可選)

 

cd /home/wusc/activemq-01/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 /home/wusc/activemq-01/bin $ ./activemq start


 

6、 打開管理界面:http://192.168.4.101:8161



默認用戶名和密碼爲:admin/admin




7、 安全配置(消息安全)

 

ActiveMQ 如果不加入安全機制的話,任何人只要知道消息服務的具體地址(包括 ip,端口,消息地址

 

[ 隊列或者主題地址 ] , ) , 都可以肆無忌憚的發送、接收消息。關於  ActiveMQ  安裝配置

 

http://activemq.apache.org/security.html


ActiveMQ 的消息安全配置策略有多種,我們以簡單授權配置爲例:

 

在 conf/activemq.xml 文件中在 broker 標籤最後加入以下內容即可

 

vi /home/wusc/activemq-01/conf/activemq.xml

 

<plugins>

 

<simpleAuthenticationPlugin>

 

<users>

 

<authenticationUser username="wusc" password="wusc.123" groups="users,admins"/>

 

</users>

 

</simpleAuthenticationPlugin>

 

</plugins>

 

定義了一個 wusc 用戶,密碼爲 wusc.123,角色爲 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: wusc.123, admin

 

 

注意:用戶名和密碼的格式是

 

用戶名 : 密碼 ,角色名

 

 

重啓:

 

/home/wusc/activemq-01/bin/activemq restart

 

 

設置開機啓動:

 

vi /etc/rc.local

 

加入以下內容

 

## ActiveMQ

 

su - wusc -c '/home/wusc/activemq-01/bin/activemq start'

 

 

8、 MQ 消息生產者也與消息消費者的 Demo 樣例講解與演示

 

具體內容請參考樣例代碼和視頻教程


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章