两台电脑搭建RocketMQ 2master2slave-异步复制 集群

Saadiya ·
更新时间:2024-11-10
· 663 次阅读

两台电脑搭建RocketMQ 2master2slave-异步复制 集群

每个Master配置一个Slave,有多对Master-Slave,HA采用异步复制方式,主备有短暂消息延迟(毫秒级),这种模式的优缺点如下:

优点:即使磁盘损坏,消息丢失的非常少,且消息实时性不会受影响,同时Master宕机后,消费者仍然可以从Slave消费,而且此过程对应用透明,不需要人工干预,性能同多Master模式几乎一样; 缺点:Master宕机,磁盘损坏情况下会丢失少量消息。 一、下载 RockerMQ安装包

下载二进制编译包:
https://archive.apache.org/dist/rocketmq/4.4.0/rocketmq-all-4.4.0-bin-release.zip

解压
yum install -y zip unzip
unzip rocketmq-all-4.4.0-bin-release.zip

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-E9f2vByq-1582203350768)(en-resource://database/17258:1)]

二、编辑启动文件

默认启动需要8G内寸机器,如果机器内存小,需要设置启动jvm参数

vim bin/runserver.sh JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn1g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m" vim bin/runbroker.sh JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn1g" 三、机器 IP 信息

NodeA:

192.168.56.101

NodeB:

192.168.56.109

四、编辑配置文件

cd /root/rocketmq-all-4.4.0-bin-release/conf/2m-2s-async

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-c4116fV9-1582203350769)(en-resource://database/17260:1)]

broker-a.properties

brokerClusterName=DefaultCluster brokerName=broker-a brokerId=0 deleteWhen=04 fileReservedTime=48 brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH listenPort=10911 namesrvAddr=192.168.56.101:9876;192.168.56.109:9876 brokerIP1=192.168.56.101 brokerIP2=192.168.56.101 autoCreateSubscriptionGroup=true autoCreateTopicEnable=true storePathRootDir=/home/rocketmq/rocketmq/data storePathCommitLog=/home/rocketmq/rocketmq/data/commitlog storePathConsumeQueue=/home/rocketmq/rocketmq/data/consumequeue storePathIndex=/home/rocketmq/rocketmq/data/index storeCheckpoint=/home/rocketmq/rocketmq/data/checkpoint abortFile=/home/rocketmq/rocketmq/data/abort

broker-a-s.properties

brokerClusterName=DefaultCluster brokerName=broker-a brokerId=1 deleteWhen=04 fileReservedTime=48 brokerRole=SLAVE flushDiskType=ASYNC_FLUSH listenPort=15911 namesrvAddr=192.168.56.101:9876;192.168.56.109:9876 brokerIP1=192.168.56.109 autoCreateSubscriptionGroup=true autoCreateTopicEnable=true storePathRootDir=/home/rocketmq/slave/rocketmq/data storePathCommitLog=/home/rocketmq/slave/rocketmq/data/commitlog storePathConsumeQueue=/home/rocketmq/slave/rocketmq/data/consumequeue storePathIndex=/home/rocketmq/slave/rocketmq/data/index storeCheckpoint=/home/rocketmq/slave/rocketmq/data/checkpoint abortFile=/home/rocketmq/slave/rocketmq/data/abort

broker-b.properties

brokerClusterName=DefaultCluster brokerName=broker-b brokerId=0 deleteWhen=04 fileReservedTime=48 brokerRole=ASYNC_MASTER flushDiskType=ASYNC_FLUSH listenPort=10911 namesrvAddr=192.168.56.101:9876;192.168.56.109:9876 brokerIP1=192.168.56.109 brokerIP2=192.168.56.109 autoCreateSubscriptionGroup=true autoCreateTopicEnable=true storePathRootDir=/home/rocketmq/rocketmq/data storePathCommitLog=/home/rocketmq/rocketmq/data/commitlog storePathConsumeQueue=/home/rocketmq/rocketmq/data/consumequeue storePathIndex=/home/rocketmq/rocketmq/data/index storeCheckpoint=/home/rocketmq/rocketmq/data/checkpoint abortFile=/home/rocketmq/rocketmq/data/abort

broker-b-s.properties

brokerClusterName=DefaultCluster brokerName=broker-b brokerId=1 deleteWhen=04 fileReservedTime=48 brokerRole=SLAVE flushDiskType=ASYNC_FLUSH listenPort=15911 namesrvAddr=192.168.56.101:9876;192.168.56.109:9876 brokerIP1=192.168.56.101 autoCreateSubscriptionGroup=true autoCreateTopicEnable=true storePathRootDir=/home/rocketmq/slave/rocketmq/data storePathCommitLog=/home/rocketmq/slave/rocketmq/data/commitlog storePathConsumeQueue=/home/rocketmq/slave/rocketmq/data/consumequeue storePathIndex=/home/rocketmq/slave/rocketmq/data/index storeCheckpoint=/home/rocketmq/slave/rocketmq/data/checkpoint abortFile=/home/rocketmq/slave/rocketmq/data/abort 五、启动

注意:一个节点放一主一从

A节点:A master B slave B节点:B maset A slave

nohup sh bin/mqnamesrv > boot.log 2>&1 &

nohup sh bin/mqbroker -c ./conf/2m-2s-async/broker-a.properties >> boot.log 2>&1 &
nohup sh bin/mqbroker -c ./conf/2m-2s-async/broker-b.properties >> boot.log 2>&1 &

nohup sh bin/mqbroker -c ./conf/2m-2s-async/broker-b-s.properties >> boot.log 2>&1 &
nohup sh bin/mqbroker -c ./conf/2m-2s-async/broker-a-s.properties >> boot.log 2>&1 &

六、停止

sh bin/mqshutdown broker
sh bin/mqshutdown namesrv

七、日志查看

tail -f ~/logs/rocketmqlogs/namesrv.log

八、集群状态查看

bin/mqadmin clusterList -n localhost:9876

九、测试消息发送

export NAMESRV_ADDR=localhost:9876

消息生产

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer

消息消费

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

十、简单运维脚本

startNodeA.sh

nohup sh bin/mqnamesrv > boot.log 2>&1 & sleep 30s nohup sh bin/mqbroker -c ./conf/2m-2s-async/broker-a.properties >> boot.log 2>&1 & sleep 60s nohup sh bin/mqbroker -c ./conf/2m-2s-async/broker-b-s.properties >> boot.log 2>&1 &

startNodeB.sh

nohup sh bin/mqnamesrv > boot.log 2>&1 & sleep 30s nohup sh bin/mqbroker -c ./conf/2m-2s-async/broker-b.properties >> boot.log 2>&1 & sleep 60s nohup sh bin/mqbroker -c ./conf/2m-2s-async/broker-a-s.properties >> boot.log 2>&1 &

shutdownBroker.sh

sh bin/mqshutdown broker

shutdownNamesrv.sh

sh bin/mqshutdown namesrv

clusterInfo.sh

sh ./bin/mqadmin clusterList -n localhost:9876

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-7NMXztux-1582203350771)(en-resource://database/17262:1)]

添加脚本可运行权限

chmod +x ./*.sh

注意:作者踩过的坑:

brokerIP1 当前broker监听的IP
brokerIP2 存在broker主从时,在broker主节点上配置了brokerIP2的话,broker从节点会连接主节点配置的brokerIP2来同步

主节点:
brokerIP1 配置当前节点所在节点ip地址
brokerIP2 配置当前节点所在节点ip地址,即从节点需要从该节点同步数据

从节点:
brokerIP1 配置当前节点所在节点ip地址,即从节点所在ip

多nameser 中间分号分隔
namesrvAddr=10.10.10.1:9876;10.10.10.2:9876


作者:书记高育良



rocketmq 集群 异步 电脑 master

需要 登录 后方可回复, 如果你还没有账号请 注册新账号