OS: Debian or SuSE
ACTIVEMQ: 5.4.2
JDK: 1.6.0_27
参考 http://wiki.tomshopping.com/pages/viewpage.action?pageId=14288188
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/activemq
3.1. 下载并安装activemq
# 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.gz
# 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 [email protected]: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