欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Docker搭建RocketMQ双主双从集群

程序员文章站 2022-07-14 23:44:17
...

使用Docker安装RocketMQ

  1. 拉取镜像
docker pull foxiswho/rocketmq:server-4.3.2
docker pull foxiswho/rocketmq:broker-4.3.2

2.创建nameserver容器

docker create -p 9876:9876 --name rmqserver \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-e "JAVA_OPTS=-Duser.home=/opt" \
-v /data/rmq/rmqserver/logs:/opt/logs \
-v /data/rmq/rmqserver/store:/opt/store \
foxiswho/rocketmq:server-4.3.2

3.创建broker容器

docker create -p 10911:10911 -p 10909:10909 --name rmqbroker \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /data/rmq/rmqbroker/conf/broker.conf:/etc/rocketmq/broker.conf \
-v /data/rmq/rmqbroker/logs:/opt/logs \
-v /data/rmq/rmqbroker/store:/opt/store \
foxiswho/rocketmq:broker-4.3.2

4.配置broker文件

创建配置文件
mkdir -p /data/rmq/rmqbroker/conf
vi broker.conf

#增加
brokerIP1=192.168.56.129
namesrvAddr=192.168.56.129:9876
brokerName=my_broker

4.启动容器

docker start rmqserver rmqbroker

5.停止删除容器

docker stop rmqbroker rmqserver 
docker rm rmqbroker rmqserver
  1. 安装控制台
docker pull styletang/rocketmq-console-ng  
docker run -e "JAVA_OPTS=-Drocketmq.config.namesrvAddr={docker宿主机ip}:9876 -Drocketmq.config.isVIPChannel=false" -p 8080:8080 -t styletang/rocketmq-console-ng

在浏览器中输入:http://{docker宿主机ip}:8080/ 访问

使用Docker搭建RocketMQ集群

创建2个nameserver
  • nameserver1
docker create -p 9876:9876 --name rmqserver01 \
 -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
 -e "JAVA_OPTS=-Duser.home=/opt" \
 -v /data/rmq/rmqserver01/logs:/opt/logs \
 -v /data/rmq/rmqserver01/store:/opt/store \
 foxiswho/rocketmq:server-4.3.2

  • nameserver2
docker create -p 9877:9876 --name rmqserver02 \ 
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \ 
-e "JAVA_OPTS=-Duser.home=/opt" \ 
-v /data/rmq/rmqserver02/logs:/opt/logs \ 
-v /data/rmq/rmqserver02/store:/opt/store \
foxiswho/rocketmq:server-4.3.2
创建2个master broker
  • master broker01
docker create --net host --name rmqbroker01 \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /data/rmq/rmqbroker01/conf/broker.conf:/etc/rocketmq/broker.conf \
-v /data/rmq/rmqbroker01/logs:/opt/logs \
-v /data/rmq/rmqbroker01/store:/opt/store \
foxiswho/rocketmq:broker-4.3.2

  • master broker01 配置
#创建配置文件
mkdir -p /data/rmq/rmqbroker01/conf
vi /data/rmq/rmqbroker01/conf/broker.conf

namesrvAddr=192.168.56.129:9876;192.168.56.129:9877 
brokerClusterName=myCluster 
brokerName=broker01 
brokerId=0 
deleteWhen=04 
fileReservedTime=48 
brokerRole=SYNC_MASTER 
flushDiskType=ASYNC_FLUSH 
brokerIP1=192.168.56.129
brokerIp2=192.168.56.129
listenPort=10911

  • master broker02
docker create --net host --name rmqbroker02 \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /data/rmq/rmqbroker02/conf/broker.conf:/etc/rocketmq/broker.conf \
-v /data/rmq/rmqbroker02/logs:/opt/logs \
-v /data/rmq/rmqbroker02/store:/opt/store \
foxiswho/rocketmq:broker-4.3.2

  • master broker02 配置
#创建配置文件
mkdir -p /data/rmq/rmqbroker02/conf
vi /data/rmq/rmqbroker02/conf/broker.conf

namesrvAddr=192.168.56.129:9876;192.168.56.129:9877
brokerClusterName=myCluster
brokerName=broker02 
brokerId=0 
deleteWhen=04 
fileReservedTime=48 
brokerRole=SYNC_MASTER 
flushDiskType=ASYNC_FLUSH 
brokerIP1=192.168.56.129 
brokerIp2=192.168.56.129
listenPort=10811

创建2个slave broker
  • slave broker01
docker create --net host --name rmqbroker03 \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /data/rmq/rmqbroker03/conf/broker.conf:/etc/rocketmq/broker.conf \
-v /data/rmq/rmqbroker03/logs:/opt/logs \
-v /data/rmq/rmqbroker03/store:/opt/store \
foxiswho/rocketmq:broker-4.3.2

  • slave broker01 配置
#创建配置文件
mkdir -p /data/rmq/rmqbroker03/conf
vi /data/rmq/rmqbroker03/conf/broker.conf

namesrvAddr=192.168.56.129:9876;192.168.56.129:9877
brokerClusterName=myCluster
brokerName=broker01
brokerId=1
deleteWhen=04 
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.56.129
listenPort=10711

  • slave broker02
docker create --net host --name rmqbroker04 \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /data/rmq/rmqbroker04/conf/broker.conf:/etc/rocketmq/broker.conf \
-v /data/rmq/rmqbroker04/logs:/opt/logs \
-v /data/rmq/rmqbroker04/store:/opt/store \
foxiswho/rocketmq:broker-4.3.2

  • slave broker02 配置
#创建配置文件
mkdir -p /data/rmq/rmqbroker04/conf
vi /data/rmq/rmqbroker04/conf/broker.conf

namesrvAddr=192.168.56.129:9876;192.168.56.129:9877
brokerClusterName=myCluster
brokerName=broker02
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
brokerIP1=192.168.56.129
listenPort=10611

启动容器

docker start rmqserver01 rmqserver02 
docker start rmqbroker01 rmqbroker02 rmqbroker03 rmqbroker04

效果图

Docker搭建RocketMQ双主双从集群

相关标签: MQ docker 2020