1、 创建目录
mkdir -p /docker/rocketmq/logs/nameserver-a
mkdir -p /docker/rocketmq/logs/nameserver-b
mkdir -p /docker/rocketmq/logs/broker-a
mkdir -p /docker/rocketmq/logs/broker-b
mkdir -p /docker/rocketmq/store/broker-a
mkdir -p /docker/rocketmq/store/broker-b
mkdir -p /docker/rocketmq/broker-a/
mkdir -p /docker/rocketmq/broker-b/
mkdir -p /docker/rocketmq/console-ng/data
2、创建rocketmq的配置文件
2.1 创建broker-a.conf(主节点)
vim /docker/rocketmq/broker-a/broker-a.conf
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = rocketmq-cluster
#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 = ASYNC_MASTER
#刷盘策略,取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要;
flushDiskType = ASYNC_FLUSH
# 设置broker节点所在服务器的ip地址(**这个非常重要,主从模式下,从节点会根据主节点的brokerIP2来同步数据,如果不配置
,主从无法同步,brokerIP1设置为自己外网能访问的ip,服务器双网卡情况下必须配置,比如阿里云这种,主节点需要配置ip1和
ip2,从节点只需要配置ip1即可)
brokerIP1 = rmqbroker-a
brokerIP2 = rmqbroker-a-s
#nameServer地址,分号分割
namesrvAddr=rmqnamesrv-a:9876;rmqnamesrv-b:9876
#Broker 对外服务的监听端口,
listenPort = 10911
slaveReadEnable = true
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
#支持sql92过滤消息
enablePropertyFilter=true
2.2 创建broker-a-s.conf(从节点)
vim /docker/rocketmq/broker-b/broker-a-s.conf
root@DESKTOP-KIQB7GS:/home/jxren# ^C
root@DESKTOP-KIQB7GS:/home/jxren# cat /docker/rocketmq/broker-a/broker-a-s.conf
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = rocketmq-cluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-b
#0表示Master,大于0表示不同的slave
brokerId = 1
#表示几点做消息删除动作,默认是凌晨4点
deleteWhen = 04
#在磁盘上保留消息的时长,单位是小时
fileReservedTime = 48
#有三个值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步和异步表示Master和Slave之间同步数据的机制;
brokerRole = SLAVE
#刷盘策略,取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要;
flushDiskType = ASYNC_FLUSH
# 设置broker节点所在服务器的ip地址(**这个非常重要,主从模式下,从节点会根据主节点的brokerIP2来同步数据,如果不配置
,主从无法同步,brokerIP1设置为自己外网能访问的ip,服务器双网卡情况下必须配置,比如阿里云这种,主节点需要配置ip1和
ip2,从节点只需要配置ip1即可)
brokerIP1 = rmqbroker-a-s
#nameServer地址,分号分割
namesrvAddr=rmqnamesrv-a:9876;rmqnamesrv-b:9876
#Broker 对外服务的监听端口,
listenPort = 10911
slaveReadEnable = true
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
#支持sql92过滤消息
enablePropertyFilter=true
3.构建docker-compose-rocketmq.yml文件
version: '3.5'
services:rmqnamesrv-a:image: apache/rocketmq:4.9.4container_name: rmqnamesrv-aports:- 9876:9876volumes:- /docker/rocketmq/logs/nameserver-a:/home/rocketmq/logs- /docker/rocketmq/store/nameserver-a:/home/rocketmq/storecommand: sh mqnamesrvnetworks:rmq:aliases:- rmqnamesrv-armqnamesrv-b:image: apache/rocketmq:4.9.4container_name: rmqnamesrv-bports:- 9877:9876volumes:- /docker/rocketmq/logs/nameserver-b:/home/rocketmq/logs- /docker/rocketmq/store/nameserver-b:/home/rocketmq/storecommand: sh mqnamesrvnetworks:rmq:aliases:- rmqnamesrv-brmqbroker-a:image: apache/rocketmq:4.9.4container_name: rmqbroker-aports:- 10911:10911volumes:- /docker/rocketmq/logs/broker-a/logs:/home/rocketmq/logs- /docker/rocketmq/store/broker-a/store:/home/rocketmq/store- /docker/rocketmq/broker-a/broker-a.conf:/opt/rocketmq/conf/broker-a.confenvironment:TZ: Asia/ShanghaiNAMESRV_ADDR: "rmqnamesrv-a:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"command: sh mqbroker -c /opt/rocketmq/conf/broker-a.conflinks:- rmqnamesrv-a:rmqnamesrv-a- rmqnamesrv-b:rmqnamesrv-bnetworks:rmq:aliases:- rmqbroker-armqbroker-a-s:image: apache/rocketmq:4.9.4container_name: rmqbroker-a-sports:- 10912:10911volumes:- /docker/rocketmq/logs/broker-a-s:/home/rocketmq/logs- /docker/rocketmq/store/broker-a-s:/home/rocketmq/store- /docker/rocketmq/broker-a/broker-a-s.conf:/home/docker/rocketmq/conf/broker-b.confenvironment:TZ: Asia/ShanghaiNAMESRV_ADDR: "rmqnamesrv-a:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"command: sh mqbroker -c /home/docker/rocketmq/conf/broker-b.conflinks:- rmqnamesrv-a:rmqnamesrv-a- rmqnamesrv-b:rmqnamesrv-bnetworks:rmq:aliases:- rmqbroker-a-srmqconsole:image: apacherocketmq/rocketmq-dashboardcontainer_name: rmqconsoleports:- 8087:8080environment:JAVA_OPTS: -Drocketmq.namesrv.addr=rmqnamesrv-a:9876;rmqnamesrv-b:9877 -Dcom.rocketmq.sendMessageWithVIPChannel=falsenetworks:rmq:aliases:- rmqconsole# 自定义网络
networks:rmq:name: rmqdriver: bridge
4、拉到服务器上运行此文件
docker-compose -f docker-compose-rocketmq.yml up -d
5、查看http://127.0.0.1:8087/
显示此界面,表明运行成功