回复
docker-compose部署rocketmq双主双丛集群
d_hero
发布于 2023-6-29 14:01
浏览
0收藏
描述
两台主机搭建双主双从集群
每台主机上一个nameserver,两个broker一主一从
主丛部署服务器规划
服务器 | 部署的应用 | broker主从规划 | 物理资源 | 存储目录 |
10.100.232.171 | namesrv 、broker、console | master-a,slave-b | 无 | /opt/docker/rocketmq |
10.100.232.172 | namesrv、broker | master-b,slave-a | 无 | /opt/docker/rocketmq |
10.100.232.171 的 broker规划:
brokerName | 主从 | broker对外服务监听端口 | 需要暴露端口 |
a | master | 10911 | 10911,10912,10909 |
b | slave | 10921 | 10921,10922,10919 |
10.100.232.172 的 broker规划:
brokerName | 主从 | broker对外服务监听端口 | 需要暴露端口 |
a | slave | 10911 | 10911,10912,10909 |
b | master | 10921 | 10921,10922,10919 |
两台机器都拉取镜像
docker pull rocketmqinc/rocketmq
10.100.232.171机器:
创建目录用于映射
#nameserver映射目录配置
mkdir -p /opt/docker/rocketmq/nameserver/logs
mkdir -p /opt/docker/rocketmq/nameserver/store
#broker-a的master映射配置
mkdir -p /opt/docker/rocketmq/broker/master-a/logs
mkdir -p /opt/docker/rocketmq/broker/master-a/store
mkdir -p /opt/docker/rocketmq/broker/master-a/conf
#broker-b的slave映射配置
mkdir -p /opt/docker/rocketmq/broker/slave-b/logs
mkdir -p /opt/docker/rocketmq/broker/slave-b/store
mkdir -p /opt/docker/rocketmq/broker/slave-b/conf
创建rmqbroker配置文件
需要注意的点:
- brokerIP1属性需要根据具体情况修改,由于是docker部署,使用的是的docker的网络,所以这里设置为宿主机内网ip。
- namesrvAddr配置为nameserver的IP和端口,这里也设置为宿主机的内网ip和映射端口,多个nameserver要用分号隔开。
- istenPort是对外服务的监听端口,会影响到vip端口和主从同步端口,vip端口=listenPort-2,主从同步端口=listenPort+1,构建broker时需要将容器的listenPort映射为宿主机相同的端口,vip端口和主从同步端口也要和容器的端口同步。例如此时,listenPort=10911,则构建broker容器的时候要添加以下参数
-p 10911:10911
-p 10912:10912
-p 10909:10909
- 丛节点需要设置
brokerId=1 #数字往后类推
brokerRole=SLAVE
需要改变
listenPort 避免端口和master冲突
brokerName 同个集群中broker的名称不能相同
rmqbroker-master-a,修改master-a的配置文件
cd /opt/docker/rocketmq/broker/master-a/conf
vim broker.conf
master-a的配置文件内容
brokerClusterName=rocketmq-cluster
# broker名字,注意此处不同的配置文件填写的不一样
brokerName=a
# 0 表示Master,>0 表示Slave
brokerId=0
# 多网卡配置,不配置默认为内网,让mq只能内网访问
brokerIP1 = 10.100.232.171
# nameServer地址,分号分割
namesrvAddr=10.100.232.171:9876;10.100.232.172:9876
# 在发送消息时,自动创建服务器不存在的Topic,默认创建的队列数
defaultTopicQueueNums=4
# 是否允许Broker 自动创建Topic, 建议线下开启, 线上关闭
autoCreateTopicEnable=true
# 是否允许Broker 自动创建订阅组, 建议线下开启, 线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=10911
# 删除文件时间点,默认是凌晨4点
deleteWhen=04
# 文件保留时间,默认是48小时
fileReservedTime=48
# commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个文件默认存30w条, 根据业务情况调整
mapedFileSizeConsumeQueue=30000
# destroyMapedFileIntervalForcibly=12000
# redeleteHangedFileInterval=12000
# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
# 限制的消息大小
maxMessageSize=65536
# flushCommitLogLeastPages=4
# flushConsumeQueueLeastPages=2
# flushCommitLogThoroughInterval=10000
# flushConsumeQueueThoroughInterval=60000
# Broker的角色
# -ASYNC_MASTER 异步复制Master
# -SYNC_MASTER 同步双写Master
# -SLAVE
brokerRole=ASYNC_MASTER
# 刷盘方式
# - ASYNC_FLUSH 异步刷盘
# - SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
# checkTransactionMessageEnable=false
# 发消息线程池数量
# sendMessageTreadPoolNums=128
# 拉消息线程池数量
# pullMessageTreadPoolNums=128
# lushDiskType=ASYNC_FLUSH
rmqbroker-slave-b配置文件修改
cd /opt/docker/rocketmq/broker/slave-b/conf
vim broker.conf
slave-b配置文件
brokerClusterName=rocketmq-cluster
# broker名字,注意此处不同的配置文件填写的不一样
brokerName=b
# 0 表示Master,>0 表示Slave
brokerId=1
# 多网卡配置,不配置默认为内网,让mq只能内网访问
brokerIP1 = 10.100.232.171
# nameServer地址,分号分割
namesrvAddr=10.100.232.171:9876;10.100.232.172:9876
# 在发送消息时,自动创建服务器不存在的Topic,默认创建的队列数
defaultTopicQueueNums=4
# 是否允许Broker 自动创建Topic, 建议线下开启, 线上关闭
autoCreateTopicEnable=true
# 是否允许Broker 自动创建订阅组, 建议线下开启, 线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=10921
# 删除文件时间点,默认是凌晨4点
deleteWhen=04
# 文件保留时间,默认是48小时
fileReservedTime=48
# commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个文件默认存30w条, 根据业务情况调整
mapedFileSizeConsumeQueue=30000
# destroyMapedFileIntervalForcibly=12000
# redeleteHangedFileInterval=12000
# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
# 限制的消息大小
maxMessageSize=65536
# flushCommitLogLeastPages=4
# flushConsumeQueueLeastPages=2
# flushCommitLogThoroughInterval=10000
# flushConsumeQueueThoroughInterval=60000
# Broker的角色
# -ASYNC_MASTER 异步复制Master
# -SYNC_MASTER 同步双写Master
# -SLAVE
brokerRole=SLAVE
# 刷盘方式
# - ASYNC_FLUSH 异步刷盘
# - SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
# checkTransactionMessageEnable=false
# 发消息线程池数量
# sendMessageTreadPoolNums=128
# 拉消息线程池数量
# pullMessageTreadPoolNums=128
# lushDiskType=ASYNC_FLUSH
创建docker-compose.yml
cd /opt/docker/rocketmq
vim docker-compose.yml
文件内容
version: '3.5'
networks:
rmq:
name: rmq
driver: bridge
services:
rmqnamesrv:
image: rocketmqinc/rocketmq
container_name: rmqnamesrv
ports:
- 9876:9876
volumes:
- /opt/docker/rocketmq/nameserver/logs:/home/rocketmq/logs
- /opt/docker/rocketmq/nameserver/store:/home/rocketmq/store
restart: always
command: sh mqnamesrv
networks:
rmq:
aliases:
- rmqnamesrv
rmqbroker-master-a:
image: rocketmqinc/rocketmq
container_name: rmqbroker-master-a
ports:
- 10911:10911
- 10912:10912
- 10909:10909
volumes:
- /opt/docker/rocketmq/broker/master-a/logs:/home/rocketmq/logs
- /opt/docker/rocketmq/broker/master-a/store:/home/rocketmq/store
- /opt/docker/rocketmq/broker/master-a/conf/broker.conf:/home/rocketmq/conf/broker.conf
restart: always
environment:
JAVA_OPTS: "-Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
command: sh mqbroker -c /home/rocketmq/conf/broker.conf autoCreateTopicEnable=true &
links:
- rmqnamesrv:rmqnamesrv
networks:
rmq:
aliases:
- rmqbroker-master-a
rmqbroker-slave-b:
image: rocketmqinc/rocketmq
container_name: rmqbroker-slave-b
ports:
- 10921:10921
- 10922:10922
- 10919:10919
volumes:
- /opt/docker/rocketmq/broker/slave-b/logs:/home/rocketmq/logs
- /opt/docker/rocketmq/broker/slave-b/store:/home/rocketmq/store
- /opt/docker/rocketmq/broker/slave-b/conf/broker.conf:/home/rocketmq/conf/broker.conf
restart: always
environment:
JAVA_OPTS: "-Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
command: sh mqbroker -c /home/rocketmq/conf/broker.conf autoCreateTopicEnable=true &
links:
- rmqnamesrv:rmqnamesrv
networks:
rmq:
aliases:
- rmqbroker-slave-b
rmqconsole:
image: styletang/rocketmq-console-ng
container_name: rmqconsole
ports:
- 9101:8080
restart: always
environment:
JAVA_OPTS: -Drocketmq.namesrv.addr=10.100.232.171:9876;10.100.232.172:9876
-Dcom.rocketmq.sendMessageWithVIPChannel=false
-Duser.timezone='Asia/Shanghai'
networks:
rmq:
aliases:
- rmqconsole
构建容器
docker-compose -f docker-compose.yml up -d
10.100.232.172机器
创建目录用于映射
#nameserver映射目录配置
mkdir -p /opt/docker/rocketmq/nameserver/logs
mkdir -p /opt/docker/rocketmq/nameserver/store
#broker-b的master映射配置
mkdir -p /opt/docker/rocketmq/broker/master-b/logs
mkdir -p /opt/docker/rocketmq/broker/master-b/store
mkdir -p /opt/docker/rocketmq/broker/master-b/conf
#broker-a的slave映射配置
mkdir -p /opt/docker/rocketmq/broker/slave-a/logs
mkdir -p /opt/docker/rocketmq/broker/slave-a/store
mkdir -p /opt/docker/rocketmq/broker/slave-a/conf
rmqbroker-master-b,修改master-b的配置文件
cd /opt/docker/rocketmq/broker/master-b/conf
vim broker.conf
master-b的broker配置文件内容
brokerClusterName=rocketmq-cluster
# broker名字,注意此处不同的配置文件填写的不一样
brokerName=b
# 0 表示Master,>0 表示Slave
brokerId=0
# 多网卡配置,不配置默认为内网,让mq只能内网访问
brokerIP1 = 10.100.232.172
# nameServer地址,分号分割
namesrvAddr=10.100.232.171:9876;10.100.232.172:9876
# 在发送消息时,自动创建服务器不存在的Topic,默认创建的队列数
defaultTopicQueueNums=4
# 是否允许Broker 自动创建Topic, 建议线下开启, 线上关闭
autoCreateTopicEnable=true
# 是否允许Broker 自动创建订阅组, 建议线下开启, 线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=10921
# 删除文件时间点,默认是凌晨4点
deleteWhen=04
# 文件保留时间,默认是48小时
fileReservedTime=48
# commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个文件默认存30w条, 根据业务情况调整
mapedFileSizeConsumeQueue=30000
# destroyMapedFileIntervalForcibly=12000
# redeleteHangedFileInterval=12000
# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
# 限制的消息大小
maxMessageSize=65536
# flushCommitLogLeastPages=4
# flushConsumeQueueLeastPages=2
# flushCommitLogThoroughInterval=10000
# flushConsumeQueueThoroughInterval=60000
# Broker的角色
# -ASYNC_MASTER 异步复制Master
# -SYNC_MASTER 同步双写Master
# -SLAVE
brokerRole=ASYNC_MASTER
# 刷盘方式
# - ASYNC_FLUSH 异步刷盘
# - SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
# checkTransactionMessageEnable=false
# 发消息线程池数量
# sendMessageTreadPoolNums=128
# 拉消息线程池数量
# pullMessageTreadPoolNums=128
# lushDiskType=ASYNC_FLUSH
rmqbroker-slave-a配置文件修改
cd /opt/docker/rocketmq/broker/slave-a/conf
vim broker.conf
slave-a配置文件
brokerClusterName=rocketmq-cluster
# broker名字,注意此处不同的配置文件填写的不一样
brokerName=a
# 0 表示Master,>0 表示Slave
brokerId=1
# 多网卡配置,不配置默认为内网,让mq只能内网访问
brokerIP1 = 10.100.232.172
# nameServer地址,分号分割
namesrvAddr=10.100.232.171:9876;10.100.232.172:9876
# 在发送消息时,自动创建服务器不存在的Topic,默认创建的队列数
defaultTopicQueueNums=4
# 是否允许Broker 自动创建Topic, 建议线下开启, 线上关闭
autoCreateTopicEnable=true
# 是否允许Broker 自动创建订阅组, 建议线下开启, 线上关闭
autoCreateSubscriptionGroup=true
# Broker 对外服务的监听端口
listenPort=10911
# 删除文件时间点,默认是凌晨4点
deleteWhen=04
# 文件保留时间,默认是48小时
fileReservedTime=48
# commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个文件默认存30w条, 根据业务情况调整
mapedFileSizeConsumeQueue=30000
# destroyMapedFileIntervalForcibly=12000
# redeleteHangedFileInterval=12000
# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
# 限制的消息大小
maxMessageSize=65536
# flushCommitLogLeastPages=4
# flushConsumeQueueLeastPages=2
# flushCommitLogThoroughInterval=10000
# flushConsumeQueueThoroughInterval=60000
# Broker的角色
# -ASYNC_MASTER 异步复制Master
# -SYNC_MASTER 同步双写Master
# -SLAVE
brokerRole=SLAVE
# 刷盘方式
# - ASYNC_FLUSH 异步刷盘
# - SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
# checkTransactionMessageEnable=false
# 发消息线程池数量
# sendMessageTreadPoolNums=128
# 拉消息线程池数量
# pullMessageTreadPoolNums=128
# lushDiskType=ASYNC_FLUSH
创建docker-compose.yml
cd /opt/docker/rocketmq
vim docker-compose.yml
version: '3.5'
networks:
rmq:
name: rmq
driver: bridge
services:
rmqnamesrv:
image: rocketmqinc/rocketmq
container_name: rmqnamesrv
ports:
- 9876:9876
volumes:
- /opt/docker/rocketmq/nameserver/logs:/home/rocketmq/logs
- /opt/docker/rocketmq/nameserver/store:/home/rocketmq/store
restart: always
command: sh mqnamesrv
networks:
rmq:
aliases:
- rmqnamesrv
rmqbroker-master-b:
image: rocketmqinc/rocketmq
container_name: rmqbroker-master-b
ports:
- 10921:10921
- 10922:10922
- 10919:10919
volumes:
- /opt/docker/rocketmq/broker/master-b/logs:/home/rocketmq/logs
- /opt/docker/rocketmq/broker/master-b/store:/home/rocketmq/store
- /opt/docker/rocketmq/broker/master-b/conf/broker.conf:/home/rocketmq/conf/broker.conf
restart: always
environment:
JAVA_OPTS: "-Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
command: sh mqbroker -c /home/rocketmq/conf/broker.conf autoCreateTopicEnable=true &
links:
- rmqnamesrv:rmqnamesrv
networks:
rmq:
aliases:
- rmqbroker-master-a
rmqbroker-slave-a:
image: rocketmqinc/rocketmq
container_name: rmqbroker-slave-a
ports:
- 10911:10911
- 10912:10912
- 10909:10909
volumes:
- /opt/docker/rocketmq/broker/slave-a/logs:/home/rocketmq/logs
- /opt/docker/rocketmq/broker/slave-a/store:/home/rocketmq/store
- /opt/docker/rocketmq/broker/slave-a/conf/broker.conf:/home/rocketmq/conf/broker.conf
restart: always
environment:
JAVA_OPTS: "-Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
command: sh mqbroker -c /home/rocketmq/conf/broker.conf autoCreateTopicEnable=true &
links:
- rmqnamesrv:rmqnamesrv
networks:
rmq:
aliases:
- rmqbroker-slave-a
# rmqconsole:
# image: styletang/rocketmq-console-ng
# container_name: rmqconsole
# ports:
# - 9101:8080
# restart: always
# environment:
# JAVA_OPTS: -Drocketmq.namesrv.addr=10.100.232.171:9876;10.100.232.172:9876
# -Dcom.rocketmq.sendMessageWithVIPChannel=false
# -Duser.timezone='Asia/Shanghai'
# networks:
# rmq:
# aliases:
# - rmqconsole
构建容器
docker-compose -f docker-compose.yml up -d
进入docker容器命令
docker exec -it 容器id /bin/bash
java服务配置文件
rocketmq:
name-server: 10.100.232.171:9876;10.100.232.172:9876
自己去试试吧
文章转载自公众号:IT学习道场
分类
已于2023-6-29 14:01:36修改
赞
收藏
回复
相关推荐