搭建rocketmq的三主三从遇到的坑

1、机器配置

cat /etc/hosts
192.168.224.128 worker1
192.168.224.129 worker2
192.168.224.130 worker3

 

2、broker配置

128机器

a-master

#所属集群名字,名字⼀样的节点就在同⼀个集群内
brokerClusterName=rocketmq-cluster
#broker名字,名字⼀样的节点就是⼀组主从节点。
brokerName=broker-a
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#是否允许 Broker ⾃动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
deleteWhen=04
fileReservedTime=120
#存储路径
storePathRootDir=/app/rocketmq/store
storePathCommitLog=/app/rocketmq/store/commitlog
storePathConsumeQueue=/app/rocketmq/store/consumequeue
storePathIndex=/app/rocketmq/store/index
storeCheckpoint=/app/rocketmq/store/checkpoint
abortFile=/app/rocketmq/store/abort
#Broker 的⻆⾊
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端⼝
listenPort=10911

b-slave

#所属集群名字,名字⼀样的节点就在同⼀个集群内
brokerClusterName=rocketmq-cluster
#broker名字,名字⼀样的节点就是⼀组主从节点。
brokerName=broker-c
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#是否允许 Broker ⾃动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
deleteWhen=04
fileReservedTime=120
#存储路径
storePathRootDir=/app/rocketmq/storeSlave
storePathCommitLog=/app/rocketmq/storeSlave/commitlog
storePathConsumeQueue=/app/rocketmq/storeSlave/consumequeue
storePathIndex=/app/rocketmq/storeSlave/index
storeCheckpoint=/app/rocketmq/storeSlave/checkpoint
abortFile=/app/rocketmq/storeSlave/abort
#Broker 的⻆⾊
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端⼝
listenPort=10912

 

129机器

b-master

#所属集群名字,名字⼀样的节点就在同⼀个集群内
brokerClusterName=rocketmq-cluster
#broker名字,名字⼀样的节点就是⼀组主从节点。
brokerName=broker-b
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#是否允许 Broker ⾃动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
deleteWhen=04
fileReservedTime=120
#存储路径
storePathRootDir=/app/rocketmq/store
storePathCommitLog=/app/rocketmq/store/commitlog
storePathConsumeQueue=/app/rocketmq/store/consumequeue
storePathIndex=/app/rocketmq/store/index
storeCheckpoint=/app/rocketmq/store/checkpoint
abortFile=/app/rocketmq/store/abort
#Broker 的⻆⾊
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端⼝
listenPort=10911

 

c-slave

#所属集群名字,名字⼀样的节点就在同⼀个集群内
brokerClusterName=rocketmq-cluster
#broker名字,名字⼀样的节点就是⼀组主从节点。
brokerName=broker-c
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#是否允许 Broker ⾃动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
deleteWhen=04
fileReservedTime=120
#存储路径
storePathRootDir=/app/rocketmq/storeSlave
storePathCommitLog=/app/rocketmq/storeSlave/commitlog
storePathConsumeQueue=/app/rocketmq/storeSlave/consumequeue
storePathIndex=/app/rocketmq/storeSlave/index
storeCheckpoint=/app/rocketmq/storeSlave/checkpoint
abortFile=/app/rocketmq/storeSlave/abort
#Broker 的⻆⾊
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端⼝
listenPort=10912

 

130机器

c-master

#所属集群名字,名字⼀样的节点就在同⼀个集群内
brokerClusterName=rocketmq-cluster
#broker名字,名字⼀样的节点就是⼀组主从节点。
brokerName=broker-c
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#是否允许 Broker ⾃动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
deleteWhen=04
fileReservedTime=120
#存储路径
storePathRootDir=/app/rocketmq/store
storePathCommitLog=/app/rocketmq/store/commitlog
storePathConsumeQueue=/app/rocketmq/store/consumequeue
storePathIndex=/app/rocketmq/store/index
storeCheckpoint=/app/rocketmq/store/checkpoint
abortFile=/app/rocketmq/store/abort
#Broker 的⻆⾊
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端⼝
listenPort=10911

 

a-slave

#所属集群名字,名字⼀样的节点就在同⼀个集群内
brokerClusterName=rocketmq-cluster
#broker名字,名字⼀样的节点就是⼀组主从节点。
brokerName=broker-a
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#是否允许 Broker ⾃动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
deleteWhen=04
fileReservedTime=120
#存储路径
storePathRootDir=/app/rocketmq/storeSlave
storePathCommitLog=/app/rocketmq/storeSlave/commitlog
storePathConsumeQueue=/app/rocketmq/storeSlave/consumequeue
storePathIndex=/app/rocketmq/storeSlave/index
storeCheckpoint=/app/rocketmq/storeSlave/checkpoint
abortFile=/app/rocketmq/storeSlave/abort
#Broker 的⻆⾊
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端⼝
listenPort=10912

 

3、启动命令

namesrv启动命令

cd /app/rocketmq/rocketmq-all-4.9.5-bin-release
nohup bin/mqnamesrv &

 

broker启动命令

nohup bin/mqbroker -c ../128-a.properties >out1.file 2>&1 &
nohup bin/mqbroker -c ../128-b-s.properties >out2.file 2>&1 &


nohup bin/mqbroker -c ../129-b.properties >out1.file 2>&1 &
nohup bin/mqbroker -c ../129-c-s.properties >out2.file 2>&1 &


nohup bin/mqbroker -c ../130-c.properties >out1.file 2>&1 &
nohup bin/mqbroker -c ../130-a-s.properties >out2.file 2>&1 &

 

4、dashboard配置文件

编译后把配置文件和jar包放同一路径

image

 

rocketmq:
  config:
    namesrvAddrs:
      - 192.168.224.128:9876

 

5、成功

image

 6、坑点

1)同一台机器搭建不同的broker,不同broker的存储文件路径不能相同

image

2)监听端口

比如有台broker配置了10991,另外一台的监听端口不要配置10992,因为broker默认会启动相邻的端口。启动另外的msgbroker失败提示端口被占用

使用   sudo ss -tlpn | grep ':10992',最后我是间隔了20个端口

 

image

 

posted @ 2025-09-14 15:33  傲云萧雨  阅读(13)  评论(0)    收藏  举报