rocketmq 集群搭建 rocketmq最新版本集群,rocketmq双主双从异步集群 rocketmq三台机器集群 虚拟机搭建rocketmq5.1.4集群

1. rocketmq 版本:5.1.4

    集群规划:

    介绍:

2. 准备三台虚拟机机器,分配2g内存。(内存够用可以3g。2g用到了1.7g):三台机器的/etc/hosts修改 worker1. worker2. worker3

    可查看之前文章设置别名的

3. ssh免密登录设置,

   可以查看我之前的文章

#
cd  ~
# 进入ssh文件夹 如果没有。可以ssh 下别的机器,就会生成
cd .ssh

# woker1 设置好之后,就copy到其他机器
# 同理 去设置woker2, worker3

ssh-keygen -t rsa

#copy
ssh-copy-id worker2

# 
ssh-copy-id worker3

4. 在上篇文章中,设置了虚拟机的第一台服务器。将其中的rocketmq 文件发送到其他两台服务器;

5. 文件路径:

 文件路径

  /opt/module/rocketmq-all-5.1.4-bin-release

 # 日志  

 /opt/module/rocketMQ

6. worker2机器 broker-a设置:

# 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.
#brokerClusterName=DefaultCluster
#brokerName=broker-a
#brokerId=0
#deleteWhen=04
#fileReservedTime=48
#brokerRole=ASYNC_MASTER
#flushDiskType=ASYNC_FLUSH

#所属集群名字,名字一样的节点就在同-个集群内
brokerClusterName=DefaultCluster
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-a
#brokerid,0就表示是Master,>0的都是表示Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#在发送消息时,白动创建服务器不存在的topic,默认创建的队列数d
defaultTopicQueueNums=4
#是否允许Broker自动创健Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许Broker自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker对外服务的监听端口
listenPort=10911
#删除文件时间点,默认凌晨4点
deleteWhen=04
#文件保留时间,默认48小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=30000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/opt/module/rocketMQ/store
#commitLog存储路径
storePathCommitLog=/opt/module/rocketMQ/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/module/rocketMQ/store/consumequeue
#消息索引存储路径
storePathIndex=/opt/module/rocketMQ/store/index
#checkpoint文件存储路径
storeCheckpoint=/opt/module/rocketMQ/store/checkpoint
#abort文件存储路径
abortFile=/opt/module/rocketMQ/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker的角色
#-ASYNC MASTER异步复制Master
#-SYNC MASTER同步双写Master
#-SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#-ASYNC FLUSH异步刷盘
#-SYNC FLUSH同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

worker2机器的broker-b-s设置:

# 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.
#brokerClusterName=DefaultCluster
#brokerName=broker-b
#brokerId=1
#deleteWhen=04
#fileReservedTime=48
#brokerRole=SLAVE
#flushDiskType=ASYNC_FLUSH


#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=DefaultCluster
#broker名字,名字一样的节点就是一组主从节点
brokerName=broker-b
#brokerid,0就表示是Master,>0的都是表示slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许Broker自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许Broker自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker对外服务的监听端口
listenPort=11011
#刚除文件时间点,默认凌晨4点
deleteWhen=04
#文件保留时间,默认48小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/opt/module/rocketMQ/storeSlave
#commitLog存储路径
storePathCommitLog=/opt/module/rocketMQ/storeSlave/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/module/rocketMQ/storeSlave/consumequeue
#消息索引存储路径
storePathIndex=/opt/module/rocketMQ/storeSlave/index
#checkpoint文件存储路径
storeCheckpoint=/opt/module/rocketMQ/storeSlave/checkpoint
#abort文件存储路径
abortFile=/opt/module/rocketMQ/storeSlave/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#Broker的角色
#-ASYNC MASTER异步复制Master
#-SYNC MASTER同步双写Master
#-SLAVE
brokerRole=SLAVE
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

7. worker3机器 broker-a-s.properties

# 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.
#brokerClusterName=DefaultCluster
#brokerName=broker-a
#brokerId=1
#deleteWhen=04
#fileReservedTime=48
#brokerRole=SLAVE
#flushDiskType=ASYNC_FLUSH

#所属集群名字,名字··样的节点就在同一个集群内
brokerClusterName=DefaultCluster
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-a
#brokerid,@就表示是Master,>0的都是表示slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#在发送消息时,白动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许Broker自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许Broker自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker对外服务的监听端口
listenPort=11011
#删除文件时间点,默认凌晨4点
deleteWhen=04
#文件保留时间,默认48小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/opt/module/rocketMQ/storeSlave
#commitLog存储路径
storePathCommitLog=/opt/module/rocketMQ/storeSlave/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/module/rocketMQ/storeSlave/consumequeue
#消息索引存储路径
storePathIndex=/opt/module/rocketMQ/storeSlave/index
#checkpoint文件存储路径
storeCheckpoint=/opt/module/rocketMQ/storeSlave/checkpoint
#abort文件存储路径
abortFile=/opt/module/rocketMQ/storeSlave/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker的角色
#-ASYNC MASTER异步复制Master
#-SYNC MASTER同步双写Master
#-SLAVE
brokerRole=SLAVE
#刷盘方式
#-ASYNC FLUSH异步刷盘
#-SYNC FLUSH同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPooINums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

worker3机器broker-b参数:

# 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.
#brokerClusterName=DefaultCluster
#brokerName=broker-b
#brokerId=0
#deleteWhen=04
#fileReservedTime=48
#brokerRole=ASYNC_MASTER
#flushDiskType=ASYNC_FLUSH


#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=DefaultCluster
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-b
#brokerid,0就表示是Master,>0的都是表示
slaveBrokerId=0
#nameServer地址,分号分割
namesrvAddr=worker1:9876;worker2:9876;worker3:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许Broker自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许Broker自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker对外服务的监听端口
listenPort=10911
#删除文件时间点,默认凌晨4点
deleteWhen=04
#文件保留时间,默认48小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLoq=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/opt/module/rocketMQ/store
#commitLog存储路径
storePathCommitLog=/opt/module/rocketMQ/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/opt/module/rocketMQ/store/consumequeue
#消息索引存储路径
storePathIndex=/opt/module/rocketMQ/store/index
#checkpoint文件存储路径
storeCheckpoint=/opt/module/rocketMQ/store/checkpoint
#abort文件存储路径
abortFile=/opt/module/rocketMQ/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000#flushConsumeQueueThoroughInterval=6000
#Broker的角色
#-ASYNC MASTER异步复制Master
#-SYNC MASTER同步双号Master#-SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

8.启动三台机器注册中心

# 注意是三台机器的注册中心都需要输入下面这些命令启动。规划是三台机器都有注册中心


# 进入rocketmq的bin目录下
cd /opt/module/rocketmq-all-5.1.4-bin-release/bin
# 给脚本加权
chmod 777 mqnamesrv
# 启动
# 在bin目录下输入的命令
nohup ./mqnamesrv &

# 查看是否启动成功
tail -10f nohup.out

 9. 启动worker2机器broker:

nohup ./mqbroker -c ../conf/2m-2s-async/broker-a.properties  &

 nohup ./mqbroker -c ../conf/2m-2s-async/broker-b-s.properties  &

输出:

10.启动worker3机器节点的broker

 nohup ./mqbroker -c ../conf/2m-2s-async/broker-b.properties  &

 nohup ./mqbroker -c ../conf/2m-2s-async/broker-a-s.properties  &

 11.测试集群, worker2发送消息:


# /bin目录下
./tools.sh org.apache.rocketmq.example.quickstart.Producer

12. 测试集群, worker3接收消息:

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

13. 测试集群b方案: worker3发送:

14.测试集群b方案:worker2接收:

15. 如何关闭broker:

#依次在worker2 ,worker3机器 输入关闭命令
./mqshutdown broker

# jps查看是否已经关闭, 稍微等待会,关闭的有点慢
jps