RocketMQ集群模式-双主双从

RocketMQ集群模式-双主双从

Deng YongJie's blog 367 2022-09-04

rocketmq集群模式:

多master 多slave模式,异步复制

多master 多slave模式,同步复制

多master 模式

单master 模式

RocketMQ四种部署模式的demo配置文件,如下所示:

1. conf
2. ├── 2m-2s-async     //多Master多Slave模式,异步复制
3. │ ├── broker-a.properties
4. │ ├── broker-a-s.properties
5. │ ├── broker-b.properties
6. │ └── broker-b-s.properties
7. ├── 2m-2s-sync      //多Master多Slave 模式,同步复制
8. │ ├── broker-a.properties
9. │ ├── broker-a-s.properties
10. │ ├── broker-b.properties
11. │ └── broker-b-s.properties
12. ├── 2m-noslave     //多Master模式
13. │ ├── broker-a.properties
14. │ ├── broker-b.properties
15. │ └── broker-trace.properties
16. └── broker.conf    //单Master模式

前提条件:先安装jdk8环境

注意:rocketmq可以配置密码,默认无密码、开放全网段。

如果需要配置,则全部机器都要统一配上密码

vim /usr/local/rocketmq/conf/plain_acl.yml
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
globalWhiteRemoteAddresses:
- *   #代表开放全网段

accounts:
- accessKey: xxxxx
  secretKey: AASNBINc3o6lF2BvZ5jDBm
  whiteRemoteAddress:
  admin: true

192.168.31.61

#cat 2m-2s-sync/broker-a.properties
namesrvAddr=192.168.31.61:9876;192.168.31.62:9876
brokerClusterName=VIPCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH
storePathRootDir=/mnt/datastore01/
storePathCommitLog=/mnt/datastore01/commitlog
storePathConsumeQueue=/mnt/datastore01/consumequeue
storeCheckpoint=/mnt/datastore01/checkpoint
storePathIndex=/mnt/datastore01/index
mapedFileSizeConsumeQueue=300000
mapedFileSizeCommitLog=1073741824
fileReservedTime=48
deleteWhen=04
#maxMessageSize=65536

#aclEnable=true
listenPort=10911

nohup /usr/local/rocketmq/bin/mqnamesrv &
nohup /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/2m-2s-sync/broker-a.properties &
nohup java -jar /usr/local/rocketmq-externals-master/rocketmq-console/target/rocketmq-console-ng-1.0.1.jar &

192.168.31.62

#cat 2m-2s-sync/broker-a-s.properties
namesrvAddr=192.168.31.61:9876;192.168.31.62:9876
brokerClusterName=VIPCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
storePathRootDir=/mnt/datastore01/
storePathCommitLog=/mnt/datastore01/commitlog
storePathConsumeQueue=/mnt/datastore01/consumequeue
storeCheckpoint=/mnt/datastore01/checkpoint
storePathIndex=/mnt/datastore01/index
mapedFileSizeConsumeQueue=300000
mapedFileSizeCommitLog=1073741824
fileReservedTime=48
deleteWhen=04
#maxMessageSize=65536

#aclEnable=true
listenPort=10911

nohup /usr/local/rocketmq/bin/mqnamesrv &
nohup /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/2m-2s-sync/broker-a-s.properties &

192.168.31.63

#cat 2m-2s-sync/broker-b.properties 
namesrvAddr=192.168.31.61:9876;192.168.31.62:9876
brokerClusterName=VIPCluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=SYNC_MASTER
flushDiskType=SYNC_FLUSH
storePathRootDir=/mnt/datastore01/
storePathCommitLog=/mnt/datastore01/commitlog
storePathConsumeQueue=/mnt/datastore01/consumequeue
storeCheckpoint=/mnt/datastore01/checkpoint
storePathIndex=/mnt/datastore01/index
mapedFileSizeConsumeQueue=300000
mapedFileSizeCommitLog=1073741824
fileReservedTime=48
deleteWhen=04
#maxMessageSize=65536


#aclEnable=true
listenPort=10911

nohup /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/2m-2s-sync/broker-b.properties &

192.168.31.64

#cat 2m-2s-sync/broker-b-s.properties
namesrvAddr=192.168.31.61:9876;192.168.31.62:9876
brokerClusterName=VIPCluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
storePathRootDir=/mnt/datastore01/
storePathCommitLog=/mnt/datastore01/commitlog
storePathConsumeQueue=/mnt/datastore01/consumequeue
storeCheckpoint=/mnt/datastore01/checkpoint
storePathIndex=/mnt/datastore01/index
mapedFileSizeConsumeQueue=300000
mapedFileSizeCommitLog=1073741824
fileReservedTime=48
deleteWhen=04
#maxMessageSize=65536

#aclEnable=true
listenPort=10911

nohup /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/2m-2s-sync/broker-b-s.properties &

关闭nameserver:

/opt/apps/rocketmq/bin/mqshutdown namesrv

关闭broker:

/opt/apps/rocketmq/bin/mqshutdown broker

部署rocketmq-console