docker 19+
# 前置环境推荐
Docker 19+
# 下载内容
docker pull apache/rocketmq:4.7.1
# 创建namesrv数据存储路径
mkdir -p /home/jamel/docker/software/rocketmq/data/namesrv/logs
mkdir -p /home/jamel/docker/software/rocketmq/data/namesrv/store
# 创建broker存储路径
mkdir -p /home/jamel/docker/software/rocketmq/broker/broker-a
第一步:启动 namesrv
docker run -d \
--restart=always \
--name rocketmq-namesrv-4.7.1 \
-p 9876:9876 \
-m 1024m \
-v /home/jamel/docker/software/rocketmq/data/namesrv/logs:/root/logs \
-v /home/jamel/docker/software/rocketmq/data/namesrv/store:/root/store \
apache/rocketmq:4.7.1 sh mqnamesrv
第二步:生成broker-a服务的配置
# 通过docker ps 找到刚启动成功的rocketmq-namesrv-4.7.1 容器id
# 复制容器内mq配置生成 broker配置
docker cp rocketmq:4.7.1:/home/rocketmq/rocketmq-4.7.1/conf /home/jamel/docker/software/rocketmq/broker/broker-a/
第三步:调整broker-a的配置文件
vim /home/jamel/docker/software/rocketmq/broker/broker-a/conf/broker.conf (下面只需要调整 brokerIP1 & namesrvAddr)
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = DefaultCluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-a
#0表示Master,大于0表示不同的slave
brokerId = 0
#表示几点做消息删除动作,默认是凌晨4点
deleteWhen = 04
#在磁盘上保留消息的时长,单位是小时
fileReservedTime = 48
#有三个值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步和异步表示Master和Slave之间同步数据的机制;
brokerRole = SYNC_MASTER
#刷盘策略,取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要;
flushDiskType = SYNC_FLUSH
# 设置broker节点所在服务器的ip地址(**这个非常重要,主从模式下,从节点会根据主节点的brokerIP2来同步数据,如果不配置,主从无法同步,brokerIP1设置为自己外网能访问的ip,服务器双网卡情况下必须配置,比如阿里云这种,主节点需要配置ip1和ip2,从节点只需要配置ip1即可)
brokerIP1 = 192.168.110.x
#nameServer地址,分号分割
namesrvAddr=192.168.110.x:9876
#Broker 对外服务的监听端口,
listenPort = 10911
#是否允许Broker自动创建Topic
autoCreateTopicEnable = true
#是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup = true
#linux开启epoll
useEpollNativeSelector = true
#数据存放的根目录
#storePathRootDir = /root/store/path
#commit log保存目录
#storePathCommitLog = /root/store/path/commitlog
#消费队列存储路径存储路径
#storePathConsumerQueue = /root/store/path/consumequeue
slaveReadEnable = true
第四步:启动broker-a
docker run -d \
--name rocketmq-broker-a \
--restart=always \
-p 10909:10909 \
-p 10911:10911 \
-m 2048m \
-v /home/jamel/docker/software/rocketmq/broker/broker-a/logs:/root/logs \
-v /home/jamel/docker/software/rocketmq/broker/broker-a/store:/root/store \
-v /home/jamel/docker/software/rocketmq/broker/broker-a/conf:/home/rocketmq/rocketmq-4.7.1/conf \
-e "JAVA_OPT_EXT=-server -Xms1g -Xmx1g -Xmn512m" apache/rocketmq:4.7.1 sh mqbroker -c /home/rocketmq/rocketmq-4.7.1/conf/broker.conf
第一步: 启动broker-a,启动后确认启动日志是否出现成功信息 docker logs --tail=100 -f rocketmq-broker-a
docker run -d \
--name rocketmq-broker-a \
--restart=always \
-p 10909:10909 \
-p 10911:10911 \
-m 2048m \
-v /home/jamel/docker/software/rocketmq/broker/broker-a/logs:/root/logs \
-v /home/jamel/docker/software/rocketmq/broker/broker-a/store:/root/store \
-v /home/jamel/docker/software/rocketmq/broker/broker-a/conf:/home/rocketmq/rocketmq-4.7.1/conf \
-e "JAVA_OPT_EXT=-server -Xms1g -Xmx1g -Xmn512m" apache/rocketmq:4.7.1 sh mqbroker -c /home/rocketmq/rocketmq-4.7.1/conf/broker.conf
第二步:启动rocketmq控制台,启动后确认启动日志是否出现成功信息 docker logs --tail=100 -f rmqadmin
docker run -d \
--restart=always \
--name rmqadmin \
-m 2048m \
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=192.168.110.x:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
-p 5001:8080 \
pangliang/rocketmq-console-ng
确认部署结果:http://192.168.110.x:5001/
访问管理页面
http://192.168.110.x:5001/
1.如果是阿里云环境下部署的,请去控制台开放 9876 和 10911 端口
2.物理服务器报错可以尝试开放端口:9876、10911
systemctl start firewalld
firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --zone=public --add-port=10911/tcp --permanent
firewall-cmd --reload
https://blog.csdn.net/apple_csdn/article/details/125277508