先了解RocketMq的集群架构
多Master模式
一个集群无Slave,全是Master,例如2个Master或者3个Master,这种模式的优缺点如下:
优点:配置简单,单个Master宕机或重启维护对应用无影响,在磁盘配置为RAID10时,即使机器宕机不可恢复情况下,由于RAID10磁盘非常可靠,消息也不会丢(异步刷盘丢失少量消息,同步刷盘一条不丢),性能最高;
缺点:单台机器宕机期间,这台机器上未被消费的消息在机器恢复之前不可订阅,消息实时性会受到影响。
- 下载二进制安装包
[root@localhost servers]#wget https://downloads.apache.org/rocketmq/4.7.1/rocketmq-all-4.7.1-bin-release.zip
- 创建数据目录
[root@localhost 2m-noslave]# mkdir data
[root@localhost 2m-noslave]# vim conf/2m-noslave/broker-a.properties
brokerClusterName=YuchangCluster #改下集群名字
brokerName=broker-113 #改下brokerName
#brokerId 0 表示 Master,>0 表示 Slave
brokerId=0
# 删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=48
#Broker role有3种:SYNC MASTER、ASYNC MASTER、SLAVE。关键词SYNC和ASYNC表示Master和Slave之间同步消息的机制,SYNC即同步更新,指当Slave和Master消息同步完成后,再返回发送成功的状态。ASYNC即异步更新,master与slave有短暂消息延迟,毫秒级。本文在此使用了异步复制集群模式
brokerRole=ASYNC_MASTER
# 刷盘方式 ASYNC_FLUSH 异步刷盘
flushDiskType=ASYNC_FLUSH
#nameServer地址,分号分割
namesrvAddr=rocketmq-nameserver-1:9876;rocketmq-nameserver-2:9876
#存储路径
storePathRootDir=/servers/rocketmq-all-4.7.1-bin-release/data
storePathCommitLog=/servers/rocketmq-all-4.7.1-bin-release/data/commitlog
brokerIP1=10.1.1.113
- 启动nameserver(依赖jdk,提前安装jdk环境)
[root@localhost rocketmq-all-4.7.1-bin-release]# nohup bin/mqnamesrv -n 10.1.1.113:9876 > nameserver.log 2>&1 &
查看nameserver日志
[root@localhost rocketmq-all-4.7.1-bin-release]# tail -f nameserver.log
nohup: 忽略输入
Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON
nameserver启动成功
- 部署另一台
[root@localhost servers]# scp -r rocketmq-all-4.7.1-bin-release root@10.1.1.114:/servers/
整体拷贝到114上,修改conf/broker-b.properties
brokerName=broker-114同种方式,再启动nameserver
brokerClusterName=YuchangCluster
brokerName=broker-114
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
namesrvAddr=10.1.1.113:9876;10.1.1.114:9876
storePathRootDir=/servers/rocketmq-all-4.7.1-bin-release/data
storePathCommitLog=/servers/rocketmq-all-4.7.1-bin-release/data/commitlog
brokerIP1=10.1.1.114
114上启动nameserver
nohup bin/mqnamesrv -n 10.1.1.114:9876 > nameserver.log 2>&1 &
- 启动broker
113 [root@localhost rocketmq-all-4.7.1-bin-release]# nohup bin/mqbroker -n 10.1.1.113:9876 -c conf/2m-noslave/broker-a.properties autoCreateTopicEnable=true > broker.log 2>&1 &
114 [root@localhost rocketmq-all-4.7.1-bin-release]# nohup bin/mqbroker -n 10.1.1.114:9876 -c conf/2m-noslave/broker-b.properties autoCreateTopicEnable=true > broker.log 2>&1 &
安装控制台
$ git clone https://github.com/apache/rocketmq-externals
cd rocketmq-externals/rocketmq-console
mvn clean package -Dmaven.test.skip=true
nohup java -jar target/rocketmq-console-ng-2.0.0.jar --server.port=8080 --rocketmq.config.namesrvAddr='10.1.1.113:9876;10.1.1.114:9876' &
操作指南
从自己的电脑访问10.1.1.113:8080
常用命令
停止broker#bin/mqshutdown broker /namesrv
官方最佳实践