首先,我们准备7台linux服务器,尽可能的在每个服务器上部署一个服务。当然,在实际工作中如果服务器数量不足,那么可以同一台机器部署两个节点,比如:broker-a的主节点与broker-b的从节点部署在一台服务器,broker-a的从节点与broker-b的主节点部署在一台服务器,这样也会节省一些资源,同样也能达到相对的高可用的效果!
192.168.1.1 | namesrv 1 |
192.168.1.2 | namesrv 2 |
192.168.1.3 | namesrv3 |
192.168.1.4 | broker-a |
192.168.1.5 | broker-a-s |
192.168.1.6 | broker-b |
192.168.1.7 | broker-b-s |
1、启动namesrv服务
分别在192.168.1.1、192.168.1.2、192.168.1.3 机器上启动namesrv服务
nohup sh bin/mqnamesrv &
tailf ~/logs/rocketmqlogs/namesrv.log
2、启动broker主节点或从节点
在192.168.1.4服务器上启动broker主节点:
nohup sh bin/mqbroker -c ./conf/2m-2s-sync/broker-a.properties &
在192.168.1.5服务器上启动broker从节点:
nohup sh bin/mqbroker -c ./conf/2m-2s-sync/broker-a-s.properties &
tailf ~/logs/rocketmqlogs/broker.log
192.168.1.6、192.168.1.7 服务器节点,以同样的方式启动.
3、主从节点配置
broker-a.properties配置如下:
rokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
namesrvAddr=192.168.1.1:9876;192.168.1.2:9876;192.168.1.3:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=50000000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/opt/rocketmq/data/store
storePathCommitLog=/opt/rocketmq/data/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH
broker-a-s.properties配置如下:
rokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=1
namesrvAddr=192.168.1.1:9876;192.168.1.2:9876;192.168.1.3:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=false
autoCreateSubscriptionGroup=true
listenPort=10915
deleteWhen=04
fileReservedTime=48
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=50000000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/opt/rocketmq/data/store
storePathCommitLog=/opt/rocketmq/data/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH