Rocketmq在单节点情况下新增从节点
在docker-compose部署rocketmq单节点的基础上,新增一个从节点
一,修改docker-compose配置文件
原docker-compose文件
version: '3.5'
services:rmqnamesrv:image: foxiswho/rocketmq:server-4.5.2container_name: rmqnamesrvports:- 9876:9876volumes:- /my/rocketmq/logs:/opt/logs- /my/rocketmq/store:/opt/storenetworks:rmq:aliases:- rmqnamesrvrmqbroker:image: foxiswho/rocketmq:broker-4.5.2container_name: rmqbrokerports:- 10909:10909- 10911:10911volumes:- /my/rocketmq/broker-logs:/root/logs/rocketmqlogs- /my/rocketmq/broker-store:/opt/store- /my/config/rocketmq/broker.conf:/etc/rocketmq/broker.confenvironment:NAMESRV_ADDR: "rmqnamesrv:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"command: mqbroker -c /etc/rocketmq/broker.confdepends_on:- rmqnamesrvnetworks:rmq:aliases:- rmqbrokerrmqconsole:image: styletang/rocketmq-console-ngcontainer_name: rmqconsoleports:- 8087:8080environment:JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"depends_on:- rmqnamesrvnetworks:rmq:aliases:- rmqconsolenetworks:rmq:name: rmqdriver: bridge
新增一个broker从节点配置
version: '3.5'
services:rmqnamesrv:image: foxiswho/rocketmq:server-4.5.2container_name: rmqnamesrvports:- 9876:9876volumes:- /my/rocketmq/logs:/opt/logs- /my/rocketmq/store:/opt/storenetworks:rmq:aliases:- rmqnamesrvrmqbroker:image: foxiswho/rocketmq:broker-4.5.2container_name: rmqbrokerports:- 10909:10909- 10911:10911volumes:- /my/rocketmq/broker-logs:/root/logs/rocketmqlogs- /my/rocketmq/broker-store:/opt/store- /my/config/rocketmq/broker.conf:/etc/rocketmq/broker.confenvironment:NAMESRV_ADDR: "rmqnamesrv:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"command: mqbroker -c /etc/rocketmq/broker.confdepends_on:- rmqnamesrvnetworks:rmq:aliases:- rmqbrokerrmqbroker-slave:image: foxiswho/rocketmq:broker-4.5.2container_name: rmqbroker-slaveports:- 10910:10909- 10912:10911volumes:- /home/my/rocketmq/broker-slave-logs:/root/logs/rocketmqlogs- /home/my/rocketmq/broker-slave-store:/opt/store- /home/my/config/rocketmq-slave/broker.conf:/etc/rocketmq/broker.confenvironment:NAMESRV_ADDR: "rmqnamesrv:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"command: mqbroker -c /etc/rocketmq/broker.confdepends_on:- rmqnamesrvnetworks:rmq:aliases:- rmqbroker-slavermqconsole:image: styletang/rocketmq-console-ngcontainer_name: rmqconsoleports:- 8087:8080environment:JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"depends_on:- rmqnamesrvnetworks:rmq:aliases:- rmqconsolenetworks:rmq:name: rmqdriver: bridge
二,新建目录并修改配置文件
#新建从节点持久化目录
mkdir -p /home/my/rocketmq/broker-slave-logs /home/my/rocketmq/broker-slave-store /home/my/config/rocketmq-slave
#复制主节点broker配置文件到从节点目录并进行相应修改
cp /home/my/config/rocketmq/broker.conf /home/my/config/rocketmq-slave
vi /home/my/config/rocketmq-slave/broker.conf
#从节点配置文件的brokerName和brokerId必须和主节点不同,其中brokerId必须比主节点大
brokerName = broker-b
brokerId = 1
deleteWhen = 04
fileReservedTime = 48
#brokerRole=SLAVE表示该broker节点为从节点
brokerRole = SLAVE
flushDiskType = ASYNC_FLUSH
autoCreateTopicEnable = true
# 如果是本地程序调用云主机 mq,这个需要设置成 云主机 IP
brokerIP1=<your ip>
namesrvAddr=<your ip>:9876
三,启动从节点并在rmqconsole查看是否运行成功
#在docker-compose目录下运行
docker-compose up -d
#该命令会自动运行文件中尚未运行的容器,不会影响其他容器运行