RocketMQ 集群
集群部署:
我们要创建一个2主2从的RocketMQ集群,同时NameServer也创建两个。
windows版本
创建store根路径
D:\workspaces\rocketmq-4.9.3\data\a
D:\workspaces\rocketmq-4.9.3\data\as
D:\workspaces\rocketmq-4.9.3\data\b
D:\workspaces\rocketmq-4.9.3\data\bs
修改broker配置文件
# 集群名称
brokerClusterName=DefaultCluster
# broker名称,Master和Slaver要保持统一
brokerName=broker-a
# 0 表示主; 1表示从
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
# 创建topic时缺省创建队列数
defaultTopicQueueNums=4
# 自动创建话题,线上关闭
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
# IP1 为主用
brokerIP1=127.0.0.1
# IP2 是从找主用
brokerIP2=127.0.0.1
# 端口号,各实例间端口号差距多些更好
listenPort=10931
# 存储主地址
storePathRootDir=D:/workspaces/rocketmq-4.9.3/data/a
# 名称服务器地址
namesrvAddr=127.0.0.1:9876;127.0.0.1:9870
新建namesrv配置文件 namesrv-1.properties
listenPort=9870
和 namesrv-2.properties。
listenPort=9876
启动集群:
start bin\mqnamesrv.cmd -c conf\2m-2s-sync\namesrv-1.properties
start bin\mqnamesrv.cmd -c conf\2m-2s-sync\namesrv-2.properties
start bin\mqbroker.cmd -c conf\2m-2s-sync\broker-a.properties
start bin\mqbroker.cmd -c conf\2m-2s-sync\broker-a-s.properties
start bin\mqbroker.cmd -c conf\2m-2s-sync\broker-b.properties
start bin\mqbroker.cmd -c conf\2m-2s-sync\broker-b-s.properties
linux版本:
创建store根路径
/home/nixinfeng/workspace/rocketmq-4.9.3/data/am
/home/nixinfeng/workspace/rocketmq-4.9.3/data/as
/home/nixinfeng/workspace/rocketmq-4.9.3/data/bm
/home/nixinfeng/workspace/rocketmq-4.9.3/data/bs
创建配置文件:
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
listenPort=10911
storePathRootDir=/home/nixinfeng/workspace/rocketmq-4.9.3/data/am
namesrvAddr=127.0.0.1:9876
启动集群:(需要补上namesrv的启动)
nohup bin/mqbroker -c /home/nixinfeng/workspace/rocketmq-4.9.3/conf/2m-2s-sync/broker-a.properties &
nohup bin/mqbroker -c /home/nixinfeng/workspace/rocketmq-4.9.3/conf/2m-2s-sync/broker-a-s.properties &
nohup bin/mqbroker -c /home/nixinfeng/workspace/rocketmq-4.9.3/conf/2m-2s-sync/broker-b.properties &
nohup bin/mqbroker -c /home/nixinfeng/workspace/rocketmq-4.9.3/conf/2m-2s-sync/broker-b-s.properties &
可能遇到的问题汇总
- 无报错直接退出
- 配置文件路径问题,windows和linux不同。
- 存储数据的路径权限不够
- 端口分配,貌似rocket会占用临近的端口号