第一步:创建集群目录
[[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客户端操作集群
更改连接地址即可,如图: