ActiveMQ集群的三种模式,如图(官网)php
一、第一种模式基于共享文件系统实现的,例如NFS、GlusterFshtml
二、第二种模式是共享一个数据库数据库
三、第三种依赖Zookeeper协调分布式服务apache
以下记载基于第三种方式的安装与配置,基于3台云服务器(m1,m1s1,m1s2)安全
官网下载压缩包,三台机器分别解压,在zookeeper根目录下建立 data 和 logs 文件夹,把conf目录下的zoo_sample.cfg文件拷贝一份并更名为zoo.cfg(默认配置名),配置以下bash
# 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=/home/taydawn/zookeeper/data dataLogDir=/home/taydawn/zookeeper/logs # the port at which the clients will connect clientPort=2181 server.1=0.0.0.0:2888:3888 server.2=m1s1:2888:3888 server.3=m1s2:2888:3888 # 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
三台机器配置相似。若是三台机器实在同一局域网下,server配置能够直接用主机名;不然须要把本机的zoo.cfg中的本机的主机名改成 0.0.0.0,不然会出错(例子)。
服务器
查看暴露在公网上的Zookeeper的服务器信息tcp
echo envi | nc xx.xx.xx.xx 2181
官网下载压缩包,三台机器分别解压,修改conf目录下的 activemq.conf,修改持久化配置,三台机器的broker名称必须同样分布式
<persistenceAdapter> <!-- <kahaDB directory="${activemq.data}/kahadb"/> --> <replicatedLevelDB directory="${activemq.data}/leveldb" replicas="3" bind="tcp://0.0.0.0:0" zkAddress="m1:2181,m1s1:2181,m1s2:2181" hostname="m1s1" zkPath="/activemq/leveldb-stores" /> </persistenceAdapter>
三台机器配置相似,其中“zkPath”为zookeeper的建立节点名称,可以使用 zkCli.sh -server m1:2181 登陆zookeeper命令查看(其中bind配置能够指定port,例如0.0.0.0:61619,0.0.0.0:0表明使用动态端口,由ActiveMQ本身指定空闲端口)ide
依次启动Zookeeper的每个节点,而后再依次启动ActiveMQ的三个节点便可。
相关文章
一、集群配置参考文章