RocketMQ双Master+双Slave集群环境搭建

RocketMQ双Master+双Slave集群环境搭建

 

1准备四台服务器

JF-pre-rocketmq01   172.21.43.103   第一台Mastewr服务器

JF-pre-rocketmq02   172.21.43.106   第二台Mastewr服务器

JF-pre-rocketmq03   172.21.43.107   第一台Mastewr服务器的Slave服务器

JF-pre-rocketmq04   172.21.43.108   第二台Mastewr服务器的Slave服务器

 

 

2修改四台服务器的主机hosts文件

[root@JF-pre-rocketmq01 ~]# vim /etc/hosts
#RocketMQ Host List
172.21.43.103 JF-pre-rocketmq01
172.21.43.106 JF-pre-rocketmq02
172.21.43.107 JF-pre-rocketmq03
172.21.43.108 JF-pre-rocketmq04

 

 

3上传 alibaba-rocketmq-broker.tar.gz 安装包到/data/目录并解压

[root@JF-pre-rocketmq01 ~]# cd /data/
[root@JF-pre-rocketmq01 data]# tar zxf alibaba-rocketmq-broker.tar.gz

 

 

4为4台服务器创建存储文件夹

[root@JF-pre-rocketmq01 data]# mkdir -p /data/rocketmq/store
[root@JF-pre-rocketmq01 data]# mkdir -p /data/rocketmq/store/commitlog
[root@JF-pre-rocketmq01 data]# mkdir -p /data/rocketmq/store/consumequeue
[root@JF-pre-rocketmq01 data]# mkdir -p /data/rocketmq/store/index

[root@JF-pre-rocketmq01 data]mkdir -p /data/logs/rocketmqlogs

 

 

5、为四台服务器修改配置文件

[root@JF-pre-rocketmq01 data]# cd /data/alibaba-rocketmq/conf/2m-2s-async/
[root@JF-pre-rocketmq01 2m-2s-async]# ll
总用量 16
-rw-rw-r-- 1 root root 935 9月  18 2016 broker-a.properties
-rw-rw-r-- 1 root root 928 9月  18 2016 broker-a-s.properties
-rw-rw-r-- 1 root root 935 9月  18 2016 broker-b.properties
-rw-rw-r-- 1 root root 928 9月  18 2016 broker-b-s.properties

 

第一台Maste主机的broker-a.properties配置文件

[root@JF-pre-rocketmq01 2m-2s-async]# mv broker-a.properties broker-a.properties.bak

[root@JF-pre-rocketmq01 2m-2s-async]# vim broker-a.properties
commercialTimerCount=1
autoCreateTopicEnable=true
waitTimeMillsInSendQueue=200
fetchNamesrvAddrByAddressServer=false
messageStorePlugIn=
highSpeedMode=false
registerBrokerTimeoutMills=6000
brokerIP2=172.21.43.103
brokerIP1=172.21.43.103
defaultTopicQueueNums=4
brokerPermission=6
pullThreadPoolQueueCapacity=10000
commercialBigCount=1
brokerId=0
slaveReadEnable=false
clientManageThreadPoolNums=16
notifyConsumerIdsChangedEnable=true
rejectTransactionMessage=false
commercialTransCount=1
sendThreadPoolQueueCapacity=10000
brokerTopicEnable=true
regionId=DefaultRegion
consumerFallbehindThreshold=0
startAcceptSendRequestTimeStamp=0
filterServerNums=0
namesrvAddr=172.21.43.103:9876;172.21.43.106:9876
rocketmqHome=/data/alibaba-rocketmq
clusterTopicEnable=true
autoCreateSubscriptionGroup=true
pullMessageThreadPoolNums=128
sendMessageThreadPoolNums=128
maxDelayTime=40
brokerClusterName=DefaultCluster
shortPollingTimeMills=1000
flushConsumerOffsetHistoryInterval=60000
transferMsgByHeap=true
adminBrokerThreadPoolNums=16
brokerName=broker-a
longPollingEnable=true
commercialEnable=true
flushConsumerOffsetInterval=5000
disableConsumeIfConsumerReadSlowly=false
storePathCommitLog=/data/rocketmq/store/commitlog
putMsgIndexHightWater=600000
maxTransferBytesOnMessageInDisk=65536
diskMaxUsedSpaceRatio=70
checkCRCOnRecover=true
haSlaveFallbehindMax=268435456
deleteConsumeQueueFilesInterval=100
offsetCheckInSlave=false
cleanResourceInterval=10000
maxMsgsNumBatch=64
flushConsumeQueueLeastPages=2
syncFlushTimeout=5000
deleteWhen=04
duplicationEnable=false
brokerRole=ASYNC_MASTER
defaultQueryMaxNum=32
diskFallRecorded=true
debugLockEnable=false
destroyMapedFileIntervalForcibly=120000
mapedFileSizeCommitLog=1073741824
haSendHeartbeatInterval=5000
flushDiskType=ASYNC_FLUSH
cleanFileForciblyEnable=true
haHousekeepingInterval=20000
redeleteHangedFileInterval=120000
maxMessageSize=65536
flushLeastPagesWhenWarmMapedFile=4096
flushCommitLogTimed=false
maxTransferCountOnMessageInDisk=8
flushIntervalCommitLog=1000
fileReservedTime=72
flushCommitLogThoroughInterval=10000
maxHashSlotNum=5000000
maxIndexNum=20000000
messageIndexEnable=true
storePathRootDir=/data/rocketmq/store/
haListenPort=10912
flushDelayOffsetInterval=10000
warmMapedFileEnable=false
haTransferBatchSize=32768
deleteCommitLogFilesInterval=100
maxTransferBytesOnMessageInMemory=262144
accessMessageInMemoryMaxRatio=40
flushConsumeQueueThoroughInterval=60000
flushIntervalConsumeQueue=1000
osPageCacheBusyTimeOutMills=1000
maxTransferCountOnMessageInMemory=32
messageIndexSafe=false
mapedFileSizeConsumeQueue=50000000
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
flushCommitLogLeastPages=4
serverChannelMaxIdleTimeSeconds=120
listenPort=10911
serverCallbackExecutorThreads=0
serverAsyncSemaphoreValue=64
serverSocketSndBufSize=131072
serverSelectorThreads=3
useEpollNativeSelector=false
serverPooledByteBufAllocatorEnable=true
serverWorkerThreads=8
serverSocketRcvBufSize=131072
serverOnewaySemaphoreValue=256
clientWorkerThreads=4
connectTimeoutMillis=3000
clientSocketRcvBufSize=131072
clientOnewaySemaphoreValue=65535
clientChannelMaxIdleTimeSeconds=120
clientPooledByteBufAllocatorEnable=false
clientAsyncSemaphoreValue=65535
channelNotActiveInterval=60000
clientCallbackExecutorThreads=4
clientSocketSndBufSize=131072
clientCloseSocketIfTimeout=false

 

第二台Maste主机的broker-b.properties配置文件

[root@JF-pre-rocketmq02 ~]# cd /data/alibaba-rocketmq/conf/2m-2s-async

[root@JF-pre-rocketmq02 2m-2s-async]# mv broker-b.properties broker-b.properties.bak
[root@JF-pre-rocketmq02 2m-2s-async]# vim broker-b.properties
commercialTimerCount=1
autoCreateTopicEnable=true
waitTimeMillsInSendQueue=200
fetchNamesrvAddrByAddressServer=false
messageStorePlugIn=
highSpeedMode=false
registerBrokerTimeoutMills=6000
brokerIP2=172.21.43.106
brokerIP1=172.21.43.106
defaultTopicQueueNums=4
brokerPermission=6
pullThreadPoolQueueCapacity=10000
commercialBigCount=1
brokerId=0
slaveReadEnable=false
clientManageThreadPoolNums=16
notifyConsumerIdsChangedEnable=true
rejectTransactionMessage=false
commercialTransCount=1
sendThreadPoolQueueCapacity=10000
brokerTopicEnable=true
regionId=DefaultRegion
consumerFallbehindThreshold=0
startAcceptSendRequestTimeStamp=0
filterServerNums=0
namesrvAddr=172.21.43.103:9876;172.21.43.106:9876
rocketmqHome=/data/alibaba-rocketmq
clusterTopicEnable=true
autoCreateSubscriptionGroup=true
pullMessageThreadPoolNums=128
sendMessageThreadPoolNums=128
maxDelayTime=40
brokerClusterName=DefaultCluster
shortPollingTimeMills=1000
flushConsumerOffsetHistoryInterval=60000
transferMsgByHeap=true
adminBrokerThreadPoolNums=16
brokerName=broker-b
longPollingEnable=true
commercialEnable=true
flushConsumerOffsetInterval=5000
disableConsumeIfConsumerReadSlowly=false
storePathCommitLog=/data/rocketmq/store/commitlog
putMsgIndexHightWater=600000
maxTransferBytesOnMessageInDisk=65536
diskMaxUsedSpaceRatio=70
checkCRCOnRecover=true
haSlaveFallbehindMax=268435456
deleteConsumeQueueFilesInterval=100
offsetCheckInSlave=false
cleanResourceInterval=10000
maxMsgsNumBatch=64
flushConsumeQueueLeastPages=2
syncFlushTimeout=5000
deleteWhen=04
duplicationEnable=false
brokerRole=ASYNC_MASTER
defaultQueryMaxNum=32
diskFallRecorded=true
debugLockEnable=false
destroyMapedFileIntervalForcibly=120000
mapedFileSizeCommitLog=1073741824
haSendHeartbeatInterval=5000
flushDiskType=ASYNC_FLUSH
cleanFileForciblyEnable=true
haHousekeepingInterval=20000
redeleteHangedFileInterval=120000
maxMessageSize=65536
flushLeastPagesWhenWarmMapedFile=4096
flushCommitLogTimed=false
maxTransferCountOnMessageInDisk=8
flushIntervalCommitLog=1000
fileReservedTime=72
flushCommitLogThoroughInterval=10000
maxHashSlotNum=5000000
maxIndexNum=20000000
messageIndexEnable=true
storePathRootDir=/data/rocketmq/store/
haListenPort=10912
flushDelayOffsetInterval=10000
warmMapedFileEnable=false
haTransferBatchSize=32768
deleteCommitLogFilesInterval=100
maxTransferBytesOnMessageInMemory=262144
accessMessageInMemoryMaxRatio=40
flushConsumeQueueThoroughInterval=60000
flushIntervalConsumeQueue=1000
osPageCacheBusyTimeOutMills=1000
maxTransferCountOnMessageInMemory=32
messageIndexSafe=false
mapedFileSizeConsumeQueue=50000000
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
flushCommitLogLeastPages=4
serverChannelMaxIdleTimeSeconds=120
listenPort=10911
serverCallbackExecutorThreads=0
serverAsyncSemaphoreValue=64
serverSocketSndBufSize=131072
serverSelectorThreads=3
useEpollNativeSelector=false
serverPooledByteBufAllocatorEnable=true
serverWorkerThreads=8
serverSocketRcvBufSize=131072
serverOnewaySemaphoreValue=256
clientWorkerThreads=4
connectTimeoutMillis=3000
clientSocketRcvBufSize=131072
clientOnewaySemaphoreValue=65535
clientChannelMaxIdleTimeSeconds=120
clientPooledByteBufAllocatorEnable=false
clientAsyncSemaphoreValue=65535
channelNotActiveInterval=60000
clientCallbackExecutorThreads=4
clientSocketSndBufSize=131072
clientCloseSocketIfTimeout=false
 
 

第一台Slave主机的broker-a-s.properties配置文件

[root@JF-pre-rocketmq03 ~]# cd /data/alibaba-rocketmq/conf/2m-2s-async

[root@JF-pre-rocketmq03 2m-2s-async]# mv broker-a-s.properties broker-a-s.properties.bak
[root@JF-pre-rocketmq03 2m-2s-async]# vim broker-a-s.properties
commercialTimerCount=1
autoCreateTopicEnable=true
waitTimeMillsInSendQueue=200
fetchNamesrvAddrByAddressServer=false
messageStorePlugIn=
highSpeedMode=false
registerBrokerTimeoutMills=6000
brokerIP2=172.21.43.107
brokerIP1=172.21.43.107
defaultTopicQueueNums=4
brokerPermission=6
pullThreadPoolQueueCapacity=10000
commercialBigCount=1
brokerId=1
slaveReadEnable=false
clientManageThreadPoolNums=16
notifyConsumerIdsChangedEnable=true
rejectTransactionMessage=false
commercialTransCount=1
sendThreadPoolQueueCapacity=10000
brokerTopicEnable=true
regionId=DefaultRegion
consumerFallbehindThreshold=0
startAcceptSendRequestTimeStamp=0
filterServerNums=0
namesrvAddr=172.21.43.103:9876;172.21.43.106:9876
rocketmqHome=/data/alibaba-rocketmq
clusterTopicEnable=true
autoCreateSubscriptionGroup=true
pullMessageThreadPoolNums=128
sendMessageThreadPoolNums=128
maxDelayTime=40
brokerClusterName=DefaultCluster
shortPollingTimeMills=1000
flushConsumerOffsetHistoryInterval=60000
transferMsgByHeap=true
adminBrokerThreadPoolNums=16
brokerName=broker-a
longPollingEnable=true
commercialEnable=true
flushConsumerOffsetInterval=5000
disableConsumeIfConsumerReadSlowly=false
storePathCommitLog=/data/rocketmq/store/commitlog
putMsgIndexHightWater=600000
maxTransferBytesOnMessageInDisk=65536
diskMaxUsedSpaceRatio=70
checkCRCOnRecover=true
haSlaveFallbehindMax=268435456
deleteConsumeQueueFilesInterval=100
offsetCheckInSlave=false
cleanResourceInterval=10000
maxMsgsNumBatch=64
flushConsumeQueueLeastPages=2
syncFlushTimeout=5000
deleteWhen=04
duplicationEnable=false
brokerRole=SLAVE
defaultQueryMaxNum=32
diskFallRecorded=true
debugLockEnable=false
destroyMapedFileIntervalForcibly=120000
mapedFileSizeCommitLog=1073741824
haSendHeartbeatInterval=5000
flushDiskType=ASYNC_FLUSH
cleanFileForciblyEnable=true
haHousekeepingInterval=20000
redeleteHangedFileInterval=120000
maxMessageSize=65536
flushLeastPagesWhenWarmMapedFile=4096
flushCommitLogTimed=false
maxTransferCountOnMessageInDisk=8
flushIntervalCommitLog=1000
fileReservedTime=72
flushCommitLogThoroughInterval=10000
maxHashSlotNum=5000000
maxIndexNum=20000000
messageIndexEnable=true
storePathRootDir=/data/rocketmq/store/
haListenPort=10912
flushDelayOffsetInterval=10000
warmMapedFileEnable=false
haTransferBatchSize=32768
deleteCommitLogFilesInterval=100
maxTransferBytesOnMessageInMemory=262144
accessMessageInMemoryMaxRatio=40
flushConsumeQueueThoroughInterval=60000
flushIntervalConsumeQueue=1000
osPageCacheBusyTimeOutMills=1000
maxTransferCountOnMessageInMemory=32
messageIndexSafe=false
mapedFileSizeConsumeQueue=50000000
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
flushCommitLogLeastPages=4
serverChannelMaxIdleTimeSeconds=120
listenPort=10911
serverCallbackExecutorThreads=0
serverAsyncSemaphoreValue=64
serverSocketSndBufSize=131072
serverSelectorThreads=3
useEpollNativeSelector=false
serverPooledByteBufAllocatorEnable=true
serverWorkerThreads=8
serverSocketRcvBufSize=131072
serverOnewaySemaphoreValue=256
clientWorkerThreads=4
connectTimeoutMillis=3000
clientSocketRcvBufSize=131072
clientOnewaySemaphoreValue=65535
clientChannelMaxIdleTimeSeconds=120
clientPooledByteBufAllocatorEnable=false
clientAsyncSemaphoreValue=65535
channelNotActiveInterval=60000
clientCallbackExecutorThreads=4
clientSocketSndBufSize=131072
clientCloseSocketIfTimeout=false

 

 

第二台Slave主机的broker-b-s.properties配置文件

[root@JF-pre-rocketmq04 ~]# cd /data/alibaba-rocketmq/conf/2m-2s-async
[root@JF-pre-rocketmq04 2m-2s-async]# mv broker-b-s.properties broker-b-s.properties.bak
[root@JF-pre-rocketmq04 2m-2s-async]# vim broker-b-s.properties
commercialTimerCount=1
autoCreateTopicEnable=true
waitTimeMillsInSendQueue=200
fetchNamesrvAddrByAddressServer=false
messageStorePlugIn=
highSpeedMode=false
registerBrokerTimeoutMills=6000
brokerIP2=172.21.43.108
brokerIP1=172.21.43.108
defaultTopicQueueNums=4
brokerPermission=6
pullThreadPoolQueueCapacity=10000
commercialBigCount=1
brokerId=1
slaveReadEnable=false
clientManageThreadPoolNums=16
notifyConsumerIdsChangedEnable=true
rejectTransactionMessage=false
commercialTransCount=1
sendThreadPoolQueueCapacity=10000
brokerTopicEnable=true
regionId=DefaultRegion
consumerFallbehindThreshold=0
startAcceptSendRequestTimeStamp=0
filterServerNums=0
namesrvAddr=172.21.43.103:9876;172.21.43.106:9876
rocketmqHome=/data/alibaba-rocketmq
clusterTopicEnable=true
autoCreateSubscriptionGroup=true
pullMessageThreadPoolNums=128
sendMessageThreadPoolNums=128
maxDelayTime=40
brokerClusterName=DefaultCluster
shortPollingTimeMills=1000
flushConsumerOffsetHistoryInterval=60000
transferMsgByHeap=true
adminBrokerThreadPoolNums=16
brokerName=broker-b
longPollingEnable=true
commercialEnable=true
flushConsumerOffsetInterval=5000
disableConsumeIfConsumerReadSlowly=false
storePathCommitLog=/data/rocketmq/store/commitlog
putMsgIndexHightWater=600000
maxTransferBytesOnMessageInDisk=65536
diskMaxUsedSpaceRatio=70
checkCRCOnRecover=true
haSlaveFallbehindMax=268435456
deleteConsumeQueueFilesInterval=100
offsetCheckInSlave=false
cleanResourceInterval=10000
maxMsgsNumBatch=64
flushConsumeQueueLeastPages=2
syncFlushTimeout=5000
deleteWhen=04
duplicationEnable=false
brokerRole=SLAVE
defaultQueryMaxNum=32
diskFallRecorded=true
debugLockEnable=false
destroyMapedFileIntervalForcibly=120000
mapedFileSizeCommitLog=1073741824
haSendHeartbeatInterval=5000
flushDiskType=ASYNC_FLUSH
cleanFileForciblyEnable=true
haHousekeepingInterval=20000
redeleteHangedFileInterval=120000
maxMessageSize=65536
flushLeastPagesWhenWarmMapedFile=4096
flushCommitLogTimed=false
maxTransferCountOnMessageInDisk=8
flushIntervalCommitLog=1000
fileReservedTime=72
flushCommitLogThoroughInterval=10000
maxHashSlotNum=5000000
maxIndexNum=20000000
messageIndexEnable=true
storePathRootDir=/data/rocketmq/store/
haListenPort=10912
flushDelayOffsetInterval=10000
warmMapedFileEnable=false
haTransferBatchSize=32768
deleteCommitLogFilesInterval=100
maxTransferBytesOnMessageInMemory=262144
accessMessageInMemoryMaxRatio=40
flushConsumeQueueThoroughInterval=60000
flushIntervalConsumeQueue=1000
osPageCacheBusyTimeOutMills=1000
maxTransferCountOnMessageInMemory=32
messageIndexSafe=false
mapedFileSizeConsumeQueue=50000000
messageDelayLevel=1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
flushCommitLogLeastPages=4
serverChannelMaxIdleTimeSeconds=120
listenPort=10911
serverCallbackExecutorThreads=0
serverAsyncSemaphoreValue=64
serverSocketSndBufSize=131072
serverSelectorThreads=3
useEpollNativeSelector=false
serverPooledByteBufAllocatorEnable=true
serverWorkerThreads=8
serverSocketRcvBufSize=131072
serverOnewaySemaphoreValue=256
clientWorkerThreads=4
connectTimeoutMillis=3000
clientSocketRcvBufSize=131072
clientOnewaySemaphoreValue=65535
clientChannelMaxIdleTimeSeconds=120
clientPooledByteBufAllocatorEnable=false
clientAsyncSemaphoreValue=65535
channelNotActiveInterval=60000
clientCallbackExecutorThreads=4
clientSocketSndBufSize=131072
clientCloseSocketIfTimeout=false

 

 

6、依次启动 JF-pre-rocketmq01 和 JF-pre-rocketmq02 的 Namesrv 服务进程

[root@JF-pre-rocketmq01 ~]# cd /data/alibaba-rocketmq/bin/

[root@JF-pre-rocketmq01 bin]# nohup sh mqnamesrv &
  
[root@JF-pre-rocketmq02 ~]# cd /data/alibaba-rocketmq/bin/
[root@JF-pre-rocketmq02 bin]# nohup sh mqnamesrv &

7、依次启动四台服务器的 Broker 进程

[root@JF-pre-rocketmq01 ~]# nohup sh mqbroker -c /data/alibaba-rocketmq/conf/2m-2s-async/broker-a.properties > /dev/null 2>&1 &
 
[root@JF-pre-rocketmq02 ~]# nohup sh mqbroker -c /data/alibaba-rocketmq/conf/2m-2s-async/broker-b.properties > /dev/null 2>&1 &
 
[root@JF-pre-rocketmq03 ~]# nohup sh mqbroker -c /data/alibaba-rocketmq/conf/2m-2s-async/broker-a-s.properties > /dev/null 2>&1 &
 
[root@JF-pre-rocketmq04 ~]# nohup sh mqbroker -c /data/alibaba-rocketmq/conf/2m-2s-async/broker-b-s.properties > /dev/null 2>&1 &

 

8.检测

分别检查是否成功启动,检查命令:jps 如果发现有Nameserver和Broker进程在问题基本不大,可以写代码进行测试了

[root@JF-pre-rocketmq01 ~]# cd /usr/java/jdk1.7.0_79/bin/
[root@JF-pre-rocketmq01 bin]# ./jps
47023 Jps
46942 NamesrvStartup
46972 BrokerStartup

 

[root@JF-pre-rocketmq02 ~]# cd /usr/java/jdk1.7.0_79/bin/
[root@JF-pre-rocketmq02 bin]# ./jps
31181 Jps
31092 NamesrvStartup
31127 BrokerStartup

 

[root@JF-pre-rocketmq03 ~]# cd /usr/java/jdk1.7.0_79/bin/
[root@JF-pre-rocketmq03 bin]# ./jps
29740 Jps
29691 BrokerStartup
 
[root@JF-pre-rocketmq04 ~]# cd /usr/java/jdk1.7.0_79/bin/
[root@JF-pre-rocketmq04 bin]# ./jps
29710 Jps
29659 BrokerStartup

 

 

查询集群消息

[root@JF-pre-rocketmq01 bin]# sh mqadmin  clusterList -n 127.0.0.1:9876
#Cluster Name  #Broker Name #BID  #Addr                #Version    #InTPS(LOAD)  #OutTPS(LOAD) #PCWait(ms) #Hour      #SPACE
DefaultCluster broker-a      0     172.21.43.103:10911  V3_5_8      0.00(0,0ms)   0.00(0,0ms)   0           422220.77  0.0484
DefaultCluster broker-a      1     172.21.43.107:10911  V3_5_8      0.00(0,0ms)   0.00(0,0ms)   0           422220.77  0.0373
DefaultCluster broker-b      0     172.21.43.106:10911  V3_5_8      0.00(0,0ms)   0.00(0,0ms)   0           422220.77  0.0373
DefaultCluster broker-b      1     172.21.43.108:10911  V3_5_8      0.00(0,0ms)   0.00(0,0ms)   0           422220.77  0.0373

 

 

 

参考文档:

RocketMQ双Master+双Slave集群环境搭建 http://blog.csdn.net/jianghuiyun/article/details/77971583

RocketMQ 集群搭建 双Master方式 http://zhousw.top/posts/165





原文地址:https://www.cnblogs.com/hello-sky/p/8625673.html