RocketMQ broker迁移测试

Rocketmq 迁移测试

实验环境

• 测试环境
• rocketmq版本4.0.0

二、实验架构
  1. nameserver 172.16.0.142:9879
  2. broker-a 172.16.0.140:10933 master
  3. broker-b 172.16.0.146:10933 master
  4. console 172.16.0.142:8089 控制台
三、配置文件
1、broker-a
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=72
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
namesrvAddr=172.16.0.142:9879;
brokerIP1=172.16.0.140
storePathRootDir=/opt/app/rocketmq-test/store
storePathCommitLog=/opt/app/rocketmq-test/store/commitlog
storePathConsumerQueue=/opt/app/rocketmq-test/store/consumequeue
mapedFileSizeCommitLog=1G
waitTimeMillsInSendQueue = 2000
listenPort = 10933
2、broker-b
brokerClusterName = DefaultCluster
brokerName = broker-b
brokerId = 0
deleteWhen = 04
fileReservedTime = 72
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
namesrvAddr = 172.16.0.142:9879
brokerIP1 = 172.16.0.146
listenPort = 10933
storePathRootDir=/opt/app/rocketmq-test/store
storePathCommitLog=/opt/app/rocketmq-test/store/commitlog
storePathConsumerQueue=/opt/app/rocketmq-test/store/consumequeue
mapedFileSizeCommitLog=1G
waitTimeMillsInSendQueue = 2000
四、目录结构

/opt/app/rocketmq-test
├── benchmark
├── bin
├── conf
│ ├── 2m-2s-async
│ ├── 2m-2s-sync
│ └── 2m-noslave
├── lib
├── logs
│ └── rocketmqlogs
└── store
├── commitlog
├── config
├── consumequeue
└── index
14 directories

生产消息

• 生产者(nameserver所在服务器上使用)
tools.sh org.apache.rocketmq.example.quickstart.Producer
• 消费者,在broker搭建完成后先使用
tools.sh org.apache.rocketmq.example.quickstart.Consumer确认broker中没有信息,因为每当broker重启的时候控制台中的消费计数器数据会归零,但是实际broker是消息是没有丢失的。
RocketMQ broker迁移测试_第1张图片
• 首先 export NAMESRV_ADDR=172.16.0.142:9879
• 在生产消息tools.sh org.apache.rocketmq.example.quickstart.Producer会出现发生成功信息
SendResult [sendStatus=SEND_OK, msgId=C0A817D07578266474C22B6BABC203E4, offsetMsgId=AC10009200002AB50000000000015D3F, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-b, queueId=1], queueOffset=124]
会看到每个broker都各种收到500条信息

迁移broker

此时停掉broker-a 并迁移到broker-b的所在机器(172.16.0.146)
killbroker-a的进程后观察日志是否正常结束掉

# » tail -f logs/rocketmqlogs/store.log 
2019-04-09 10:44:58 INFO FlushRealTimeService - FlushRealTimeService service end
2019-04-09 10:44:58 INFO ReputMessageService - ReputMessageService service end
2019-04-09 10:44:58 INFO FlushConsumeQueueService - FlushConsumeQueueService service end
2019-04-09 10:44:58 WARN AllocateMappedFileService - AllocateMappedFileService interrupted, possibly by shutdown.
2019-04-09 10:44:58 INFO AllocateMappedFileService - AllocateMappedFileService service end
2019-04-09 10:44:58 INFO ShutdownHook - delete pre allocated maped file, /opt/app/rocketmq-test/store/commitlog/00000000001073741824
2019-04-09 10:44:58 INFO ShutdownHook - unmap file[REF:0] /opt/app/rocketmq-test/store/commitlog/00000000001073741824 OK
2019-04-09 10:44:58 INFO ShutdownHook - close file channel /opt/app/rocketmq-test/store/commitlog/00000000001073741824 OK
2019-04-09 10:44:58 INFO ShutdownHook - delete file[REF:0] /opt/app/rocketmq-test/store/commitlog/00000000001073741824 OK, W:0 M:0, 64
2019-04-09 10:44:59 INFO ShutdownHook - /opt/app/rocketmq-test/store/abort delete OK
# » tail -f logs/rocketmqlogs/broker.log 
2019-04-09 10:44:58 INFO ShutdownHook - shutdown thread StoreStatsService interrupt false
2019-04-09 10:44:58 INFO ShutdownHook - join thread StoreStatsService eclipse time(ms) 0 90000
2019-04-09 10:44:58 INFO ShutdownHook - shutdown thread FlushRealTimeService interrupt false
2019-04-09 10:44:58 INFO ShutdownHook - join thread FlushRealTimeService eclipse time(ms) 0 300000
2019-04-09 10:44:58 INFO ShutdownHook - shutdown thread ReputMessageService interrupt false
2019-04-09 10:44:58 INFO ShutdownHook - join thread ReputMessageService eclipse time(ms) 1 90000
2019-04-09 10:44:58 INFO ShutdownHook - shutdown thread FlushConsumeQueueService interrupt false
2019-04-09 10:44:58 INFO ShutdownHook - join thread FlushConsumeQueueService eclipse time(ms) 214 60000
2019-04-09 10:44:59 INFO ShutdownHook - unregisterBroker OK, NamesrvAddr: 172.16.0.142:9879
2019-04-09 10:44:59 INFO ShutdownHook - Shutdown hook over, consuming total time(ms): 7847

• 日志在未发生变化后,对rocketmq-test文件夹进行打包
• tar cjf rocketmq-test.tar.bz2 rocketmq-test/
• 解压至 /opt/app/rocketmq-testmove

修改配置文件broker.conf

brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=72
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
namesrvAddr=172.16.0.142:9879;
brokerIP1=172.16.0.146                                                 ##需要修改
storePathRootDir=/opt/app/rocketmq-testmove/store                      ##路径不冲突可不修改
storePathCommitLog=/opt/app/rocketmq-testmove/store/commitlog          ##路径不冲突可不修改
storePathConsumerQueue=/opt/app/rocketmq-testmove/store/consumequeue   ##路径不冲突可不修改
mapedFileSizeCommitLog=1G
waitTimeMillsInSendQueue = 2000
listenPort = 10953                                            ##端口不冲突可不修改

• 修改日志记录地址

cd /opt/app/rocketmq-testmove/conf
sed -i 's@/opt/app/rocketmq-test@/opt/app/rocketmq-testmove@g' logback_*.xml

• 再次启动新节点broker

/opt/app/rocketmq-testmove/bin/mqbroker -c /opt/app/rocketmq-testmove/conf/broker.conf &

• 观察控制台
RocketMQ broker迁移测试_第2张图片
broker-a 地址已经更换,消费计数归零

开始消费

开始消费tools.sh org.apache.rocketmq.example.quickstart.Consumer
RocketMQ broker迁移测试_第3张图片
观察到迁移后的broker-a,保存的500条信息得到消费
再次运行tools.sh org.apache.rocketmq.example.quickstart.Consumer看是否会重复消费

11:38:12.200 [main] DEBUG io.netty.util.Recycler - -Dio.netty.recycler.maxCapacity.default: 262144
11:38:12.208 [NettyClientWorkerThread_1] DEBUG io.netty.buffer.AbstractByteBuf - -Dio.netty.buffer.bytebuf.checkAccessible: true
11:38:12.211 [NettyClientWorkerThread_1] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.level: simple
11:38:12.211 [NettyClientWorkerThread_1] DEBUG io.netty.util.ResourceLeakDetector - -Dio.netty.leakDetection.maxRecords: 4
11:38:12.340 [NettyClientSelector_1] DEBUG io.netty.util.internal.Cleaner0 - java.nio.ByteBuffer.cleaner(): available
Consumer Started.

发现已经无消息可以消费了,broker迁移成功

你可能感兴趣的:(Linux,运维,中间件,linux,centos,服务器)