activemq集群搭建Demo

Posted lxcy

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了activemq集群搭建Demo相关的知识,希望对你有一定的参考价值。

第一步:创建集群目录

[[email protected] ~]# mkdir -p /usr/local/activemqCluster

复制单点至集群目录

[[email protected] ~]# cp /usr/local/activemq/apache-activemq-5.14.5 /usr/local/activemqCluster/mq1 -rf

第二步:配置activemq.xml

进入conf所在目录

[[email protected] ~]# cd /usr/local/activemqCluster/mq1/conf

[[email protected] conf]# vi activemq.xml

技术分享图片

替换为下面的内容:

技术分享图片

配置详细信息解读:

<persistenceAdapter>
    <replicatedLevelDB
        #数据目录
        directory="${activemq.data}/leveldb"   
        #集群数为3
        replicas="3"
        #绑定服务地址
        bind="tcp://0.0.0.0:62621"
        #zookeeper地址
        zkAddress="localhost:2181,localhost:2182,localhost:2183"
        #服务的地址
        hostname="localhost"
        #在zookeeper中的路径
        zkPath="/activemq/leveldb-stores"/>
</persistenceAdapter>


<networkConnectors>
    #配置自动切换地址
    <networkConnector uri="static:(tcp://127.0.0.1:61616,tcp://127.0.0.1:61716,tcp://127.0.0.1:61816)" duplex="false"/>
</networkConnectors>

 

第三步:再复制两份,共计三份,修改端口号

[[email protected] ~]# cd /usr/local/activemqCluster/

[[email protected] activemqCluster]# cp mq1 mq2 -rf
[[email protected] activemqCluster]# cp mq1 mq3 -rf

mq2修改端口号

[[email protected] activemqCluster]# cd mq2/conf

[[email protected] conf]# vi activemq.xml 

技术分享图片

mq3修改端口号同理,改为61816即可,此处不在演示

第四步:启动

[[email protected] ~]# cd /usr/local/activemqCluster/

[[email protected] activemqCluster]# mq1/bin/activemq start
INFO: Loading ‘/usr/local/activemqCluster/mq1//bin/env‘
INFO: Using java ‘/usr/local/java/jdk1.8.0_161/bin/java‘
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : ‘/usr/local/activemqCluster/mq1//data/activemq.pid‘ (pid ‘2786‘)
[[email protected] activemqCluster]# mq2/bin/activemq start
INFO: Loading ‘/usr/local/activemqCluster/mq2//bin/env‘
INFO: Using java ‘/usr/local/java/jdk1.8.0_161/bin/java‘
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : ‘/usr/local/activemqCluster/mq2//data/activemq.pid‘ (pid ‘2840‘)
[[email protected] activemqCluster]# mq3/bin/activemq start
INFO: Loading ‘/usr/local/activemqCluster/mq3//bin/env‘
INFO: Using java ‘/usr/local/java/jdk1.8.0_161/bin/java‘
INFO: Starting - inspect logfiles specified in logging.properties and log4j.properties to get details
INFO: pidfile created : ‘/usr/local/activemqCluster/mq3//data/activemq.pid‘ (pid ‘2892‘)

java客户端操作集群

更改连接地址即可,如图:

技术分享图片

 

以上是关于activemq集群搭建Demo的主要内容,如果未能解决你的问题,请参考以下文章

linux环境下搭建ActiveMQ集群

基于Docker搭建ActiveMQ的高可用集群

ActiveMQ集群搭建

ActiveMQ集群搭建

ActiveMQ笔记:搭建Broker集群(cluster)

Zookeeper+ActiveMQ集群搭建