OS: Debian or SuSEmysql
ACTIVEMQ: 5.4.2web
JDK: 1.6.0_27spring
參考 http://wiki.tomshopping.com/pages/viewpage.action?pageId=14288188sql
mkdir -p /data/postmall/activemq/data && chown -R web.users /data/postmall/activemq/data數據庫
mkdir -p /data/logs/activemq && chown -R web.users /data/logs/activemqapache
3.1. 下載並安裝activemqbash
# cd /data/postmall/steve服務器
# wget http://archive.apache.org/dist/activemq/apache-activemq/5.4.2/apache-activemq-5.4.2-bin.tar.gz架構
# tar zxvf apache-activemq-5.4.2-bin.tar.gzapp
# cd /usr/local
# cp -r /data/postmall/steve/apache-activemq-5.4.2-bin activemq
# chown -R web.users /usr/local/activemq
3.2. 配置activemq
目前郵樂平臺採用的activemq,均使用mysql database鏈接方式
# vi /usr/local/activemq/conf/activemq.xml
將下面這段
<bean id="mysql-ds" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://172.24.154.149:3306/activemq3?relaxAutoCommit=true"/> #activemq3 爲數據庫名稱
<property name="username" value="activemq"/>
<property name="password" value="uleQueue"/>
<property name="maxActive" value="200"/>
</bean>
放到
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>file:${activemq.base}/conf/credentials.properties</value>
</property>
</bean>
後面
註釋掉kahadb 這段,以下:
<!--
<persistenceAdapter>
<kahaDB directory="${activemq.base}/data/kahadb"/>
</persistenceAdapter>
-->
隨後加入如下一段
<persistenceAdapter>
<jdbcPersistenceAdapter dataSource="#mysql-ds"/>
</persistenceAdapter>
這句是表示activemq使用mysql數據源,數據不存在本地
若有必要,修改activemq啓動監聽端口
<transportConnectors>
<transportConnector name="openwire" uri="tcp://0.0.0.0:61616"/>
</transportConnectors>
修改日誌位置
vi /usr/local/activemq/conf/log4j.properties
log4j.appender.logfile.file=/data/logs/activemq/activemq.log
下載並將 MySQL驅動包放到 /usr/local/activemq/lib下
3.3. Activemq 啓動腳本
# su - web
Web> cat activemq_61616_restart.sh
#!/bin/bash
# restart activemq port 61616
cd
/usr/local/activemq1/bin/activemq stop
if [ -f /usr/local/activemq1/data/activemq.pid ]
then
rm -f /usr/local/activemq1/data/activemq.pid
fi
sleep 5
/usr/local/activemq/bin/activemq setup /home/web/.activemqrc
/usr/local/activemq1/bin/activemq start
3.4. Activemq master & broker
Activemq 鏈接mysql數據庫,能夠實現master/broker 架構,當master出現問題時,能夠由broker接管成爲新的master, 避免master服務器故障
3.5 檢驗activemq啓動是否正常
查看日誌信息,顯示鏈接8161,服務器61617和8161都開啓,日誌信息以下:
vice | main 2014-10-21 15:57:28,890 | INFO | Logging to org.slf4j.impl.JCLLoggerAdapter(org.eclipse.jetty.util.log) via org.eclipse.jetty.util.log.Slf4jLog | org.eclipse.jetty.util.log | main 2014-10-21 15:57:28,890 | INFO | jetty-7.0.1.v20091125 | org.eclipse.jetty.util.log | main 2014-10-21 15:57:29,137 | INFO | ActiveMQ WebConsole initialized. | org.apache.activemq.web.WebConsoleStarter | main 2014-10-21 15:57:29,249 | INFO | Initializing Spring FrameworkServlet 'dispatcher' | /admin | main 2014-10-21 15:57:29,393 | INFO | ActiveMQ Console at http://0.0.0.0:8161/admin | org.eclipse.jetty.util.log | main 2014-10-21 15:57:29,622 | INFO | Initializing Spring root WebApplicationContext | /camel | main 2014-10-21 15:57:31,906 | INFO | Connector vm://localhost Started | org.apache.activemq.broker.TransportConnector | main 2014-10-21 15:57:33,279 | INFO | Camel Console at http://0.0.0.0:8161/camel | org.eclipse.jetty.util.log | main 2014-10-21 15:57:33,311 | INFO | ActiveMQ Web Demos at http://0.0.0.0:8161/demo | org.eclipse.jetty.util.log | main 2014-10-21 15:57:33,343 | INFO | RESTful file access application at http://0.0.0.0:8161/fileserver | org.eclipse.jetty.util.log | main 2014-10-21 15:57:33,357 | INFO | Started SelectChannelConnector@0.0.0.0:8161 | org.eclipse.jetty.util.log | main
3.6. 使用activemq
客戶端使用failover傳輸機制來使用activemq, 一般代碼裏須要用下面的方法來調用activemq
failover:(tcp://broker1:61616,
tcp://broker2:61616,
tcp://broker3:61616)
3.7. Activemq 監控
一般咱們採用2臺服務器,鏈接mysql數據庫,實現master/borker,可是這種架構,只有master有主端口啓動,broker沒有主端口啓動,因此一般用ZABBIX監控master上運行的主端口 61616