RocketMQ集群,包括多主多从异步复制、多主多从同步双写等多种模式,下面搭建一个一主一从异步复制集群。

        准备两个虚拟机节点

                node1:部署主节点、部署nameServer、部署RocketMQ管控台

                node2:部署从节点、部署nameServer

        在node1 node2上传RocketMQ源码包,使用mvn -Prelease-all -DskipTests clean install -U

进行编译,进入  /distribution/target/apache-rocketmq

        在两个节点上,根据机器内存,修改脚本文件中的jvm参数

                runserver.sh

JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

                runbroker.sh

JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"

        在两个节点上启动nameServer

nohup sh bin/mqnamesrv &

         在node1上启动主节点

                编辑 conf/2m-2s-async/broker-a.properties,指定两个nameServer的地址,用;分割

namesrvAddr=192.168.50.136:9876;192.168.50.137:9876
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a.properties &

 

        在node2上启动从节点

                编辑 conf/2m-2s-async/broker-a-s.properties,指定两个nameServer的地址,用;分割

namesrvAddr=192.168.50.136:9876;192.168.50.137:9876
brokerClusterName=XdclassCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
nohup sh bin/mqbroker -c conf/2m-2s-async/broker-a-s.properties &

 

        使用管控台

                在node1上上传rocketmq-console源码包,修改pom.xml版本为使用的版本,修改springboot的配置文件application.properties,指定nameServer地址,多个地址用;分割

                application.properties

server.contextPath=
server.port=8080
#spring.application.index=true
spring.application.name=rocketmq-console
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
logging.config=classpath:logback.xml
#if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876
rocketmq.config.namesrvAddr=192.168.50.136:9876;192.168.50.136:9876
#if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
rocketmq.config.isVIPChannel=
#rocketmq-console's data path:dashboard/monitor
rocketmq.config.dataPath=/tmp/rocketmq-console/data
#set it false if you don't want use dashboard.default true
rocketmq.config.enableDashBoardCollect=true
#set the message track trace topic if you don't want use the default one
rocketmq.config.msgTrackTopicName=

                对管控台源码编译:mvn clean compie -DskipTests,在target目录下找到rocketmq-console-ng-1.0.0.jar,使用java命令来启动管控台。

在管控台查看到集群信息,部署成功了。

对一主一从集群进行测试后,具有如下特性:

主节点宕机后,应用程序可以继续在从节点消费,但是不能发送消息,在主节点恢复后,主节点会跟从节点同步已经被消费的消息。

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐