承接上一篇Broker启动失败原因,今天在学习RocketMQ过程中,Broker启动又双叒叕出问题了,在排除了上一篇文章中描述的JVM配置问题之外,今天经过数个小时的排查,终于搞定这个问题,现将问题记录于此,避免小伙伴踩坑


集群架构模式
我的集群搭建采用的是双主双从同步模式。

角色

架构模式

nameserver,brokerserver

Master1,Slave2

nameserver,brokerserver

Master2,Slave1

总共两台机器,A机器作为Master1,他的从节点Slave1由B机器担任。B机器作为Master2,他的从节点Slave2由A机器担任。可能有点绕,下面给出示意图:

centos7 安装rockmq开机自启详细教程_配置文件


启动Master成功了,但是启动Slave时就有问题了,如下

centos7 安装rockmq开机自启详细教程_sed_02


Slave进程总是在启动后就退出

Broker节点的配置文件
Master1:

#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样
brokerName=broker-a
#0表示Master >0表示Slave
brokerId=0
#nameserver地址 分号分割 根据/etc/hosts的映射查找IP
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver: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=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#储存路径
storePathRootDir=/usr/local/rocketmq/store
#CommitLog存储路径
storePathCommitLog=/usr/local/rocketmq/store/commitlog
#消费队列储存路径
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
#消息索引存储路径
storePathIndex=/usr/local/rocketmq/store/index
#checkpoint文件存储路径
storeCheckPoint=/usr/local/rocketmq/store/checkpoint
#abort文件存储路径
abortFile=/usr/local/rocketmqs/store/abort
#限制的消息大小
maxMessageSize=65536
#Broker的角色 -SYNC_MASTER同步复制Master -ASYNC_MASTER异步复制MASTER
brokerRole=SYNC_MASTER
#刷盘方式 异步和同步
flushDiskType=ASYNC_FLUSH

Slave2:

brokerClusterName=rocketmq-cluster
brokerName=broker-b
brokerId=1
namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=11011
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
diskMaxUsedSpaceRatio=88
#==============注意,下面的路径就是出现问题的地方=============#
storePathRootDir=/usr/local/rocketmq/store
storePathCommitLog=/usr/local/rocketmq/store/commitlog
storePathConsumeQueue=/usr/local/rocketmq/store/consumequeue
storePathIndex=/usr/local/rocketmq/store/index
storeCheckPoint=/usr/local/rocketmq/store/checkpoint
abortFile=/usr/local/rocketmqs/store/abort
#========================================================#
maxMessageSize=65536
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH

问题原因
【路径问题并不是说所配置的路径不存在,而是A机器中的Master1和Slave2不能使用相同的路径。同理,B机器中的Master2与Slave1也就不能相同】

保持A机器中Master1中的配置不变,修改Slave2中的路径。B机器也做类似的更改,下面仅给出Slave2中需要修改的配置。

storePathRootDir=/usr/local/rocketmq/store-s
storePathCommitLog=/usr/local/rocketmq/store-s/commitlog
storePathConsumeQueue=/usr/local/rocketmq/store-s/consumequeue
storePathIndex=/usr/local/rocketmq/store-s/index
storeCheckPoint=/usr/local/rocketmq/store-s/checkpoint
abortFile=/usr/local/rocketmqs/store-s/abort

同一台机器上Master与Slave的配置不同点汇总(双主双从同步模式为例):

centos7 安装rockmq开机自启详细教程_sed_03

再次启动Slave2和Slave1,成功!

centos7 安装rockmq开机自启详细教程_sed_04


出现这种问题的原因可能不只是这一种,如果这种方法不能解决你的问题,你也可以看看我的另一篇文章,希望能帮助到遇到此类问题心急如焚的你 (✿◠‿◠)。