1、下载 RocketMQ 镜像
docker pull apache/rocketmq:5.1.0
2、创建容器共享网络 rocketmq
docker network create rocketmq
3、部署 NameServer
# 创建目录
mkdir -p /data/rocketmq/nameserver/{bin,logs}
# 授权文件
chmod 777 -R /data/rocketmq/nameserver/*
# 创建容器
docker run -d \
--privileged=true --name rmqnamesrv \
apache/rocketmq:5.1.0 sh mqnamesrv
# 拷贝启动脚本
docker cp rmqnamesrv:/home/rocketmq/rocketmq-5.1.0/bin/runserver.sh /data/rocketmq/nameserver/bin/
# 删除容器 NameServer
docker rm -f rmqnamesrv
4、启动容器
# 启动容器 NameServer
docker run -d --network rocketmq \
--privileged=true --restart=always \
--name rmqnamesrv -p 9876:9876 \
-v /data/rocketmq/nameserver/logs:/home/rocketmq/logs \
-v /data/rocketmq/nameserver/bin/runserver.sh:/home/rocketmq/rocketmq-5.1.0/bin/runserver.sh \
apache/rocketmq:5.1.0 sh mqnamesrv
5、 查看启动日志
docker logs -f rmqnamesrv
6、部署 Broker + Proxy
创建挂载文件夹并授权
mkdir -p /data/rocketmq/broker/{store,logs,conf,bin}
chmod 777 -R /data/rocketmq/broker/*
7、创建**broker.cnf**
文件
vi /data/rocketmq/broker/conf/broker.conf
# nameServer 地址多个用;隔开 默认值null # 下面是没有注释的版本, 记得修改"namesrvAddr", "brokerIP1"的地址 |
8、 拷贝启动脚本
# 启动 Broker 容器
docker run -d \
--name rmqbroker --privileged=true \
apache/rocketmq:5.1.0 sh mqbroker
# 拷贝脚本文件
docker cp rmqbroker:/home/rocketmq/rocketmq-5.1.0/bin/runbroker.sh /data/rocketmq/broker/bin
9、 启动容器 Broker
# 删除容器 Broker
docker rm -f rmqbroker
# 启动容器 Broker
docker run -d --network rocketmq \
--restart=always --name rmqbroker --privileged=true \
-p 10911:10911 -p 10909:10909 \
-v /data/rocketmq/broker/logs:/root/logs \
-v /data/rocketmq/broker/store:/root/store \
-v /data/rocketmq/broker/conf/broker.conf:/home/rocketmq/broker.conf \
-v /data/rocketmq/broker/bin/runbroker.sh:/home/rocketmq/rocketmq-5.1.0/bin/runbroker.sh \
-e "NAMESRV_ADDR=rmqnamesrv:9876" \
apache/rocketmq:5.1.0 sh mqbroker --enable-proxy -c /home/rocketmq/broker.conf
10、查看启动日志
docker logs -f rmqbroker
11、部署RocketMQ控制台
下载rocketmq-console镜像
docker pull styletang/rocketmq-console-ng
12、构建RocketMQ-Console容器并启动
docker run -d \
--restart=always --name rmq-dashboard \
-p 8080:8080 --network rocketmq \
-e "JAVA_OPTS=-Xmx256M -Xms256M -Xmn128M -Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
styletang/rocketmq-console-ng