NutzCN Logo
问答 RocketMQ 双master双slave集群部署,两台机器互为主从,目前和单机效果差不多,请问怎么配置才能做到高可用?
发布于 1974天前 作者 wqmain 5810 次浏览 复制 上一个帖子 下一个帖子
标签:

两台虚机CentOS7.2, 分别为:192.168.1.11(mq-master-a)和 192.168.1.12(mq-master-b)。
mq-master-a 上部署 a主b从,mq-master-b上部署b主a从,同步双写,异步刷盘,namesrv也分别在这两台机器上启动,
理想场景:生产者发送异步消息,消费者正常消费,topic会在两台broker服务中同步,其中一台broker服务宕掉后,另一台继续接收消息,保证MQ服务集群高可用。
但实测结果:生产者发送异步消息,但topic始终只在一个broker中创建,导致这台broker服务宕掉后,生产者无法继续针对该topic发消息,报错如下:
org.apache.rocketmq.client.exception.MQClientException: No route info of this topic,xxx...

服务启动具体操作如下:
1、先分别启动两台机器上的namesrv服务:

nohup sh ./mqnamesrv -c /usr/local/rocketmq/conf/namesrv.p &

2、再分别启动 mq-master-a 和 mq-master-b 上的 broker-master 服务:

nohup sh ./mqbroker -c /usr/local/rocketmq/conf/broker-master-a.p & 
nohup sh ./mqbroker -c /usr/local/rocketmq/conf/broker-master-b.p & 

3、最后分别启动 mq-master-a 和 mq-master-b 上的 broker-slave 服务:

nohup sh ./mqbroker -c /usr/local/rocketmq/conf/broker-slave-b.p & 
nohup sh ./mqbroker -c /usr/local/rocketmq/conf/broker-slave-a.p & 

mq-master-a 和 mq-master-b 上的主从配置如下:
1、192.168.1.11上的 broker-master-a.p 配置:

listenPort=10911
namesrvAddr=192.168.1.11:9876;192.168.1.12:9876
brokerClusterName=mq-cluster
brokerIP1=192.168.1.11
brokerName=broker-a
brokerId=0
defaultTopicQueueNums=1
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileInterval=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=85
storePathRootDir=/usr/local/rocketmq/data/store/master
storePathCommitLog=/usr/local/rocketmq/data/store/master/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH

2、192.168.1.11上的 broker-slave-b.p 配置:

listenPort=10950
namesrvAddr=192.168.1.11:9876;192.168.1.12:9876
brokerClusterName=mq-cluster
brokerIP1=192.168.1.11
brokerName=broker-b
brokerId=1
defaultTopicQueueNums=1
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileInterval=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=85
storePathRootDir=/usr/local/rocketmq/data/store/slave
storePathCommitLog=/usr/local/rocketmq/data/store/slave/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH

3、192.168.1.12上的 broker-master-b.p 配置:

listenPort=10911
namesrvAddr=192.168.1.11:9876;192.168.1.12:9876
brokerClusterName=mq-cluster
brokerIP1=192.168.1.12
brokerName=broker-b
brokerId=0
defaultTopicQueueNums=1
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileInterval=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=85
storePathRootDir=/usr/local/rocketmq/data/store/master
storePathCommitLog=/usr/local/rocketmq/data/store/master/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH

4、192.168.1.12上的 broker-slave-a.p 配置:

listenPort=10950
namesrvAddr=192.168.1.11:9876;192.168.1.12:9876
brokerClusterName=mq-cluster
brokerIP1=192.168.1.12
brokerName=broker-b
brokerId=1
defaultTopicQueueNums=1
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileInterval=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=85
storePathRootDir=/usr/local/rocketmq/data/store/slave
storePathCommitLog=/usr/local/rocketmq/data/store/slave/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH

5、192.168.1.11和192.168.1.12上的 namesrv.p 配置如下:

listenPort=9876
orderMessageEnable=true
useEpollNativeSelector=true
4 回复

补充:生产者Producer就普通异步发送消息:

DefaultMQProducer producer = new DefaultMQProducer("mq-group-demo");
producer.setNamesrvAddr("192.168.1.11:9876;192.168.1.12:9876");
producer.setRetryTimesWhenSendAsyncFailed(3);
//producer.setDefaultTopicQueueNums(1);
//producer.setRetryAnotherBrokerWhenNotStoreOK(true);
producer.start();

producer.send(new Message("mq-topic-demo", "abc", "测试消息".getBytes()), new SendCallback() {
            @Override
            public void onSuccess(SendResult result) {
                //...
            }

            @Override
            public void onException(Throwable e) {
                e.printStackTrace();
            }
        }, 15000);

消费端采用广播消息模式,顺序消费:

DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("mq-consumer-1");
consumer.setNamesrvAddr("192.168.1.11:9876;192.168.1.12:9876");
consumer.setMessageModel(MessageModel.CLUSTERING);
consumer.subscribe("mq-topic-demo", "abc");
consumer.registerMessageListener(new MessageListenerOrderly() {
	@Override
	public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
		try {
			listener.consume(msgs);
			return ConsumeOrderlyStatus.SUCCESS;
		} catch (Exception e) {
			e.printStackTrace();
			return ConsumeOrderlyStatus.SUSPEND_CURRENT_QUEUE_A_MOMENT;
		}
	}
});
consumer.start();

看上去是客户端问题?

@wendal 额滴神现身了啊 兽总指点下具体是哪里的问题呢? 我试过 DefaultMQPushConsumer 即使不start去消费,MQ的broker一样有问题啊,两个broker之间始终不同时创建topic,运行一段时间topic也不同步,才导致topic所在的broker宕掉后生产者发消息失败报错的,网上都说配置了autoCreateTopicEnable就好了,但true和false都试过了,都不行。只有手动执行创建topic的命令后另一个broker上才会有该topic、生产者才能正常发消息,怎么配置才能够做到主主自动同步topic、主宕掉后对应的从仍可保证Consumer能继续消费呢?感谢!!!

手动执行创建topic的命令如下:

./mqadmin updateTopic -n "192.168.1.11:9876;192.168.1.12:9876" -c "mq-cluster" -t mq-topic-demo

@wendal 忘了补充,服务端和客户端的版本都是 4.5.1

添加回复
请先登陆
回到顶部