http://rocketmq.apache.org/dowloading/releases/
搭建一个单机版的RocketMQ没有太大的实用价值,所以在这里搭建一个双主 、 双从 、 无单点故障的高可用 RocketMQ集群 。
两台物理机(这里我采用了两台虚拟机)
主机地址:
192.168.223.41 node01
192.168.223.42 node02
1.解压文件
unzip rocketmq-all-4.3.2-bin-release.zip -d ./rocketmq-all-4.3.2-bin
2.启动两机器的nameserver
[root@node01 rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqnamesrv &
[root@node02 rocketmq-all-4.3.2-bin-release]# nohup sh bin/mqnamesrv &
3.broker配置文件
双master配置:
[root@node01]#vim /rocketmq-all-4.3.2-bin-release/conf/2m-2s-sync/broker-a.properties
namesrvAddr=192.168.223.41:9876;192.168.223.42:9876
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
listenPort=10911
storePathRootDir=/home/rocketmq/store-a
[root@node02]#vim /rocketmq-all-4.3.2-bin-release/conf/2m-2s-sync/broker-b.properties
namesrvAddr=192.168.223.41:9876;192.168.223.42:9876
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
listenPort=10911
storePathRootDir=/home/rocketmq/store-b
双slave配置:
[root@node01]#vim /rocketmq-all-4.3.2-bin-release/conf/2m-2s-sync/broker-b-s.properties
namesrvAddr=192.168.223.41:9876;192.168.223.42:9876
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
listenPort=10911
storePathRootDir=/home/rocketmq/store-b
[root@node02]#vim /rocketmq-all-4.3.2-bin-release/conf/2m-2s-sync/broker-a-s.properties
namesrvAddr=192.168.223.41:9876;192.168.223.42:9876
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
listenPort=11011
storePathRootDir=/home/rocketmq/store-a
4.启动4个broker:
命令:nohup sh ./bin/mqbroker –c config_file &
[root@node01 rocketmq-all-4.3.2-bin-release]# nohup sh ./bin/mqbroker -c ./conf/2m-2s-sync/broker-a.properties &
[root@node01 rocketmq-all-4.3.2-bin-release]# nohup sh ./bin/mqbroker -c ./conf/2m-2s-sync/broker-b-s.properties &
[root@node02 rocketmq-all-4.3.2-bin-release]# nohup sh ./bin/mqbroker -c ./conf/2m-2s-sync/broker-b.properties &
[root@node02 rocketmq-all-4.3.2-bin-release]# nohup sh ./bin/mqbroker -c ./conf/2m-2s-sync/broker-a-s.properties &
jps查看效果如下:
5.查看集群状态
可采用图形化界面管理
https://github.com/apache/rocketmq-externals/tree/master/rocketmq-console
图形化界面配置过程参考:
https://yq.aliyun.com/articles/486069?spm=5176.10695662.1996646101.searchclickresult.37e0a3dbrOPWp6
坑1:
下载不同版本rocketmq时,要注意其要求的jdk版本
原因,高版本rocketmq中有MaxMetaspaceSize参数,MaxMetaspaceSize为Java8中新引入的参数
坑2:
启动mqnamesev时候报:
Java HotSpot 64-Bit Server VM warning: INFO: os::commit_memory(0x00000006c0000000, 2147483648, 0) failed; error=‘Cannot allocate memory’ (errno=12)
则需要调整rocketMQ的内存
vim bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms128m -Xmx256m -Xmn256m -XX:PermSize=128m -XX:MaxPermSize=320m"
-Xms 的值一定要比 -Xmx 要小不让,也会报错:
Initial heap size set to a larger value than the maximum heap size
启动mqbroker时报,则修改:
vim bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"