官网地址:http://activemq.apache.org/replicated-leveldb-store
原理图:
原理说明:
1)使用Zookeeper集群注册所有的ActiveMQ Broker,但只有其中一个Broker可以提供服务,它将被视为Master,其他的Broker处于待机状态被视为Slave。如果Master因故障而不能提供服务,Zookeeper会从Slave中选举出一个Broker充当Master。
2)Slave连接Master并同步他们的存储状态,Slave不接受客户端连接。所有的存储操作都将被复制到连接至Maste的Slaves。
3)如果Master宕机得到了最新更新的Slave会变成Master。故障节点在恢复后会重新加入到集群中并连接Master进入Slave模式。
4)所有需要同步的消息操作都将等待存储状态被复制到其他法定节点的操作完成才能完成。所以,如给你配置了replicas=3,name法定大小是(3/2)+1 = 2。Master将会存储更新然后等待(2-1)=1个Slave存储和更新完成,才汇报success。有一个node要作为观察者存在。当一个新的Master被选中,你需要至少保障一个法定mode在线以能够找到拥有最新状态的ode,这个node才可以成为新的Master。因此,推荐运行至少3个replica nodes以防止一个node失败后服务中断。
主机 | zookeeper集群端口 | zookeeper安装目录 | AMQ集群bind端口 | AMQ消息tcp端口 | AMQ管理控制台端口 | AMQ安装目录 |
10.0.0.11 | 2191 | /data/app/zookeeper | bind=”tcp://0.0.0.0:63631” | 61616 | 8161 | /data/app/activemq |
10.0.0.12 | 2192 | /data/app/zookeeper | bind=”tcp://0.0.0.0:63632” | 61617 | 8162 | /data/app/activemq |
10.0.0.13 | 2193 | /data/app/zookeeper | bind=”tcp://0.0.0.0:63633” | 61618 | 8263 | /data/app/activemq |
参考文档:https://www.cnblogs.com/hujinzhong/p/11825535.html
1)安装jdk8
[root@activemq01 ~]# rpm -ivh jdk-8u181-linux-x64.rpm [root@activemq01 ~]# java -version java version "1.8.0_181" Java(TM) SE Runtime Environment (build 1.8.0_181-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.181-b13, mixed mode)
2)解压zookeeper安装包至指定目录
[root@activemq01 ~]# tar xf zookeeper-3.3.6.tar.gz -C /data/app/ [root@activemq01 ~]# mv /data/app/zookeeper-3.3.6/ /data/app/zookeeper
3)配置文件修改
[root@activemq01 conf]# pwd /data/app/zookeeper/conf [root@activemq01 conf]# cp zoo_sample.cfg zoo.cfg [root@activemq01 conf]# vim 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. dataDir=/opt/zookeeper # the port at which the clients will connect clientPort=2181 #创建数据目录 [root@activemq01 conf]# mkdir -p /opt/zookeeper
4)启动zookeeper并查看状态
[root@activemq01 ~]# /data/app/zookeeper/bin/zkServer.sh start JMX enabled by default Using config: /data/app/zookeeper/bin/../conf/zoo.cfg Starting zookeeper ... STARTED [root@activemq01 ~]# jps 17477 QuorumPeerMain 17498 Jps [root@activemq01 ~]# /data/app/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /data/app/zookeeper/bin/../conf/zoo.cfg Mode: standalone [root@activemq01 ~]# netstat -lntp|grep 2181 tcp6 0 0 :::2181 :::* LISTEN 17477/java
5)其他两台做相同配置
[root@activemq02 conf]# ../bin/zkServer.sh status JMX enabled by default Using config: /data/app/zookeeper/bin/../conf/zoo.cfg Mode: standalone [root@activemq02 conf]# netstat -lntp|grep 2181 tcp6 0 0 :::2181 :::* LISTEN 16530/java [root@active03 conf]# ../bin/zkServer.sh status JMX enabled by default Using config: /data/app/zookeeper/bin/../conf/zoo.cfg Mode: standalone [root@active03 conf]# netstat -lntp|grep 2181 tcp6 0 0 :::2181 :::* LISTEN 17204/java
6)创建myid文件
#三台不一样 [root@activemq01 ~]# echo 1 > /opt/zookeeper/myid [root@activemq02 ~]# echo 2 > /opt/zookeeper/myid [root@active03 ~]# echo 3 > /opt/zookeeper/myid
7)修改配置文件
#三台一样 [root@activemq01 ~]# vim /data/app/zookeeper/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. dataDir=/opt/zookeeper # the port at which the clients will connect clientPort=2181 #cluster server.1=10.0.0.11:2888:3888 server.2=10.0.0.12:2888:3888 server.3=10.0.0.13:2888:3888
8)重启三台zookeeper
[root@activemq01 ~]# /data/app/zookeeper/bin/zkServer.sh restart [root@activemq02 ~]# /data/app/zookeeper/bin/zkServer.sh restart [root@activemq03 ~]# /data/app/zookeeper/bin/zkServer.sh restart #查看三台的状态 [root@activemq01 ~]# /data/app/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /data/app/zookeeper/bin/../conf/zoo.cfg Mode: leader [root@activemq02 ~]# /data/app/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /data/app/zookeeper/bin/../conf/zoo.cfg Mode: follower [root@active03 ~]# /data/app/zookeeper/bin/zkServer.sh status JMX enabled by default Using config: /data/app/zookeeper/bin/../conf/zoo.cfg Mode: follower
ActiveMQ多节点集群-基于zookeeper + replicated-leveldb-store的主从集群
原文:https://www.cnblogs.com/hujinzhong/p/12538853.html