创建挂载目录
mkdir -p /app/rocketmq/logs/nameserver-a
mkdir -p /app/rocketmq/logs/nameserver-b
mkdir -p /app/rocketmq/store/nameserver-a
mkdir -p /app/rocketmq/store/nameserver-b
mkdir -p /app/rocketmq/logs/broker-a
mkdir -p /app/rocketmq/logs/broker-b
mkdir -p /app/rocketmq/store/broker-a
mkdir -p /app/rocketmq/store/broker-b
mkdir -p /app/rocketmq/broker-a/
mkdir -p /app/rocketmq/broker-b/
创建broker.conf
broker.conf是Broker的配置文件,因为此时RocketMQ镜像还没有拉取,所以还没有默认的broker.conf。所以这里直接写好,到时候通过命令替换默认的broker.conf。
因为是双主模式部署,所以会有两个broker.conf,这里暂且命名 broker-a.conf 和 broker-b.conf
- broker-a.conf
vim /app/rocketmq/broker-a/broker-a.conf
brokerClusterName = rocketmq-cluster
brokerName = broker-a
brokerId = 0
#这个很有讲究 如果是正式环境 这里一定要填写内网地址(安全)
#如果是用于测试或者本地这里建议要填外网地址,因为你的本地代码是无法连接到阿里云内网,只能连接外网。
brokerIP1 = 192.168.92.129
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 内网的(阿里云有内网IP和外网IP)
namesrvAddr=172.18.0.5:9876;172.18.0.5:9877
autoCreateTopicEnable=true
#Broker 对外服务的监听端口,
listenPort = 10911
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
这里配置的主要信息有:
1、当前Broker对外暴露的端口号
2、注册到NameServer的地址,看到这里有两个地址,说明NameServer也是集群部署。
3、当前Broker的角色,是主还是从,这里表示是主。
2)broker-b.conf
vim /app/rocketmq/broker-b/broker-b.conf
brokerClusterName = rocketmq-cluster
brokerName = broker-b
brokerId = 0
brokerIP1 = 192.168.92.129
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 内网的(阿里云有内网IP和外网IP)
namesrvAddr=172.18.0.5:9876;172.18.0.5:9877
autoCreateTopicEnable=true
#Broker 对外服务的监听端口,
listenPort = 10909
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
这个上面并无差别,只是当前Brocker对外暴露的端口不一样。
3、编写 docker-compose.yml
我们可以简单把docker-compose.yml理解成一个类似Shell的脚本,这个脚本定义了运行多容器应用程序的信息。
vim /app/docker-compose.yml
version: '3.5'
services:rmqnamesrv-a:image: rocketmqinc/rocketmq:4.3.0container_name: rmqnamesrv-aports:- 9876:9876volumes:- /app/rocketmq/logs/nameserver-a:/opt/logs- /app/rocketmq/store/nameserver-a:/opt/storecommand: sh mqnamesrvnetworks:rmq:aliases:- rmqnamesrv-armqnamesrv-b:image: rocketmqinc/rocketmq:4.3.0container_name: rmqnamesrv-bports:- 9877:9877volumes:- /app/rocketmq/logs/nameserver-b:/opt/logs- /app/rocketmq/store/nameserver-b:/opt/storecommand: sh mqnamesrvnetworks:rmq:aliases:- rmqnamesrv-brmqbroker-a:image: rocketmqinc/rocketmq:4.3.0container_name: rmqbroker-aports:- 10911:10911volumes:- /app/rocketmq/logs/broker-a:/opt/logs- /app/rocketmq/store/broker-a:/opt/store- /app/rocketmq/broker-a/broker-a.conf:/opt/rocketmq-4.3.0/conf/broker.conf environment:TZ: Asia/ShanghaiNAMESRV_ADDR: "rmqnamesrv-a:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"command: sh mqbroker -c /app/rocketmq-4.3.0/conf/broker.conf autoCreateTopicEnable=true &links:- rmqnamesrv-a:rmqnamesrv-a- rmqnamesrv-b:rmqnamesrv-bnetworks:rmq:aliases:- rmqbroker-armqbroker-b:image: rocketmqinc/rocketmq:4.3.0container_name: rmqbroker-bports:- 10909:10909volumes:- /app/rocketmq/logs/broker-b:/opt/logs- /app/rocketmq/store/broker-b:/opt/store- /app/rocketmq/broker-b/broker-b.conf:/opt/rocketmq-4.3.0/conf/broker.conf environment:TZ: Asia/ShanghaiNAMESRV_ADDR: "rmqnamesrv-b:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"command: sh mqbroker -c /opt/rocketmq-4.3.0/conf/broker.conf autoCreateTopicEnable=true &links:- rmqnamesrv-a:rmqnamesrv-a- rmqnamesrv-b:rmqnamesrv-bnetworks:rmq:aliases:- rmqbroker-brmqconsole:image: styletang/rocketmq-console-ngcontainer_name: rmqconsoleports:- 9001:9001environment:JAVA_OPTS: -Drocketmq.namesrv.addr=rmqnamesrv-a:9876;rmqnamesrv-b:9877 -Dcom.rocketmq.sendMessageWithVIPChannel=falsenetworks:rmq:aliases:- rmqconsole
networks:rmq:name: rmqdriver: bridge
从配置文件可以大致看出几点:
1、通过Docker总共拉取了5条镜像记录。rmqnamesrv-a、rmqnamesrv-b、rmqbroker-a、rmqbroker-b、rmqconsole。
2、rmqconsole是一个可视化的工具,可以通过页面来查看RocketMQ相关信息。
3、可以看出对于broker的配置文件broker.conf已经被broker-a/b.conf替换。
关键一步
前面所有的操作,都是为这一步的铺垫,通过docker-compose执行docker-compose.yml配置文件
docker-compose -f docker-compose.yml up -d
查看可视化界面
http://192.168.92.129:9001/