序
基础设施
- zookeeper
程序协调服务框架,用于自动调度多个activemq。在某个activemq服务宕机后,zookeeper会自动调度集群中其中一个正常的activemq服务成为master主机继续服务 - activemq
消息队列框架,我们会部署多个activemq服务
规划
假设我们有三台服务器:
- 192.168.0.200
部署activemq-master、zookeeper - 192.168.0.201
部署activemq-slave01 - 192.168.0.202
部署activemq-slave02
集群搭建
配置zookeeper
- 解压zookeeper-3.4.9.tar.gz
$ tar -zxvf zookeeper-3.4.9.tar.gz
- 通过实例创建zookeeper配置文件
$ cp -R zoo_sample.cfg /home/zookeeper-3.4.9/conf/zoo.cfg
- 配置zookeeper-3.4.9/conf/zoo.cfg,内容如下:
# The number of milliseconds of each tick
tickTime=2000
# The number of ticks that the initial
# synchronization phase can take
initLimit=10
# The number of ticks that can pass between
# sending a request and getting an acknowledgement
syncLimit=5
# the directory where the snapshot is stored.
# do not use /tmp for storage, /tmp here is just
# example sakes.
dataDir=/tmp/zookeeper
# the port at which the clients will connect
clientPort=2181
# the maximum number of client connections.
# increase this if you need to handle more clients
#maxClientCnxns=60
#
# Be sure to read the maintenance section of the
# administrator guide before turning on autopurge.
#
# http://zookeeper.apache.org/doc/current/zookeeperAdmin.html#sc_maintenance
#
# The number of snapshots to retain in dataDir
#autopurge.snapRetainCount=3
# Purge task interval in hours
# Set to "0" to disable auto purge feature
#autopurge.purgeInterval=1
关键配置说明:
dataDir:zookeeper数据存放目录
dataLogDir:zookeeper保存日志文件的目录
clientPort:zookeeper端口
tickTime:zookeeper服务器之间或客户端与服务器之间维持心跳的时间间隔,也就是每个 tickTime 时间就会发送一个心跳。tickTime以毫秒为单位
initLimit:集群中的follower服务器(F)与leader服务器(L)之间初始连接时能容忍的最多心跳数(tickTime的数量)
syncLimit:集群中的follower服务器与leader服务器之间请求和应答之间能容忍的最多心跳数(tickTime的数量)
server.N=YYY:A:B:服务器名称与地址:集群信息(服务器编号,服务器地址,LF通信端口,选举端口),这个配置项的书写格式比较特殊。其中N表示服务器编号,YYY表示服务器的IP地址,A为LF通信端口,表示该服务器与集群中的leader交换的信息的端口。B为选举端口,表示选举新 leader时服务器间相互通信的端口(当leader挂掉时,其余服务器会相互通信,选择出新的leader)。一般来说,集群中每个服务器的A端口都 是一样,每个服务器的B端口也是一样。但是当所采用的为伪集群时,IP地址都一样,只能时A端口和B端口不一样
配置activemq
activemq配置,会按照规划配置3个服务,并统统交由zookeeper进行调度
安装
此处,不在赘述activemq的安装,详见《ActiveMQ教程(一)-安装 》:http://blog.csdn.net/eugeneheen/article/details/55190552配置核心配置文件/home/apache-activemq-5.9.1-bin/activemq.xml
<beans
xmlns