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:端口,效果如下:

集群信息如下:

相关推荐
CYRUS_STUDIO2 天前
用 Frida 控制 Android 线程:kill 命令、挂起与恢复全解析
android·linux·逆向
熊猫李2 天前
rootfs-根文件系统详解
linux
dessler2 天前
Hadoop HDFS-高可用集群部署
linux·运维·hdfs
泽泽爱旅行2 天前
awk 语法解析-前端学习
linux·前端
轻松Ai享生活3 天前
5 节课深入学习Linux Cgroups
linux
阿里云云原生3 天前
海量接入、毫秒响应:易易互联携手阿里云构筑高可用物联网消息中枢
rocketmq
christine-rr3 天前
linux常用命令(4)——压缩命令
linux·服务器·redis
三坛海会大神5553 天前
LVS与Keepalived详解(二)LVS负载均衡实现实操
linux·负载均衡·lvs
東雪蓮☆3 天前
深入理解 LVS-DR 模式与 Keepalived 高可用集群
linux·运维·服务器·lvs
乌萨奇也要立志学C++3 天前
【Linux】进程概念(二):进程查看与 fork 初探
linux·运维·服务器