搭建 RocketMQ 集群

使用两台虚拟机搭建出 双主-双从 集群
A 192.168.153.131
B 192.168.153.132

官网地址
http://rocketmq.apache.org/docs/quick-start/

先从上面下载下来最新的 RocketMQ 安装包,最新的是 rocketmq-all-4.8.0-bin-release

解压后进入到 conf 文件夹下,官方已经创建好了简单的集群配置文件。

  • 2m-2s-async :2个master,2个slave,async异步复制
  • 2m-2s-sync :2个master,2个slave,sync同步双写
  • 2m-noslave :2个master,没有slave

首先在每台机器上启动 nameServer

nohub sh bin/mqnamesrv &

然后配置 Broker,每台机器上都要分别配置一个 Master 角色的 Broker 和一个 Slave 角色的 Broker,并互为主备。

A 机器启动 broker-a master, broker-b slave
B 机器启动 broker-a slave, broker-b master

启动

nohub sh bin/mqbroker -c conf/2m-2s-async/broker-xxx.properties

然后在安装 console ,最终效果如图:

配置文件:
broker-a-master

brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH

namesrvAddr=192.168.153.131:9876;192.168.153.132:9876
listenPort=10911
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#存储路径
storePathRootDir=~/mq/data/store-a
#commitLog 存储路径 
storePathCommitLog=~/mq/data/store-a/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=~/mq/data/store-a/consumequeue
#消息索引存储路径
storePathIndex=~/mq/data/store-a/index
#checkpoint 文件存储路径
storeCheckpoint=~/mq/data/store-a/checkpoint

broker-b-slave

brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH

namesrvAddr=192.168.153.131:9876;192.168.153.132:9876
listenPort=11011
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#存储路径
storePathRootDir=~/mq/data/store-b
#commitLog 存储路径 
storePathCommitLog=~/mq/data/store-b/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=~/mq/data/store-b/consumequeue
#消息索引存储路径
storePathIndex=~/mq/data/store-b/index
#checkpoint 文件存储路径
storeCheckpoint=~/mq/data/store-b/checkpoint

broker-b-master

brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH

namesrvAddr=192.168.153.131:9876;192.168.153.132:9876
listenPort=10911
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#存储路径
storePathRootDir=~/mq/data/store-b
#commitLog 存储路径 
storePathCommitLog=~/mq/data/store-b/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=~/mq/data/store-b/consumequeue
#消息索引存储路径
storePathIndex=~/mq/data/store-b/index
#checkpoint 文件存储路径
storeCheckpoint=~/mq/data/store-b/checkpoint

broker-a-slave

brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH

namesrvAddr=192.168.153.131:9876;192.168.153.132:9876
listenPort=11011
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#存储路径
storePathRootDir=~/mq/data/store-a
#commitLog 存储路径 
storePathCommitLog=~/mq/data/store-a/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=~/mq/data/store-a/consumequeue
#消息索引存储路径
storePathIndex=~/mq/data/store-a/index
#checkpoint 文件存储路径
storeCheckpoint=~/mq/data/store-a/checkpoint
2021/4/6 posted in  RocketMQ