天天看点

activemq集群搭建activemq集群搭建

文章目录

  • activemq集群搭建
    • 1.将activemq复制三分
    • 2.修改三个mq的端口
    • 3.localhost名字映射
    • 4.统一brokerName
    • 5.集群配置
    • 6.修改mq消息端口
    • 7.运行zookeeper集群和avtivemq集群
    • 8.测试
    • 9.制造故障

activemq集群搭建

1.将activemq复制三分

cp -r apache-activemq-5.16.0   activemq8161
cp -r apache-activemq-5.16.0   activemq8162
cp -r apache-activemq-5.16.0   activemq8163
           
activemq集群搭建activemq集群搭建

接下来我们将使用activemq8161,activemq8162,activemq8163来基于zookeeper做集群

2.修改三个mq的端口

(activemq8161不动,修改activemq8162,activemq8163)

进入conf的目录下。修改jetty的内容

修改activemq8162

cd activemq8162/conf
 vim jetty.xml
           
activemq集群搭建activemq集群搭建

修改activemq8163

cd activemq8163/conf
 vim jetty.xml
           
activemq集群搭建activemq集群搭建

3.localhost名字映射

vim /etc/hosts
           

添加映射

activemq集群搭建activemq集群搭建

4.统一brokerName

vim activemq8161/conf/activemq.xml 
 vim activemq8162/conf/activemq.xml 
 vim activemq8163/conf/activemq.xml 
           
activemq集群搭建activemq集群搭建
activemq集群搭建activemq集群搭建
activemq集群搭建activemq集群搭建

5.集群配置

在activemq.xml添加集群配置(取消掉kahadb)

activemq集群搭建activemq集群搭建
activemq集群搭建activemq集群搭建
activemq集群搭建activemq集群搭建

6.修改mq消息端口

(activemq8161不动,修改activemq8162,activemq8163)

activemq集群搭建activemq集群搭建
activemq集群搭建activemq集群搭建

7.运行zookeeper集群和avtivemq集群

集群搭建教程:https://blog.csdn.net/weixin_45742032/article/details/108331492

cd /usr/local/zookeeper2181/bin
./zkServer.sh start

cd /usr/local/zookeeper2182/bin
./zkServer.sh start

cd /usr/local/zookeeper2183/bin
./zkServer.sh start
           
cd /usr/local/activemq8161/bin
./activemq start
cd /usr/local/activemq8162/bin
./activemq start
cd /usr/local/activemq8163/bin
./activemq start
           

8.测试

随便登录一个zookeeper

cd /usr/local/zookeeper2183/bin
 ./zkCli.sh -server 192.168.164.134:2182
           

查看mq集群节点

activemq集群搭建activemq集群搭建

查看节点

get  /activemq/leveldb-stores/00000000000
 get  /activemq/leveldb-stores/00000000001
 get  /activemq/leveldb-stores/00000000002
           

elected节点不是null的就是主mq,是null的节点就是从mq,因此address为tcp://liumq:61631对应的端口为8161的mq为主mq

activemq集群搭建activemq集群搭建
activemq集群搭建activemq集群搭建
activemq集群搭建activemq集群搭建

由于MQ集群只能访问主节点,分别访问mq,只有端口为8161可以访问

http://192.168.164.134:8161
http://192.168.164.134:8162
http://192.168.164.134:8163
           
activemq集群搭建activemq集群搭建

9.制造故障

现在我们停掉8161的服务

查看8161的pid

netstat -nlp
           
activemq集群搭建activemq集群搭建

停掉8161的服务

kill -9 3999
           

zookeeper选举8162为主节点

activemq集群搭建activemq集群搭建