Rocketmq在单节点情况下新增从节点
在docker-compose部署rocketmq单节点的基础上,新增一个从节点
一,修改docker-compose配置文件
原docker-compose文件
version: '3.5'
services:
rmqnamesrv:
image: foxiswho/rocketmq:server-4.5.2
container_name: rmqnamesrv
ports:
- 9876:9876
volumes:
- /my/rocketmq/logs:/opt/logs
- /my/rocketmq/store:/opt/store
networks:
rmq:
aliases:
- rmqnamesrv
rmqbroker:
image: foxiswho/rocketmq:broker-4.5.2
container_name: rmqbroker
ports:
- 10909:10909
- 10911:10911
volumes:
- /my/rocketmq/broker-logs:/root/logs/rocketmqlogs
- /my/rocketmq/broker-store:/opt/store
- /my/config/rocketmq/broker.conf:/etc/rocketmq/broker.conf
environment:
NAMESRV_ADDR: "rmqnamesrv:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: mqbroker -c /etc/rocketmq/broker.conf
depends_on:
- rmqnamesrv
networks:
rmq:
aliases:
- rmqbroker
rmqconsole:
image: styletang/rocketmq-console-ng
container_name: rmqconsole
ports:
- 8087:8080
environment:
JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
depends_on:
- rmqnamesrv
networks:
rmq:
aliases:
- rmqconsole
networks:
rmq:
name: rmq
driver: bridge
新增一个broker从节点配置
version: '3.5'
services:
rmqnamesrv:
image: foxiswho/rocketmq:server-4.5.2
container_name: rmqnamesrv
ports:
- 9876:9876
volumes:
- /my/rocketmq/logs:/opt/logs
- /my/rocketmq/store:/opt/store
networks:
rmq:
aliases:
- rmqnamesrv
rmqbroker:
image: foxiswho/rocketmq:broker-4.5.2
container_name: rmqbroker
ports:
- 10909:10909
- 10911:10911
volumes:
- /my/rocketmq/broker-logs:/root/logs/rocketmqlogs
- /my/rocketmq/broker-store:/opt/store
- /my/config/rocketmq/broker.conf:/etc/rocketmq/broker.conf
environment:
NAMESRV_ADDR: "rmqnamesrv:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: mqbroker -c /etc/rocketmq/broker.conf
depends_on:
- rmqnamesrv
networks:
rmq:
aliases:
- rmqbroker
rmqbroker-slave:
image: foxiswho/rocketmq:broker-4.5.2
container_name: rmqbroker-slave
ports:
- 10910:10909
- 10912:10911
volumes:
- /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.conf
environment:
NAMESRV_ADDR: "rmqnamesrv:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: mqbroker -c /etc/rocketmq/broker.conf
depends_on:
- rmqnamesrv
networks:
rmq:
aliases:
- rmqbroker-slave
rmqconsole:
image: styletang/rocketmq-console-ng
container_name: rmqconsole
ports:
- 8087:8080
environment:
JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
depends_on:
- rmqnamesrv
networks:
rmq:
aliases:
- rmqconsole
networks:
rmq:
name: rmq
driver: 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
#该命令会自动运行文件中尚未运行的容器,不会影响其他容器运行