文章目录
🔊博主介绍
🌟我是廖志伟,一名Java开发工程师、Java领域优质创作者、CSDN博客专家、51CTO专家博主、阿里云专家博主、清华大学出版社签约作者、产品软文专业写手、技术文章评审老师、问卷调查设计师、个人社区创始人、开源项目贡献者。🌎跑过十五公里、🚀徒步爬过衡山、🔥有过三个月减肥20斤的经历、是个喜欢躺平的狠人。
📕拥有多年一线研发和团队管理经验,研究过主流框架的底层源码(Spring、SpringBoot、Spring MVC、SpringCould、Mybatis、Dubbo、Zookeeper),消息中间件底层架构原理(RabbitMQ、RockerMQ、Kafka)、Redis缓存、MySQL关系型数据库、 ElasticSearch全文搜索、MongoDB非关系型数据库、Apache ShardingSphere分库分表读写分离、设计模式、领域驱动DDD、Kubernetes容器编排等。
📙有过从0到1的项目高并发项目开发与管理经验,对JVM调优、MySQL调优、Redis调优 、ElasticSearch调优、消息中间件调优、系统架构调优都有着比较全面的实战经验。
📘有过云端搭建服务器环境,自动化部署CI/CD,弹性伸缩扩容服务器(最高200台),了解过秒级部署(阿里云的ACK和华为云的云容器引擎CCE)流程,能独立开发和部署整个后端服务,有过分库分表的实战经验。
🎥经过多年在CSDN创作上千篇文章的经验积累,我已经拥有了不错的写作技巧,与清华大学出版社签下了四本书籍的合约,并将陆续在明年出版。这些书籍包括了基础篇、进阶篇、架构篇的📌《Java项目实战—深入理解大型互联网企业通用技术》📌,以及📚《解密程序员的思维密码–沟通、演讲、思考的实践》📚。具体出版计划会根据实际情况进行调整,希望各位读者朋友能够多多支持!
文章目录
🌾阅读前,快速浏览目录和章节概览可帮助了解文章结构、内容和作者的重点。了解自己希望从中获得什么样的知识或经验是非常重要的。建议在阅读时做笔记、思考问题、自我提问,以加深理解和吸收知识。
💡在这个美好的时刻,本人不再啰嗦废话,现在毫不拖延地进入文章所要讨论的主题。接下来,我将为大家呈现正文内容。
🥤本文内容
首先,需要在Docker-Compose中创建两个RocketMQ Broker容器,一个作为主节点,另一个作为从节点。主从节点之间的数据同步可以通过Dledger实现。以下是详细的步骤:
规划集群
准备好三台机器:
节点0:192.168.80.101
节点1:192.168.80.102
节点2:192.168.80.103
准备工作
在所有机器上执行以下操作:
安装配置JDK,根据实际情况选择版本,注意JDK的版本和RocketMQ的版本是否匹配。
节点0配置(ip地址为192.168.80.101的机器)
创建rocket目录,代码如下:
mkdir -p /opt/software/rocketmqcluster
进入到rocketmq目录,代码如下:
cd /opt/software/rocketmqcluster
创建rocket存储、日志、配置目录,代码如下:
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/store
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/conf
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/logs
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/commitlog
编辑broker-n0的broker属性文件,代码如下:
vi /opt/software/rocketmqcluster/data/broker-n0/conf/broker.properties
添加配置,代码如下:
# broker名,名称一样的节点就是一组主从节点。
brokerName=broker0
# broker对外服务的监听端口
listenPort=30911
# 所属集群名,名称一样的节点就在同一个集群内
brokerClusterName=DefaultCluster
# brokerid,0就表示是Master,>0的都是表示Slave
brokerId=0
# 删除文件时间点,默认凌晨4点
deleteWhen=04
# 文件保留时间,默认48 小时
fileReservedTime=48
# broker角色,ASYNC_MASTER异步复制Master,SYNC_MASTER同步双写Master,SLAVE
brokerRole=ASYNC_MASTER
# 刷盘方式,ASYNC_FLUSH异步刷盘,SYNC_FLUSH同步刷盘
flushDiskType=ASYNC_FLUSH
# broker ip多网卡配置,容器配置宿主机网卡ip
brokerIP1=192.168.80.101
# name-server地址,分号间隔
namesrvAddr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876;
# 存储路径
storePathRootDir=/home/rocketmq/store
# commitLog存储路径
storePathCommitLog=/home/rocketmq/commitlog
# 是否允许broker自动创建Topic
autoCreateTopicEnable=true
# 是否允许broker自动创建订阅组
autoCreateSubscriptionGroup=true
# 是否启动DLedger
enableDLegerCommitLog=true
# DLedger Raft Group的名字,建议和brokerName保持一致
dLegerGroup=broker0
# DLedger Group内各节点的端口信息,同一个Group内的各个节点配置必须要保证一致
dLegerPeers=n0-192.168.80.101:40911;n1-192.168.80.102:40911;n2-192.168.80.103:40911
# 节点id, 必须属于dLegerPeers中的一个;同Group内各个节点要唯一
dLegerSelfId=n0
编辑broker-n1的broker属性文件,代码如下:
vi /opt/software/rocketmqcluster/data/broker-n1/conf/broker.properties
添加配置,代码如下:
brokerName=broker1
listenPort=30912
brokerClusterName=DefaultCluster
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.80.101
namesrvAddr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876;
storePathRootDir=/home/rocketmq/store
storePathCommitLog=/home/rocketmq/commitlog
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
enableDLegerCommitLog=true
dLegerGroup=broker1
dLegerPeers=n0-192.168.80.101:40912;n1-192.168.80.102:40912;n2-192.168.80.103:40912
dLegerSelfId=n0
编辑broker-n2的broker属性文件,代码如下:
vi /opt/software/rocketmqcluster/data/broker-n2/conf/broker.properties
添加配置,代码如下:
brokerName=broker2
listenPort=30913
brokerClusterName=DefaultCluster
brokerId=2
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.80.101
namesrvAddr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876;
storePathRootDir=/home/rocketmq/store
storePathCommitLog=/home/rocketmq/commitlog
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
enableDLegerCommitLog=true
dLegerGroup=broker2
dLegerPeers=n0-192.168.80.101:40913;n1-192.168.80.102:40913;n2-192.168.80.103:40913
dLegerSelfId=n0
创建docker-compose.yaml文件,代码如下:
vi /opt/software/rocketmqcluster/docker-compose.yaml
添加配置,代码如下:
version: '3.5'
services:namesrv:restart: alwaysimage: apache/rocketmq:4.9.4container_name: namesrvports:- 9876:9876environment:- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/namesrv/logs:/home/rocketmq/logs/rocketmqlogs/rocketmqlogscommand: sh mqnamesrvbroker-n0:restart: alwaysimage: apache/rocketmq:4.9.4container_name: broker-n0ports:- 30911:30911- 40911:40911environment:- NAMESRV_ADDR=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876;- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/broker-n0/logs:/home/rocketmq/logs/rocketmqlogs- /opt/software/rocketmqcluster/data/broker-n0/store:/home/rocketmq/store- /opt/software/rocketmqcluster/data/broker-n0/commitlog:/home/rocketmq/commitlog- /opt/software/rocketmqcluster/data/broker-n0/conf/broker.properties:/home/rocketmq/conf/broker.propertiescommand: sh mqbroker -c /home/rocketmq/conf/broker.propertiesbroker-n1:restart: alwaysimage: apache/rocketmq:4.9.4container_name: broker-n1ports:- 30912:30912- 40912:40912environment:- NAMESRV_ADDR=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876;- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/broker-n1/logs:/home/rocketmq/logs/rocketmqlogs- /opt/software/rocketmqcluster/data/broker-n1/store:/home/rocketmq/store- /opt/software/rocketmqcluster/data/broker-n1/commitlog:/home/rocketmq/commitlog- /opt/software/rocketmqcluster/data/broker-n1/conf/broker.properties:/home/rocketmq/conf/broker.propertiescommand: sh mqbroker -c /home/rocketmq/conf/broker.propertiesbroker-n2:restart: alwaysimage: apache/rocketmq:4.9.4container_name: broker-n2ports:- 30913:30913- 40913:40913environment:- NAMESRV_ADDR=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876;- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/broker-n2/logs:/home/rocketmq/logs/rocketmqlogs- /opt/software/rocketmqcluster/data/broker-n2/store:/home/rocketmq/store- /opt/software/rocketmqcluster/data/broker-n2/commitlog:/home/rocketmq/commitlog- /opt/software/rocketmqcluster/data/broker-n2/conf/broker.properties:/home/rocketmq/conf/broker.propertiescommand: sh mqbroker -c /home/rocketmq/conf/broker.properties
# 网络声明
networks:rmq:name: rmq # 指定网络名称driver: bridge # 指定网络驱动程序
# 通用日志设置
x-logging:&default-logging# 日志大小和数量options:max-size: "100m"max-file: "3"# 文件存储类型driver: json-file
节点1配置(ip地址为192.168.80.102的机器)
mkdir -p /opt/software/rocketmqcluster
进入到rocketmq目录,代码如下:
cd /opt/software/rocketmqcluster
创建rocket存储、日志、配置目录,代码如下:
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/store
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/conf
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/logs
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/commitlog
节点1的配置:
vi /opt/software/rocketmqcluster/data/broker-n0/conf/broker.properties
brokerName=broker0
listenPort=30911
brokerClusterName=DefaultCluster
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.80.102
namesrvAddr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876
storePathRootDir=/home/rocketmq/store
storePathCommitLog=/home/rocketmq/commitlog
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
enableDLegerCommitLog=true
dLegerGroup=broker0
dLegerPeers=n0-192.168.80.101:40911;n1-192.168.80.102:40911;n2-192.168.80.103:40911
dLegerSelfId=n1
vi /opt/software/rocketmqcluster/data/broker-n1/conf/broker.properties
brokerName=broker1
listenPort=30912
brokerClusterName=DefaultCluster
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.80.102
namesrvAddr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876
storePathRootDir=/home/rocketmq/store
storePathCommitLog=/home/rocketmq/commitlog
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
enableDLegerCommitLog=true
dLegerGroup=broker1
dLegerPeers=n0-192.168.80.101:40912;n1-192.168.80.102:40912;n2-192.168.80.103:40912
dLegerSelfId=n1
vi /opt/software/rocketmqcluster/data/broker-n2/conf/broker.properties
brokerName=broker2
listenPort=30913
brokerClusterName=DefaultCluster
brokerId=2
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.80.102
namesrvAddr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876
storePathRootDir=/home/rocketmq/store
storePathCommitLog=/home/rocketmq/commitlog
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
enableDLegerCommitLog=true
dLegerGroup=broker2
dLegerPeers=n0-192.168.80.101:40913;n1-192.168.80.102:40913;n2-192.168.80.103:40913
dLegerSelfId=n1
vi /opt/software/rocketmqcluster/docker-compose.yaml
version: '3.5'
services:namesrv:restart: alwaysimage: apache/rocketmq:5.1.3container_name: namesrvports:- 9876:9876environment:- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/namesrv/logs:/home/rocketmq/logs/rocketmqlogscommand: sh mqnamesrvbroker-n0:restart: alwaysimage: apache/rocketmq:5.1.3container_name: broker-n0ports:- 30911:30911- 40911:40911environment:- NAMESRV_ADDR=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/broker-n0/logs:/home/rocketmq/logs/rocketmqlogs- /opt/software/rocketmqcluster/data/broker-n0/store:/home/rocketmq/store- /opt/software/rocketmqcluster/data/broker-n0/commitlog:/home/rocketmq/commitlog- /opt/software/rocketmqcluster/data/broker-n0/conf/broker.properties:/home/rocketmq/conf/broker.propertiescommand: sh mqbroker -c /home/rocketmq/conf/broker.propertiesbroker-n1:restart: alwaysimage: apache/rocketmq:5.1.3container_name: broker-n1ports:- 30912:30912- 40912:40912environment:- NAMESRV_ADDR=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/broker-n1/logs:/home/rocketmq/logs/rocketmqlogs- /opt/software/rocketmqcluster/data/broker-n1/store:/home/rocketmq/store- /opt/software/rocketmqcluster/data/broker-n1/commitlog:/home/rocketmq/commitlog- /opt/software/rocketmqcluster/data/broker-n1/conf/broker.properties:/home/rocketmq/conf/broker.propertiescommand: sh mqbroker -c /home/rocketmq/conf/broker.propertiesbroker-n2:restart: alwaysimage: apache/rocketmq:5.1.3container_name: broker-n2ports:- 30913:30913- 40913:40913environment:- NAMESRV_ADDR=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/broker-n2/logs:/home/rocketmq/logs/rocketmqlogs- /opt/software/rocketmqcluster/data/broker-n2/store:/home/rocketmq/store- /opt/software/rocketmqcluster/data/broker-n2/commitlog:/home/rocketmq/commitlog- /opt/software/rocketmqcluster/data/broker-n2/conf/broker.properties:/home/rocketmq/conf/broker.propertiescommand: sh mqbroker -c /home/rocketmq/conf/broker.properties
# 网络声明
networks:rmq:name: rmq # 指定网络名称driver: bridge # 指定网络驱动程序
# 通用日志设置
x-logging:&default-logging# 日志大小和数量options:max-size: "100m"max-file: "3"# 文件存储类型driver: json-file
节点2配置(ip地址为192.168.80.103的机器)
mkdir -p /opt/software/rocketmqcluster
进入到rocketmq目录,代码如下:
cd /opt/software/rocketmqcluster
创建rocket存储、日志、配置目录,代码如下:
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/store
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/conf
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/logs
mkdir -p /opt/software/rocketmqcluster/data/broker-n{0..2}/commitlog
节点2的配置:
vi /opt/software/rocketmqcluster/data/broker-n0/conf/broker.properties
brokerName=broker0
listenPort=30911
brokerClusterName=DefaultCluster
brokerId=2
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.80.103
namesrvAddr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876
storePathRootDir=/home/rocketmq/store
storePathCommitLog=/home/rocketmq/commitlog
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
enableDLegerCommitLog=true
dLegerGroup=broker0
dLegerPeers=n0-192.168.80.101:40911;n1-192.168.80.102:40911;n2-192.168.80.103:40911
dLegerSelfId=n2
vi /opt/software/rocketmqcluster/data/broker-n1/conf/broker.properties
brokerName=broker1
listenPort=30912
brokerClusterName=DefaultCluster
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.80.103
namesrvAddr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876
storePathRootDir=/home/rocketmq/store
storePathCommitLog=/home/rocketmq/commitlog
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
enableDLegerCommitLog=true
dLegerGroup=broker1
dLegerPeers=n0-192.168.80.101:40912;n1-192.168.80.102:40912;n2-192.168.80.103:40912
dLegerSelfId=n2
vi /opt/software/rocketmqcluster/data/broker-n2/conf/broker.properties
brokerName=broker2
listenPort=30913
brokerClusterName=DefaultCluster
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.80.103
namesrvAddr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876
storePathRootDir=/home/rocketmq/store
storePathCommitLog=/home/rocketmq/commitlog
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
enableDLegerCommitLog=true
dLegerGroup=broker2
dLegerPeers=n0-192.168.80.101:40913;n1-192.168.80.102:40913;n2-192.168.80.103:40913
dLegerSelfId=n2
vi /opt/software/rocketmqcluster/docker-compose.yaml
version: '3.5'
services:namesrv:restart: alwaysimage: apache/rocketmq:5.1.3container_name: namesrv ports:- 9876:9876environment:- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/namesrv/logs:/home/rocketmq/logs/rocketmqlogscommand: sh mqnamesrvbroker-n0:restart: alwaysimage: apache/rocketmq:5.1.3container_name: broker-n0ports:- 30911:30911- 40911:40911environment:- NAMESRV_ADDR=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/broker-n0/logs:/home/rocketmq/logs/rocketmqlogs- /opt/software/rocketmqcluster/data/broker-n0/store:/home/rocketmq/store- /opt/software/rocketmqcluster/data/broker-n0/commitlog:/home/rocketmq/commitlog- /opt/software/rocketmqcluster/data/broker-n0/conf/broker.properties:/home/rocketmq/conf/broker.propertiescommand: sh mqbroker -c /home/rocketmq/conf/broker.propertiesbroker-n1:restart: alwaysimage: apache/rocketmq:5.1.3container_name: broker-n1ports:- 30912:30912- 40912:40912environment:- NAMESRV_ADDR=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/broker-n1/logs:/home/rocketmq/logs/rocketmqlogs- /opt/software/rocketmqcluster/data/broker-n1/store:/home/rocketmq/store- /opt/software/rocketmqcluster/data/broker-n1/commitlog:/home/rocketmq/commitlog- /opt/software/rocketmqcluster/data/broker-n1/conf/broker.properties:/home/rocketmq/conf/broker.propertiescommand: sh mqbroker -c /home/rocketmq/conf/broker.propertiesbroker-n2:restart: alwaysimage: apache/rocketmq:5.1.3container_name: broker-n2ports: - 30913:30913- 40913:40913environment:- NAMESRV_ADDR=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876- JAVA_OPT_EXT=-Duser.home=/home/rocketmq -Xms512m -Xmx512m -Xmn256m -XX:InitiatingHeapOccupancyPercent=30 -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m -XX:SoftRefLRUPolicyMSPerMB=0 -verbose:gc - TZ=Asia/Shanghaivolumes:- /opt/software/rocketmqcluster/data/broker-n2/logs:/home/rocketmq/logs/rocketmqlogs- /opt/software/rocketmqcluster/data/broker-n2/store:/home/rocketmq/store- /opt/software/rocketmqcluster/data/broker-n2/commitlog:/home/rocketmq/commitlog- /opt/software/rocketmqcluster/data/broker-n2/conf/broker.properties:/home/rocketmq/conf/broker.propertiescommand: sh mqbroker -c /home/rocketmq/conf/broker.propertiesconsole:restart: alwaysimage: apacherocketmq/rocketmq-dashboardcontainer_name: consoleports:- 19081:8080environment:TZ: "Asia/Shanghai"JAVA_OPTS: "-Drocketmq.namesrv.addr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"depends_on:- namesrv
# 网络声明
networks:rmq:name: rmq # 指定网络名称driver: bridge # 指定网络驱动程序
# 通用日志设置
x-logging:&default-logging# 日志大小和数量options:max-size: "100m"max-file: "3"# 文件存储类型driver: json-file
在所有节点机器上执行
以下命令:
进入/opt/software/rocketmqcluster目录
cd /opt/software/rocketmqcluster
给data目录赋可读可写可执行权限
chmod -R 777 ./data
chmod -R 777 ./docker-compose.yaml
在后台启动docker-compose服务
docker-compose up -d
显示所有docker-compose管理的容器状态
docker-compose ps
查看日志输出
docker-compose logs
停止并移除容器
docker stop namesrv broker-n2 broker-n1 broker-n0 && docker rm namesrv broker-n2 broker-n1 broker-n0 && rm -rf data/
docker stop namesrv broker-n2 broker-n1 broker-n0 console && docker rm namesrv broker-n2 broker-n1 broker-n0 console && rm -rf data/
防火墙端口需要注意开放:
控制面板
如果需要在单独服务器上部署一个控制面板,观察MQ集群情况,则添加以下docker-compose.yaml配置文件:
version: '3.5'
services:console:restart: alwaysimage: apacherocketmq/rocketmq-dashboardcontainer_name: consoleports:- 19081:8080environment:TZ: "Asia/Shanghai"JAVA_OPTS: "-Drocketmq.namesrv.addr=192.168.80.101:9876;192.168.80.102:9876;192.168.80.103:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
📢文章总结
对本篇文章进行总结:
🔔以上就是今天要讲的内容,阅读结束后,反思和总结所学内容,并尝试应用到现实中,有助于深化理解和应用知识。与朋友或同事分享所读内容,讨论细节并获得反馈,也有助于加深对知识的理解和吸收。
🔔如果您需要转载或者搬运这篇文章的话,非常欢迎您私信我哦~
🚀🎉希望各位读者大大多多支持用心写文章的博主,现在时代变了,🚀🎉 信息爆炸,酒香也怕巷子深🔥,博主真的需要大家的帮助才能在这片海洋中继续发光发热🎨,所以,🏃💨赶紧动动你的小手,点波关注❤️,点波赞👍,点波收藏⭐,甚至点波评论✍️,都是对博主最好的支持和鼓励!
- 💂 博客主页: 我是廖志伟
- 👉开源项目:java_wxid
- 🌥 哔哩哔哩:我是廖志伟
- 🎏个人社区:幕后大佬
- 🔖个人微信号:
SeniorRD
- 🎉微信号二维码:
📥博主目标
- 🍋程序开发这条路不能停,停下来容易被淘汰掉,吃不了自律的苦,就要受平庸的罪,持续的能力才能带来持续的自信。我本是一个很普通的程序员,放在人堆里,除了与生俱来的盛世美颜,就剩180的大高个了,就是我这样的一个人,默默写博文也有好多年了。
- 📺有句老话说的好,牛逼之前都是傻逼式的坚持,希望自己可以通过大量的作品、时间的积累、个人魅力、运气、时机,可以打造属于自己的技术影响力。
- 💥内心起伏不定,我时而激动,时而沉思。我希望自己能成为一个综合性人才,具备技术、业务和管理方面的精湛技能。我想成为产品架构路线的总设计师,团队的指挥者,技术团队的中流砥柱,企业战略和资本规划的实战专家。
- 🎉这个目标的实现需要不懈的努力和持续的成长,但我必须努力追求。因为我知道,只有成为这样的人才,我才能在职业生涯中不断前进并为企业的发展带来真正的价值。在这个不断变化的时代,我们必须随时准备好迎接挑战,不断学习和探索新的领域,才能不断地向前推进。我坚信,只要我不断努力,我一定会达到自己的目标。
🔔有需要对自己进行综合性评估,进行职业方向规划,我可以让技术大牛帮你模拟面试、针对性的指导、传授面试技巧、简历优化、进行技术问题答疑等服务。
可访问:https://java_wxid.gitee.io/tojson/