activemq集群搭建Demo

activemq5.14.5单节点安装Demo

第一步:创建集群目录

[root@node001 ~]# mkdir -p /usr/local/activemqCluster

复制单点至集群目录

[root@node001 ~]# cp /usr/local/activemq/apache-activemq-5.14.5 /usr/local/activemqCluster/mq1 -rf

第二步:配置activemq.xml

进入conf所在目录

[root@node001 ~]# cd /usr/local/activemqCluster/mq1/conf

[root@node001 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>

 

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

[root@node001 ~]# cd /usr/local/activemqCluster/

[root@node001 activemqCluster]# cp mq1 mq2 -rf
[root@node001 activemqCluster]# cp mq1 mq3 -rf

mq2修改端口号

[root@node001 activemqCluster]# cd mq2/conf

[root@node001 conf]# vi activemq.xml 

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

第四步:启动

[root@node001 ~]# cd /usr/local/activemqCluster/

[root@node001 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')
[root@node001 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')
[root@node001 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客户端操作集群

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

 

posted @ 2018-03-10 16:49  Jony.K.Chen  阅读(943)  评论(0编辑  收藏  举报