Linux Centos 环境下搭建RocketMq集群(双主双从)

1、下载rocketmq的包

下载 | RocketMQ

2、配置环境变量

1、编辑环境变量文件:vim /etc/profile

2、加入如下配置:
#rocketmq 4.9.8
ROCKETMQ_HOME=/home/rocketmq/rocketmq-4.9.8
export PATH=${ROCKETMQ_HOME}/bin:${PATH}

3、刷新配置:source /etc/profile

3、修改相关参数

修改bin目录下的runserver.sh如下:

修改bin目录下的runbroker.sh如下:

4、启动和停止nameserver

1、启动命令
nohup sh /bin/mqnamesrv &

2、查看日志
tail -f ~/logs/rocketmq/namesrv.log

3、停止
./mqshutdown namesrv

5、启动和停止broker

1、启动命令
nohup sh /bin/mqbroker autoCreateTopicEnable=true &

2、查看日志
tail -f ~/logs/rocketmq/broker.log

3、停止
./mqshutdown broker

6、rocketmq集群配置

worker1 只需要启动nameserver即可

worker2中配置两个文件:broker-a.properties、broker-b-s.properties

worker3中配置两个文件:broker-b.properties、broker-a-s.properties

四个配置文件如下:

broker-a.properties

#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=rocketmq-cluster
brokerIP1=192.168.10.200
brokerIP2=192.168.10.200
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-a
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=192.168.10.200:9876;192.168.10.201:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
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=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/home/rocketmq-4.9.8/data
#commitLog 存储路径
storePathCommitLog=/home/rocketmq-4.9.8/data/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq-4.9.8/data/consumequeue
#消息索引存储路径
storePathIndex=/home/rocketmq-4.9.8/data/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq-4.9.8/data/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq-4.9.8/data/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

broker-b-s.properties

#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=rocketmq-cluster
brokerIP1=192.168.10.200
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-b
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=100
#nameServer地址,分号分割
namesrvAddr=192.168.10.200:9876;192.168.10.201: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=/home/rocketmq-4.9.8/dataslave
#commitLog 存储路径
storePathCommitLog=/home/rocketmq-4.9.8/dataslave/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq-4.9.8/dataslave/consumequeue
#消息索引存储路径
storePathIndex=/home/rocketmq-4.9.8/dataslave/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq-4.9.8/dataslave/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq-4.9.8/dataslave/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
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

broker-b.properties

#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=rocketmq-cluster
brokerIP1=192.168.10.201
brokerIP2=192.168.10.201
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-b
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=192.168.10.200:9876;192.168.10.201:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
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=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/home/rocketmq-4.9.8/data
#commitLog 存储路径
storePathCommitLog=/home/rocketmq-4.9.8/data/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq-4.9.8/data/consumequeue
#消息索引存储路径
storePathIndex=/home/rocketmq-4.9.8/data/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq-4.9.8/data/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq-4.9.8/data/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

broker-a-s.properties

#所属集群名字,名字一样的节点就在同一个集群内
brokerClusterName=rocketmq-cluster
brokerIP1=192.168.10.201
#broker名字,名字一样的节点就是一组主从节点。
brokerName=broker-a
#brokerid,0就表示是Master,>0的都是表示 Slave
brokerId=100
#nameServer地址,分号分割
namesrvAddr=192.168.10.200:9876;192.168.10.201: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=/home/rocketmq-4.9.8/dataslave
#commitLog 存储路径
storePathCommitLog=/home/rocketmq-4.9.8/dataslave/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq-4.9.8/dataslave/consumequeue
#消息索引存储路径
storePathIndex=/home/rocketmq-4.9.8/dataslave/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq-4.9.8/dataslave/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq-4.9.8/dataslave/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
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128

启动顺序为:先启动3台服务器的nameserver,再启动worker2和worker3中的broker.

进入worker2,进入rocketmq的安装目录,执行一下两行,
nohup bin/mqbroker -c conf/broker-a.properties autoCreateTopicEnable=true &
nohup bin/mqbroker -c conf/broker-b-s.properties autoCreateTopicEnable=true &
查看日志:
tail -f ~/logs/rocketmq/broker.log

进入worker3,进入rocketmq的安装目录,执行一下两行,
nohup bin/mqbroker -c conf/broker-b.properties autoCreateTopicEnable=true &
nohup bin/mqbroker -c conf/broker-a-s.properties autoCreateTopicEnable=true &

7、rockermq-console图形化管理界面

下载地址:
拉取rocketmq-console的源代码
github克隆项目到本地:git clone 
https://github.com/apache/rocketmq-externals.git

gitee克隆项目到本地:git clone 
https://gitee.com/zjj19941/rocketmq-externals-master.git

修改启动端口
对rocketmq-console模块进行打包

将打好的jar包上传至对应的服务器
maven打包命令:mvn package -DskipTests

使用nohup对jar包进行后台启动:nohup java -jar rocketmq-console-ng-xxx.jar &

如果没配置地址的话,可以在启动命令那儿加以下配置:
// > /home/soft/rocketmq/rocketmq-console.log 表示将标准输出重定向到指定的日志文件中;
// 2>&1 表示将标准错误输出也重定向到标准输出中;
nohup java -jar rocketmq-console-ng-1.0.0.jar --rocketmq.config.namesrvAddr='ip1:9876;ip2:9876' > /home/soft/rocketmq/rocketmq-console.log 2>&1 &

浏览器访问localhost:端口,效果如下:

集群信息如下:

相关推荐
起个别名1 分钟前
必须掌握的Linux的九大命令
linux·服务器·网络
胡歌_北京分歌19 分钟前
【CentOS 7 上安装 Oracle JDK 8u333】
java·centos
结衣结衣.19 分钟前
完全理解C语言函数
java·linux·c语言·数据库·经验分享·笔记
零K沁雪20 分钟前
VirtualBox 安装 Ubuntu Server24.04
linux·运维·ubuntu
Hundreds_N27 分钟前
kali改回官方源后更新失败
linux·kali
wenhui.wang1 小时前
Linux/Ubuntu访问局域网共享文件夹
linux·ubuntu
光亮§那方1 小时前
linux - cp 命令
linux·ubuntu
liulanba1 小时前
leetcode--二叉树中的最长交错路径
linux·算法·leetcode
蜗牛学苑_武汉1 小时前
Linux之文本三剑客
linux·运维
WaiSaa2 小时前
Linux内核升级
linux·运维