1.本文以RocketMQ 5.3.0 版本的镜像为例。
2.首先先更新docker,之前旧版docker,导致rocketmq一直起不来,一直报错。
3.安装docker-compose。
服务器环境(目前只用192.168.25.133后期改ip地址即可)
| 1 | 192.168.200.133 | nameserver、brokerserver | Master1、Slave2 |
| ---- | -------------- | ------------------------ | --------------- |
| 2 | 192.168.200.134 | nameserver、brokerserver | Master2、Slave1 |
开放端口号
* `nameserver` 默认使用 9876 端口
* `master` 默认使用 10911 端口
* `slave` 默认使用11011 端口
4.拉取镜像
docker pull apache/rocketmq:5.3.0
5.创建消息存储路径
mkdir -p /usr/local/rocketmq/broker-1-m/conf
touch /usr/local/rocketmq/broker-1-m/conf/broker.conf
mkdir -p /usr/local/rocketmq/broker-1-m/logs
mkdir -p /usr/local/rocketmq/broker-1-m/store
mkdir -p /usr/local/rocketmq/broker-1-s/conf
touch /usr/local/rocketmq/broker-1-s/conf/broker.conf
mkdir -p /usr/local/rocketmq/broker-1-s/logs
mkdir -p /usr/local/rocketmq/broker-1-s/store
mkdir -p /usr/local/rocketmq/broker-2-m/conf
touch /usr/local/rocketmq/broker-2-m/conf/broker.conf
mkdir -p /usr/local/rocketmq/broker-2-m/logs
mkdir -p /usr/local/rocketmq/broker-2-m/store
mkdir -p /usr/local/rocketmq/broker-2-s/conf
touch /usr/local/rocketmq/broker-2-s/conf/broker.conf
mkdir -p /usr/local/rocketmq/broker-2-s/logs
mkdir -p /usr/local/rocketmq/broker-2-s/store
6.授权
chmod 777 -R /usr/local/rocketmq
7.修改/usr/local/rocketmq/broker-1-m/conf/broker.conf配置文件
vim /usr/local/rocketmq/broker-1-m/conf/broker.conf
#集群名称
brokerClusterName=rocketmq-cluster
#broker名称
brokerName=broker1
#brokerId master用0 slave用其他
brokerId=0
#清理时机
deleteWhen=4
#文件保留时长 48小时
fileReservedTime=48
#broker角色 -ASYNC_MASTER异步复制 -SYNC_MASTER同步双写 -SLAVE
brokerRole=SYNC_MASTER
#刷盘策略 - ASYNC_FLUSH 异步刷盘 - SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#主机ip
brokerIP1=192.168.200.133
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=10911
#haService中使用 默认值为:listenPort + 1
haListenPort=10912
#主要用于slave同步master listenPort - 2
fastListenPort=10909
#是否能够自动创建topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
8.修改/usr/local/rocketmq/broker-2-s/conf/broker.conf配置文件
vim /usr/local/rocketmq/broker-2-s/conf/broker.conf
#集群名称
brokerClusterName=rocketmq-cluster
#broker名称
brokerName=broker2
#brokerId master用0 slave用其他
brokerId=1
#清理时机
deleteWhen=4
#文件保留时长 48小时
fileReservedTime=48
#broker角色 -ASYNC_MASTER异步复制 -SYNC_MASTER同步双写 -SLAVE
brokerRole=SLAVE
#刷盘策略 - ASYNC_FLUSH 异步刷盘 - SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#主机ip
brokerIP1=192.168.200.133
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=11911
#haService中使用 默认值为:listenPort + 1
haListenPort=11912
#主要用于slave同步master listenPort - 2
fastListenPort=11909
#是否能够自动创建topic
autoCreateTopicEnable=true
9.修改/usr/local/rocketmq/broker-2-m/conf/broker.conf配置文件
vim /usr/local/rocketmq/broker-2-m/conf/broker.conf
#集群名称
brokerClusterName=rocketmq-cluster
#broker名称
brokerName=broker2
#brokerId master用0 slave用其他
brokerId=0
#清理时机
deleteWhen=4
#文件保留时长 48小时
fileReservedTime=48
#broker角色 -ASYNC_MASTER异步复制 -SYNC_MASTER同步双写 -SLAVE
brokerRole=SYNC_MASTER
#刷盘策略 - ASYNC_FLUSH 异步刷盘 - SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#主机ip
brokerIP1=192.168.200.133
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=12911
#haService中使用 默认值为:listenPort + 1
haListenPort=12912
#主要用于slave同步master listenPort - 2
fastListenPort=12909
#是否能够自动创建topic
autoCreateTopicEnable=true
10.修改/usr/local/rocketmq/broker-1-s/conf/broker.conf配置文件
vim /usr/local/rocketmq/broker-1-s/conf/broker.conf
#集群名称
brokerClusterName=rocketmq-cluster
#broker名称
brokerName=broker1
#brokerId master用0 slave用其他
brokerId=1
#清理时机
deleteWhen=4
#文件保留时长 48小时
fileReservedTime=48
#broker角色 -ASYNC_MASTER异步复制 -SYNC_MASTER同步双写 -SLAVE
brokerRole=SLAVE
#刷盘策略 - ASYNC_FLUSH 异步刷盘 - SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#主机ip
brokerIP1=192.168.200.133
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=13911
#haService中使用 默认值为:listenPort + 1
haListenPort=13912
#主要用于slave同步master listenPort - 2
fastListenPort=13909
#是否能够自动创建topic
autoCreateTopicEnable=true
11.新建docker-compose文件
touch /usr/local/rocketmq/docker-compose.yml
vim /usr/local/rocketmq/docker-compose.yml
12.粘贴以下内容到docker-compose.yml
version: "3"
services:
mqnamesrv:
image: apache/rocketmq:5.3.0
container_name: mqnamesrv
ports:
- 9876:9876
environment:
JAVA_OPT_EXT: "-Duser.home=/opt -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
command: sh mqnamesrv
mqbroker-1-m:
image: apache/rocketmq:5.3.0
container_name: mqbroker-1-m
ports:
- 10911:10911
- 10909:10909
- 10912:10912
volumes:
- /usr/local/rocketmq/broker-1-m/conf/broker.conf:/home/rocketmq/conf/broker.conf
- /usr/local/rocketmq/broker-1-m/logs:/home/rocketmq/logs
- /usr/local/rocketmq/broker-1-m/store:/home/rocketmq/store
environment:
NAMESRV_ADDR: "mqnamesrv:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
command: sh mqbroker -c /home/rocketmq/conf/broker.conf
depends_on:
- mqnamesrv
mqbroker-2-s:
image: apache/rocketmq:5.3.0
container_name: mqbroker-2-s
ports:
- 11911:11911
- 11909:11909
- 11912:11912
volumes:
- /usr/local/rocketmq/broker-2-s/conf/broker.conf:/home/rocketmq/conf/broker.conf
- /usr/local/rocketmq/broker-2-s/logs:/home/rocketmq/logs
- /usr/local/rocketmq/broker-2-s/store:/home/rocketmq/store
environment:
NAMESRV_ADDR: "mqnamesrv:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
command: sh mqbroker -c /home/rocketmq/conf/broker.conf
depends_on:
- mqnamesrv
mqbroker-2-m:
image: apache/rocketmq:5.3.0
container_name: mqbroker-2-m
ports:
- 12911:12911
- 12909:12909
- 12912:12912
volumes:
- /usr/local/rocketmq/broker-2-m/conf/broker.conf:/home/rocketmq/conf/broker.conf
- /usr/local/rocketmq/broker-2-m/logs:/home/rocketmq/logs
- /usr/local/rocketmq/broker-2-m/store:/home/rocketmq/store
environment:
NAMESRV_ADDR: "mqnamesrv:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
command: sh mqbroker -c /home/rocketmq/conf/broker.conf
depends_on:
- mqnamesrv
mqbroker-1-s:
image: apache/rocketmq:5.3.0
container_name: mqbroker-1-s
ports:
- 13911:13911
- 13909:13909
- 13912:13912
volumes:
- /usr/local/rocketmq/broker-1-s/conf/broker.conf:/home/rocketmq/conf/broker.conf
- /usr/local/rocketmq/broker-1-s/logs:/home/rocketmq/logs
- /usr/local/rocketmq/broker-1-s/store:/home/rocketmq/store
environment:
NAMESRV_ADDR: "mqnamesrv:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
command: sh mqbroker -c /home/rocketmq/conf/broker.conf
depends_on:
- mqnamesrv
mqconsole:
image: styletang/rocketmq-console-ng:1.0.0
container_name: mqconsole
ports:
- 19876:8080
environment:
JAVA_OPTS: -Drocketmq.namesrv.addr=mqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=falses
depends_on:
- mqnamesrv
13.在docker-compose.yml文件所在目录运行docker-compose.yml
docker-compose up -d
14.查看容器是否启动成功
docker ps
docker logs -f (容器id)
15.显示成功,就是成功了。
16.打开ip:19876
16.注意,记得把以上ip地址换成自己的。如果是云服务器,则需要把以上的端口都打开。注意路径不要错了。
不同主机可参考: