优点:
缺点:
在broker节点中,每一个master配置一个slave。producer写数据到master完成后立即得到“写入完成”的响应。后台再异步将master上的数据增量复制到slave。
优点:
缺点:
在broker节点中,每一个master配置一个slave。producer写数据时,同步向master和slave同步写入,都写入成功才向producer返回“写入成功”的响应。
优点:
缺点:
前提:在RocketMQ4.5版本以后提供了DLedger集群架构,要求一个broker集群中至少要提供有三个broker集群分片(即多对“1master多slave”),一旦master节点宕机,DLedger会自动从剩下的多个slave中选举出一个新的master继续对外提供服务。master与slave之间的数据同步可以支持异步模式和同步模式。
优点:
缺点:
集群使用交叉部署:三台机器,每台各自装一个nameserver,三个broker:一个master,两个其他brokber的slave。采用异步复制模式
【node1】10.90.19.243 namesever-1、master-a、c-slave1
【node2】10.90.19.245 namesever-2、master-b、a-slave1
【node3】10.90.19.246 namesever-3、master-c、b-slave1
nameserver节点时彼此独立的,每个节点的数据都是完整的一份,并不是真正意义上的“集群”
1.上传二进制版本的rocketmq安装文件/tmp目录
2.【node1】创建目录,并解压安装文件到/usr/local/rocketmq/rocketmq-nameserver
【node1】
mkdir -p /usr/local/rocketmq
cd /usr/local/rocketmq
unzip /tmp/rocketmq-all-4.9.1-bin-release.zip -d /usr/local/rocketmq/
cp -r rocketmq-all-4.9.1-bin-release rocketmq-nameserver
rm -rf rocketmq-all-4.9.1-bin-release
3.创建数据目录和日志目录
mkdir -p /usr/local/rocketmq/rocketmq-nameserver/data
mkdir -p /usr/local/rocketmq/rocketmq-nameserver/logs
4.【node1】创建nameserver.conf的配置文件,并修改
touch /usr/local/rocketmq/rocketmq-nameserver/conf/nameserver.conf
cat>/usr/local/rocketmq/rocketmq-nameserver/conf/nameserver.conf<<EOF
#数据保存目录,需要配置,不配置的话默认在/root/namesrv
kvConfigPath=/usr/local/rocketmq/rocketmq-nameserver/data/kvConfig.json
#是否启用Epoll IO模型
useEpollNativeSelector=true
#端口
listenPort=9876
EOF
5.【node1]修改nameserver的日志路径
/usr/local/rocketmq/rocketmq-nameserver/conf/logback_namesrv.xml
sed -i 's?${user.home}/logs/rocketmqlogs?/usr/local/rocketmq/rocketmq-nameserver/logs?' logback_namesrv.xml
6.【node1]修改启动脚本脚本
根据硬件配置修改JVM参数
更改前:JAVA_OPT=“${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m”
更改后:JAVA_OPT=“${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m”
sed -i 's#${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m#${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m#' /usr/local/rocketmq/rocketmq-nameserver/bin/runserver.sh
7.【node1】启动nameserver
nohup sh /usr/local/rocketmq/rocketmq-nameserver/bin/mqnamesrv -c /usr/local/rocketmq/rocketmq-nameserver/conf/nameserver.conf >/dev/null 2>&1 &
#日志中有如下输出,说明nameserver启动成功
……
2022-04-13 11:42:22 INFO main - The Name Server boot success. serializeType=JSON
8.将【node1】/usr/local/rocketmq/rocketmq-nameserver
整个目录拷贝到node2,node3上后,直接启动nameserver即可。
nohup sh /usr/local/rocketmq/rocketmq-nameserver/bin/mqnamesrv -c /usr/local/rocketmq/rocketmq-nameserver/conf/nameserver.conf >/dev/null 2>&1 &
至此nameserver集群搭建完成
先搭建一个master-a,验证启动后,再修改配置复制到其他节点即可。
步骤:
1.上传二进制版本的rocketmq安装文件/tmp目录
2.【node1】创建目录,并解压安装文件到/usr/local/rocketmq/rocketmq-a-m
【node1】
mkdir -p /usr/local/rocketmq
cd /usr/local/rocketmq
unzip /tmp/rocketmq-all-4.9.1-bin-release.zip -d /usr/local/rocketmq/
cp -r rocketmq-all-4.9.1-bin-release rocketmq-a-m
rm -rf rocketmq-all-4.9.1-bin-release
3.创建数据目录和日志目录
mkdir -p /usr/local/rocketmq/rocketmq-a-m/store
mkdir -p /usr/local/rocketmq/rocketmq-a-m/store/commitlog
mkdir -p /usr/local/rocketmq/rocketmq-a-m/store/consumequeue
mkdir -p /usr/local/rocketmq/rocketmq-a-m/logs
4.修改broker配置文件
可用配置
cat>/usr/local/rocketmq/rocketmq-a-m/conf/broker.conf<<EOF
#端口(注意:broker启动后,会占用3个端口,默认是10911(供客户端连接)。分别在listenPort基础上-2(实现Master与Slave之间的数据同步)。+1(实现HA机制的监听端口)。
#如果单机上部署有个broker,除以不要端口冲突了,该例中可以将a-slave1的listenPort修改为任意一个不要冲突的端口
listenPort = 10911
#RocketMQ主目录
rocketmqHome = /usr/local/rocketmq/rocketmq-a-m
#消息数据存放的根目录
storePathRootDir = /usr/local/rocketmq/rocketmq-a-m/store
#commitlog保存目录
storePathCommitLog = /usr/local/rocketmq/rocketmq-a-m/store/commitlog
#消费队列存储路径存储路径
storePathConsumerQueue = /usr/local/rocketmq/rocketmq-a-m/store/consumequeue
#broker集群名称
brokerClusterName = Rocketmq01
#nameserver地址,多个以分号隔开
namesrvAddr=10.90.19.243:9876;10.90.19.245:9876;10.90.19.246:9876
#broker名称(每组主从节点使用相同的brokerName,方便查看)
brokerName = broker-a
#Broker对外提供服务地址
brokerIP1 = 10.90.19.243
#供slave同步消息的地址
brokerIP2= 10.90.19.243
#broker的id,0为主,非0为从
brokerId = 0
#删除文件时间点,默认凌晨4点。24小时制,单位小时
deleteWhen = 04
#文件保存小时数
fileReservedTime = 72
#SYNC_MASTER/ASYNC_MASTER/SLAVE 节点角色
brokerRole = ASYNC_MASTER
#刷盘方式
flushDiskType = ASYNC_FLUSH
#是否允许Broker自动创建Topic
autoCreateTopicEnable = false
#是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup = false
#linux开启epoll
useEpollNativeSelector = true
EOF
5.修改日志文件保存路径
sed -i 's?${user.home}/logs/rocketmqlogs?/usr/local/rocketmq/rocketmq-a-m/logs?' /usr/local/rocketmq/rocketmq-a-m/conf/logback_broker.xml
sed -i 's?${user.home}/logs/rocketmqlogs?/usr/local/rocketmq/rocketmq-a-m/logs?' /usr/local/rocketmq/rocketmq-a-m/conf/logback_namesrv.xml
sed -i 's?${user.home}/logs/rocketmqlogs?/usr/local/rocketmq/rocketmq-b-m/logs?' /usr/local/rocketmq/rocketmq-a-m/conf/logback_tools.xml
6.修改broker启动脚本runbroker.sh
修改JVM参数,GC日志路径(可选)
更改前:JAVA_OPT=“${JAVA_OPT} -server -Xms8g -Xmx8g”
更改后:JAVA_OPT=“${JAVA_OPT} -server -Xms1g -Xmx1g”
sed -i 's#JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g"#JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g"#' /usr/local/rocketmq/rocketmq-a-m/bin/runbroker.sh
7.【node1】启动broker-a 的master
nohup /usr/local/rocketmq/rocketmq-a-m/bin/mqbroker -c /usr/local/rocketmq/rocketmq-a-m/conf/broker.conf > /dev/null 2>&1 &
如下表示master-a的broker启动成功:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-cSipICCB-1649844551370)(D:\Users\80338871\AppData\Roaming\Typora\typora-user-images\image-20220413142625305.png)]
参考“【node1】搭建master-a”。
1.从【node1】拷贝整个/usr/local/rocketmq/rocketmq-a-m/
到【node2】,并解压
tar -zxf rocketmq-a-m.tar.gz -C /usr/local/rocketmq/
mv /usr/local/rocketmq/rocketmq-a-m /usr/local/rocketmq/rocketmq-a-s1
2.创建数据目录和日志目录
rm -rf /usr/local/rocketmq/rocketmq-a-s1/store && mkdir -p /usr/local/rocketmq/rocketmq-a-s1/store
rm -rf /usr/local/rocketmq/rocketmq-a-s1/logs && mkdir -p /usr/local/rocketmq/rocketmq-a-s1/store/commitlog
mkdir -p /usr/local/rocketmq/rocketmq-a-s1/store/consumequeue
mkdir -p /usr/local/rocketmq/rocketmq-a-s1/logs
3.修改配置项
基于master-a的配置,修改:rocketmqHome
,storePathRootDir
,storePathCommitLog
,storePathConsumerQueue
,brokerName
,brokerIP1
,brokerIP2
cat>/usr/local/rocketmq/rocketmq-a-s1/conf/broker.conf<<EOF
#端口(注意:broker启动后,会占用3个端口,默认是10911(供客户端连接)。分别在listenPort基础上-2(实现Master与Slave之间的数据同步)。+1(实现HA机制的监听端口)。
#如果单机上部署有个broker,除以不要端口冲突了
listenPort = 10950
#RocketMQ主目录
rocketmqHome = /usr/local/rocketmq/rocketmq-a-s1
#消息数据存放的根目录
storePathRootDir = /usr/local/rocketmq/rocketmq-a-s1/store
#commitlog保存目录
storePathCommitLog = /usr/local/rocketmq/rocketmq-a-s1/store/commitlog
#消费队列存储路径存储路径
storePathConsumerQueue = /usr/local/rocketmq/rocketmq-a-s1/store/consumequeue
#broker集群名称
brokerClusterName = Rocketmq01
#nameserver地址,多个以分号隔开
namesrvAddr=10.90.19.243:9876;10.90.19.245:9876;10.90.19.246:9876
#broker名称(每组主从节点使用相同的brokerName,方便查看)
brokerName = broker-a
#Broker对外提供服务地址
brokerIP1 = 10.90.19.245
#供slave同步消息的地址
brokerIP2= 10.90.19.245
#broker的id,0为主,非0为从
brokerId = 1
#删除文件时间点,默认凌晨4点。24小时制,单位小时
deleteWhen = 04
#文件保存小时数
fileReservedTime = 72
#SYNC_MASTER/ASYNC_MASTER/SLAVE 节点角色
brokerRole = ASYNC_MASTER
#刷盘方式
flushDiskType = ASYNC_FLUSH
#是否允许Broker自动创建Topic
autoCreateTopicEnable = false
#是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup = false
#linux开启epoll
useEpollNativeSelector = true
EOF
4.修改日志保存路径
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-a-s1/logs/?' /usr/local/rocketmq/rocketmq-a-s1/conf/logback_broker.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-a-s1/logs/?' /usr/local/rocketmq/rocketmq-a-s1/conf/logback_namesrv.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-a-s1/logs/?' /usr/local/rocketmq/rocketmq-a-s1/conf/logback_tools.xml
5.启动broker-a 的a-slave1
nohup /usr/local/rocketmq/rocketmq-a-s1/bin/mqbroker -c /usr/local/rocketmq/rocketmq-a-s1/conf/broker.conf > /dev/null 2>&1 &
参考“【node1】搭建master-a”。
1.从【node1】拷贝整个/usr/local/rocketmq/rocketmq-a-m/
到【node2】,并解压
tar -zxf rocketmq-a-m.tar.gz -C /usr/local/rocketmq/
mv /usr/local/rocketmq/rocketmq-a-m /usr/local/rocketmq/rocketmq-b-m
2.创建数据目录和日志目录
rm -rf /usr/local/rocketmq/rocketmq-b-m/store && mkdir -p /usr/local/rocketmq/rocketmq-b-m/store
rm -rf /usr/local/rocketmq/rocketmq-b-m/logs && mkdir -p /usr/local/rocketmq/rocketmq-b-m/store/commitlog
mkdir -p /usr/local/rocketmq/rocketmq-b-m/store/consumequeue
mkdir -p /usr/local/rocketmq/rocketmq-b-m/logs
3.修改配置项
基于master-a的配置,修改:rocketmqHome
,storePathRootDir
,storePathCommitLog
,storePathConsumerQueue
,brokerName
,brokerIP1
,brokerIP2
cat>/usr/local/rocketmq/rocketmq-b-m/conf/broker.conf<<EOF
#端口(注意:broker启动后,会占用3个端口,默认是10911(供客户端连接)。分别在listenPort基础上-2(实现Master与Slave之间的数据同步)。+1(实现HA机制的监听端口)。
#如果单机上部署有个broker,除以不要端口冲突了
listenPort = 10911
#RocketMQ主目录
rocketmqHome = /usr/local/rocketmq/rocketmq-b-m
#消息数据存放的根目录
storePathRootDir = /usr/local/rocketmq/rocketmq-b-m/store
#commitlog保存目录
storePathCommitLog = /usr/local/rocketmq/rocketmq-b-m/store/commitlog
#消费队列存储路径存储路径
storePathConsumerQueue = /usr/local/rocketmq/rocketmq-b-m/store/consumequeue
#broker集群名称
brokerClusterName = Rocketmq01
#nameserver地址,多个以分号隔开
namesrvAddr=10.90.19.243:9876;10.90.19.245:9876;10.90.19.246:9876
#broker名称(每组主从节点使用相同的brokerName,方便查看)
brokerName = broker-b
#Broker对外提供服务地址
brokerIP1 = 10.90.19.245
#供slave同步消息的地址
brokerIP2= 10.90.19.245
#broker的id,0为主,非0为从
brokerId = 0
#删除文件时间点,默认凌晨4点。24小时制,单位小时
deleteWhen = 04
#文件保存小时数
fileReservedTime = 72
#SYNC_MASTER/ASYNC_MASTER/SLAVE 节点角色
brokerRole = ASYNC_MASTER
#刷盘方式
flushDiskType = ASYNC_FLUSH
#是否允许Broker自动创建Topic
autoCreateTopicEnable = false
#是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup = false
#linux开启epoll
useEpollNativeSelector = true
EOF
4.修改日志保存路径
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-b-m/logs/?' /usr/local/rocketmq/rocketmq-b-m/conf/logback_broker.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-b-m/logs/?' /usr/local/rocketmq/rocketmq-b-m/conf/logback_namesrv.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-b-m/logs/?' /usr/local/rocketmq/rocketmq-b-m/conf/logback_tools.xml
5.启动broker-b 的master-b
nohup /usr/local/rocketmq/rocketmq-b-m/bin/mqbroker -c /usr/local/rocketmq/rocketmq-b-m/conf/broker.conf > /dev/null 2>&1 &
1.从【node1】拷贝整个/usr/local/rocketmq/rocketmq-a-m/
到【node3】,并解压
tar -zxf rocketmq-a-m.tar.gz -C /usr/local/rocketmq/
mv /usr/local/rocketmq/rocketmq-a-m /usr/local/rocketmq/rocketmq-b-s1
2.创建数据目录和日志目录
rm -rf /usr/local/rocketmq/rocketmq-b-m/store && mkdir -p /usr/local/rocketmq/rocketmq-b-m/store
rm -rf /usr/local/rocketmq/rocketmq-b-m/logs && mkdir -p /usr/local/rocketmq/rocketmq-b-m/store/commitlog
mkdir -p /usr/local/rocketmq/rocketmq-b-m/store/consumequeue
mkdir -p /usr/local/rocketmq/rocketmq-b-m/logs
3.修改配置项
基于master-a的配置,修改:rocketmqHome
,storePathRootDir
,storePathCommitLog
,storePathConsumerQueue
,brokerName
,brokerIP1
,brokerIP2
cat>/usr/local/rocketmq/rocketmq-b-s1/conf/broker.conf<<EOF
#端口(注意:broker启动后,会占用3个端口,默认是10911(供客户端连接)。分别在listenPort基础上-2(实现Master与Slave之间的数据同步)。+1(实现HA机制的监听端口)。
#如果单机上部署有个broker,除以不要端口冲突了
listenPort = 10950
#RocketMQ主目录
rocketmqHome = /usr/local/rocketmq/rocketmq-b-s1
#消息数据存放的根目录
storePathRootDir = /usr/local/rocketmq/rocketmq-b-s1/store
#commitlog保存目录
storePathCommitLog = /usr/local/rocketmq/rocketmq-b-s1/store/commitlog
#消费队列存储路径存储路径
storePathConsumerQueue = /usr/local/rocketmq/rocketmq-b-s1/store/consumequeue
#broker集群名称
brokerClusterName = Rocketmq01
#nameserver地址,多个以分号隔开
namesrvAddr=10.90.19.243:9876;10.90.19.245:9876;10.90.19.246:9876
#broker名称(每组主从节点使用相同的brokerName,方便查看)
brokerName = broker-b
#Broker对外提供服务地址
brokerIP1 = 10.90.19.246
#供slave同步消息的地址
brokerIP2= 10.90.19.246
#broker的id,0为主,非0为从
brokerId = 1
#删除文件时间点,默认凌晨4点。24小时制,单位小时
deleteWhen = 04
#文件保存小时数
fileReservedTime = 72
#SYNC_MASTER/ASYNC_MASTER/SLAVE 节点角色
brokerRole = SLAVE
#刷盘方式
flushDiskType = ASYNC_FLUSH
#是否允许Broker自动创建Topic
autoCreateTopicEnable = false
#是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup = false
#linux开启epoll
useEpollNativeSelector = true
EOF
4.修改日志保存路径
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-b-m/logs/?' logback_broker.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-b-m/logs/?' logback_namesrv.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-b-m/logs/?' logback_tools.xml
5.启动broker-b的b-slave1
nohup /usr/local/rocketmq/rocketmq-b-m/bin/mqbroker -c /usr/local/rocketmq/rocketmq-b-m/conf/broker.conf > /dev/null 2>&1 &
1.从【node1】拷贝整个/usr/local/rocketmq/rocketmq-a-m/
到【node2】,并解压
tar -zxf rocketmq-a-m.tar.gz -C /usr/local/rocketmq/
mv /usr/local/rocketmq/rocketmq-a-m /usr/local/rocketmq/rocketmq-c-m
2.创建数据目录和日志目录
rm -rf /usr/local/rocketmq/rocketmq-c-m/store && mkdir -p /usr/local/rocketmq/rocketmq-c-m/store
rm -rf /usr/local/rocketmq/rocketmq-c-m/logs && mkdir -p /usr/local/rocketmq/rocketmq-c-m/store/commitlog
mkdir -p /usr/local/rocketmq/rocketmq-c-m/store/consumequeue
mkdir -p /usr/local/rocketmq/rocketmq-c-m/logs
3.修改配置项
基于master-a的配置,修改:rocketmqHome
,storePathRootDir
,storePathCommitLog
,storePathConsumerQueue
,brokerName
,brokerIP1
,brokerIP2
cat>/usr/local/rocketmq/rocketmq-c-m/conf/broker.conf<<EOF
#端口(注意:broker启动后,会占用3个端口,默认是10911(供客户端连接)。分别在listenPort基础上-2(实现Master与Slave之间的数据同步)。+1(实现HA机制的监听端口)。
#如果单机上部署有个broker,除以不要端口冲突了
listenPort = 10911
#RocketMQ主目录
rocketmqHome = /usr/local/rocketmq/rocketmq-c-m
#消息数据存放的根目录
storePathRootDir = /usr/local/rocketmq/rocketmq-c-m/store
#commitlog保存目录
storePathCommitLog = /usr/local/rocketmq/rocketmq-c-m/store/commitlog
#消费队列存储路径存储路径
storePathConsumerQueue = /usr/local/rocketmq/rocketmq-c-m/store/consumequeue
#broker集群名称
brokerClusterName = Rocketmq01
#nameserver地址,多个以分号隔开
namesrvAddr=10.90.19.243:9876;10.90.19.245:9876;10.90.19.246:9876
#broker名称(每组主从节点使用相同的brokerName,方便查看)
brokerName = broker-c
#Broker对外提供服务地址
brokerIP1 = 10.90.19.246
#供slave同步消息的地址
brokerIP2= 10.90.19.246
#broker的id,0为主,非0为从
brokerId = 0
#删除文件时间点,默认凌晨4点。24小时制,单位小时
deleteWhen = 04
#文件保存小时数
fileReservedTime = 72
#SYNC_MASTER/ASYNC_MASTER/SLAVE 节点角色
brokerRole = ASYNC_MASTER
#刷盘方式
flushDiskType = ASYNC_FLUSH
#是否允许Broker自动创建Topic
autoCreateTopicEnable = false
#是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup = false
#linux开启epoll
useEpollNativeSelector = true
EOF
4.修改日志保存路径
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-c-m/logs/?' /usr/local/rocketmq/rocketmq-c-m/conf/logback_broker.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-c-m/logs/?' /usr/local/rocketmq/rocketmq-c-m/conf/logback_namesrv.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-c-m/logs/?' /usr/local/rocketmq/rocketmq-c-m/conf/logback_tools.xml
5.启动broker-c 的master-c
nohup /usr/local/rocketmq/rocketmq-c-m/bin/mqbroker -c /usr/local/rocketmq/rocketmq-c-m/conf/broker.conf > /dev/null 2>&1 &
参考“【node1】搭建master-a”。
1.从【node1】拷贝整个/usr/local/rocketmq/rocketmq-a-m/
到【node2】,并解压
tar -zxf rocketmq-a-m.tar.gz -C /usr/local/rocketmq/
mv /usr/local/rocketmq/rocketmq-a-m /usr/local/rocketmq/rocketmq-c-s1
2.创建数据目录和日志目录
rm -rf /usr/local/rocketmq/rocketmq-c-s1/store && mkdir -p /usr/local/rocketmq/rocketmq-c-s1/store
rm -rf /usr/local/rocketmq/rocketmq-c-s1/logs && mkdir -p /usr/local/rocketmq/rocketmq-c-s1/store/commitlog
mkdir -p /usr/local/rocketmq/rocketmq-c-s1/store/consumequeue
mkdir -p /usr/local/rocketmq/rocketmq-c-s1/logs
3.修改配置项
基于master-a的配置,修改:rocketmqHome
,storePathRootDir
,storePathCommitLog
,storePathConsumerQueue
,brokerName
,brokerIP1
,brokerIP2
cat>/usr/local/rocketmq/rocketmq-c-s1/conf/broker.conf<<EOF
#端口(注意:broker启动后,会占用3个端口,默认是10911(供客户端连接)。分别在listenPort基础上-2(实现Master与Slave之间的数据同步)。+1(实现HA机制的监听端口)。
#如果单机上部署有个broker,除以不要端口冲突了
listenPort = 10950
#RocketMQ主目录
rocketmqHome = /usr/local/rocketmq/rocketmq-c-s1
#消息数据存放的根目录
storePathRootDir = /usr/local/rocketmq/rocketmq-c-s1/store
#commitlog保存目录
storePathCommitLog = /usr/local/rocketmq/rocketmq-c-s1/store/commitlog
#消费队列存储路径存储路径
storePathConsumerQueue = /usr/local/rocketmq/rocketmq-c-s1/store/consumequeue
#broker集群名称
brokerClusterName = Rocketmq01
#nameserver地址,多个以分号隔开
namesrvAddr=10.90.19.243:9876;10.90.19.245:9876;10.90.19.246:9876
#broker名称(每组主从节点使用相同的brokerName,方便查看)
brokerName = broker-c
#Broker对外提供服务地址
brokerIP1 = 10.90.19.246
#供slave同步消息的地址
brokerIP2= 10.90.19.246
#broker的id,0为主,非0为从
brokerId = 1
#删除文件时间点,默认凌晨4点。24小时制,单位小时
deleteWhen = 04
#文件保存小时数
fileReservedTime = 72
#SYNC_MASTER/ASYNC_MASTER/SLAVE 节点角色
brokerRole = SLAVE
#刷盘方式
flushDiskType = ASYNC_FLUSH
#是否允许Broker自动创建Topic
autoCreateTopicEnable = false
#是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup = false
#linux开启epoll
useEpollNativeSelector = true
EOF
4.修改日志保存路径
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-c-s1/logs/?' /usr/local/rocketmq/rocketmq-c-s1/conf/logback_broker.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-c-s1/logs/?' /usr/local/rocketmq/rocketmq-c-s1/conf/logback_namesrv.xml
sed -i 's?/usr/local/rocketmq/rocketmq-a-m/logs/?/usr/local/rocketmq/rocketmq-c-s1/logs/?' /usr/local/rocketmq/rocketmq-c-s1/conf/logback_tools.xml
5.启动broker-c 的c-slave1
nohup /usr/local/rocketmq/rocketmq-c-s1/bin/mqbroker -c /usr/local/rocketmq/rocketmq-c-s1/conf/broker.conf > /dev/null 2>&1 &
在集群中任意一个节点的bin目录下执行如下命令:sh mqadmin clusterList -n 10.90.19.243:9876
.
至此rocketmq '3主3从,3个nameserver’的集群已经搭建好了。集群信息如下:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-suW0Vuv9-1649844551370)(D:\Users\80338871\AppData\Roaming\Typora\typora-user-images\image-20220413165348138.png)]
步骤同“多主多从异步复制模式”唯一的区别是在调整每个broker.conf中的如下两个配置: