【Rocketmq】通过 docker 快速搭建 rocketmq 集群环境

【Rocketmq】通过 docker 快速搭建 rocketmq 集群环境

一.单机版

1.Namesrv服务器

a.获取镜像
docker pull rocketmqinc/rocketmq:4.4.0
mkdir -p /opt/rmq
b.启动容器
docker run --name rmqnamesrv  -d \
-p 9876:9876 \
--privileged=true \
--restart=always \
-m 1g \
-v /opt/rmq/data/namesrv/logs:/root/logs \
-v /opt/rmq/data/namesrv/store:/root/store \
-e "MAX_POSSIBLE_HEAP=100000000" \
rocketmqinc/rocketmq:4.4.0 sh mqnamesrv

注意:/opt是自己创建的文件夹

2.broker 服务器

a.创建 vim配置文件
mkdir /opt/rmq/config
vim /opt/rmq/config/broker.conf
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = {
     本地外网 IP}
b.启动容器
docker run --name rmqbroker -d \
-p 10909:10909 \
-p 10911:10911 \
--privileged=true \
--restart=always \
-m 1g \
-v  /opt/rmq/data/broker/logs:/root/logs \
-v  /opt/rmq/rocketmq/data/broker/store:/root/store \
-v  /opt/rmq/config/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf \
--link rmqnamesrv:namesrv \
-e "NAMESRV_ADDR=namesrv:9876" \
-e "MAX_POSSIBLE_HEAP=200000000" \
rocketmqinc/rocketmq:4.4.0 sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf

注意:broker.conf 的文件中的 brokerIP1 是你的 broker 注册到 Namesrv 中的 ip。如果不指定他会默认取容器中的内网 IP。除非你的应用也同时部署在网络相通的容器中,本地或容器外就无法连接 broker 服务了,进而导致类似 RemotingTooMuchRequestException 等各种异常

3.rocketmq 控制台

a.获取镜像
docker pull pangliang/rocketmq-console-ng
b.启动容器
docker run --name rmqconsole -p 10084:8080 -d \
--privileged=true \
--restart=always \
-m 512m \
-e "JAVA_OPTS=-Drocketmq.namesrv.addr={本地外网 IP}:9876 \
-Dcom.rocketmq.sendMessageWithVIPChannel=false \
-Dserver.contextPath=/rmqconsole" \
pangliang/rocketmq-console-ng

注意:server.contextPath 是项目访问路径,需要在端口后面添加,我这里是为了nginx跳转

二、集群搭建(分别在两台主机安装)

1.Namesrv服务器

#分别在两台主机上运行
docker run --name rmqnamesrv  -d \
-p 9876:9876 \
--privileged=true \
--restart=always \
-m 1g \
-v /opt/rmq/data/namesrv/logs:/root/logs \
-v /opt/rmq/data/namesrv/store:/root/store \
-e "MAX_POSSIBLE_HEAP=100000000" \
rocketmqinc/rocketmq:4.4.0 sh mqnamesrv

2.broker 服务器

a.创建配置文件

#两台主机上运行
mkdir /opt/rmq/config
vim /opt/rmq/config/broker.conf
#213主机
brokerClusterName = MscmCluster
brokerName = broker-203
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1=172.16.46.213
brokerIp2=172.16.46.214

#214主机
brokerClusterName = MscmCluster
brokerName = broker-204
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1=172.16.46.213
brokerIp2=172.16.46.214
docker run --name rmqbroker -d \
-p 10909:10909 \
-p 10911:10911 \
--privileged=true \
--restart=always \
-m 1g \
-v  /opt/rmq/data/broker/logs:/root/logs \
-v  /opt/rmq/rocketmq/data/broker/store:/root/store \
-v  /opt/rmq/config/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf \
--link rmqnamesrv:namesrv \
-e "NAMESRV_ADDR=172.16.46.213:9876;172.16.46.214:9876" \
-e "MAX_POSSIBLE_HEAP=200000000" \
rocketmqinc/rocketmq:4.4.0 sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf

你可能感兴趣的:(docker,rockemq,docker)