一、部署环境
两台服务器,每台一个nameserver构成集群,broker集群双主双从。
主机 容器名称 IP 与宿主机的端口映射
- ODL控制器会同过vip通道10909去连接mq。
- 主从通过10912端口同步
- 这两个地址是通过-2 +1 在配置文件端口10911基础上计算得出
两个宿主机上都有docker,并且创建了网桥docker-br0。
docker network create --subnet=172.16.1.0/24 docker-br0
docker network create --subnet=172.16.2.0/24 docker-br0
二、部署步骤
(一)、安装docker compose
参考官方方法:https://docs.docker.com/compose/install/linux/
DOCKER_CONFIG=${DOCKER_CONFIG:-$HOME/.docker}
mkdir -p $DOCKER_CONFIG/cli-plugins
curl -SL https://github.com/docker/compose/releases/download/v2.17.2/docker-compose-linux-x86_64 -o $DOCKER_CONFIG/cli-plugins/docker-compose
chmod +x $DOCKER_CONFIG/cli-plugins/docker-compose
docker compose version
拉取mq docker镜像
docker pull apache/rocketmq:4.3.1
docker pull apacherocketmq/rocketmq-dashboard
(二)、172.16.101.14 主机docker compose 部署 nameserver和broker 配置文件
- 现在broker master配置文件都是开启自动创建topic的。如果
topic消息间隔时间 > nameserver路由更新时间30s / (单个broker topic队列数 + 1)
,只会使用一个broker。 - 在生产环境下不开启自动创建topic。需要手动给每个broker创建topic。手动创建topic后,消息会轮询所有broker的队列,选择一个发送。
1.创建路径docker-compose/rocketmq/
,存放主从broker的配置文件:broker-a.conf
broker-b-s.conf
。
broker-a.conf
brokerClusterName = rocketmq-cluster
brokerName = broker-a
# 0表示broker master 非0表示 broker slaver
brokerId = 0
# brokerIP1 当前broker监听的IP
brokerIP1 = 172.16.101.14
# brokerIP2 存在broker主从时,在broker主节点上配置了brokerIP2的话,broker从节点会连接主节点配置的brokerIP2来同步
brokerIP2 = 172.16.101.14
deleteWhen = 04
fileReservedTime = 48
namesrvAddr = rmqnamesrv-a:9876;172.16.101.13:9876
# 是否能够自动创建topic
autoCreateTopicEnable = true
#Broker 对外服务的监听端口, 默认10911
# listenPort = 10911
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole = ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType = ASYNC_FLUSH
broker-b-s.conf
brokerClusterName = rocketmq-cluster
brokerName = broker-b
brokerId = 1
brokerIP1 = 172.16.101.14
deleteWhen = 04
fileReservedTime = 48
namesrvAddr = rmqnamesrv-a:9876;172.16.101.13:9876
listenPort = 11911
brokerRole = SLAVE
flushDiskType = ASYNC_FLUSH
- docker-compose/下创建文件docker-compose.yml
docker-compose.yml
version: '3.5'
services:
rmqnamesrv-a:
image: apache/rocketmq:4.3.1
restart: always
container_name: rmqnamesrv-a
ports:
- 9876:9876
volumes:
- ./rocketmq/logs/nameserver-a:/opt/logs/rocketmqlogs
- ./rocketmq/store/nameserver-a:/opt/store
environment:
JAVA_OPT_EXT: "-Duser.home=/opt -Xms512m -Xmx512m -Xmn150m"
command: sh mqnamesrv
networks:
- docker-br0
rmqbroker-a:
image: apache/rocketmq:4.3.1
container_name: rmqbroker-a
ports:
- 10911:10911
- 10909:10909
- 10912:10912
volumes:
- ./rocketmq/logs/broker-a:/home/rocketmq/logs
- ./rocketmq/store/broker-a:/home/rocketmq/store
- ./rocketmq/broker-a.conf:/home/rocketmq/rocketmq-4.3.1/conf/broker.conf
environment:
TZ: Asia/Shanghai
NAMESRV_ADDR: "rmqnamesrv-a:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: sh mqbroker -c /home/rocketmq/rocketmq-4.3.1/conf/broker.conf autoCreateTopicEnable=true &
links:
- rmqnamesrv-a:rmqnamesrv-a
networks:
- docker-br0
rmqbroker-b-s:
image: apache/rocketmq:4.3.1
container_name: rmqbroker-b-s
ports:
- 11911:11911
- 11909:11909
- 11912:11912
volumes:
- ./rocketmq/logs/broker-b-s:/home/rocketmq/logs
- ./rocketmq/store/broker-b-s:/home/rocketmq/store
- ./rocketmq/broker-b-s.conf:/home/rocketmq/rocketmq-4.3.1/conf/broker.conf
environment:
TZ: Asia/Shanghai
NAMESRV_ADDR: "rmqnamesrv-a:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: sh mqbroker -c /home/rocketmq/rocketmq-4.3.1/conf/broker.conf autoCreateTopicEnable=true &
links:
- rmqnamesrv-a:rmqnamesrv-a
networks:
- docker-br0
networks:
docker-br0:
external: true
(三)、172.16.101.13 主机docker compose 部署 nameserver和broker 配置文件
1.创建路径docker-compose/rocketmq/
,存放主从broker的配置文件:broker-b.conf
broker-a-s.conf
。
broker-b.conf
brokerClusterName = rocketmq-cluster
brokerName = broker-b
brokerId = 0
brokerIP1 = 172.16.101.13
brokerIP2 = 172.16.101.13
deleteWhen = 04
fileReservedTime = 48
namesrvAddr = rmqnamesrv-b:9876;172.16.101.14:9876
autoCreateTopicEnable = true
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
broker-a-s.conf
brokerClusterName = rocketmq-cluster
brokerName = broker-a
brokerId = 1
brokerIP1 = 172.16.101.13
deleteWhen = 04
fileReservedTime = 48
namesrvAddr = rmqnamesrv-b:9876;172.16.101.14:9876
listenPort = 11911
brokerRole = SLAVE
flushDiskType = ASYNC_FLUSH
- docker-compose/下创建文件docker-compose.yml
docker-compose.yml
version: '3.5'
services:
rmqnamesrv-b:
image: apache/rocketmq:4.3.1
restart: always
container_name: rmqnamesrv-b
ports:
- 9876:9876
volumes:
- ./rocketmq/logs/nameserver-b:/opt/logs/rocketmqlogs
- ./rocketmq/store/nameserver-b:/opt/store
environment:
JAVA_OPT_EXT: "-Duser.home=/opt -Xms512m -Xmx512m -Xmn150m"
command: sh mqnamesrv
networks:
- docker-br0
rmqbroker-b:
image: apache/rocketmq:4.3.1
container_name: rmqbroker-b
ports:
- 10911:10911
- 10909:10909
- 10912:10912
volumes:
- ./rocketmq/logs/broker-b:/home/rocketmq/logs
- ./rocketmq/store/broker-b:/home/rocketmq/store
- ./rocketmq/broker-b.conf:/home/rocketmq/rocketmq-4.3.1/conf/broker.conf
environment:
TZ: Asia/Shanghai
NAMESRV_ADDR: "rmqnamesrv-b:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: sh mqbroker -c /home/rocketmq/rocketmq-4.3.1/conf/broker.conf autoCreateTopicEnable=true &
links:
- rmqnamesrv-b:rmqnamesrv-b
networks:
- docker-br0
rmqbroker-a-s:
image: apache/rocketmq:4.3.1
container_name: rmqbroker-a-s
ports:
- 11911:11911
- 11909:11909
- 11912:11912
volumes:
- ./rocketmq/logs/broker-a-s:/home/rocketmq/logs
- ./rocketmq/store/broker-a-s:/home/rocketmq/store
- ./rocketmq/broker-a-s.conf:/home/rocketmq/rocketmq-4.3.1/conf/broker.conf
environment:
TZ: Asia/Shanghai
NAMESRV_ADDR: "rmqnamesrv-b:9876"
JAVA_OPTS: " -Duser.home=/opt"
JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
command: sh mqbroker -c /home/rocketmq/rocketmq-4.3.1/conf/broker.conf autoCreateTopicEnable=true &
links:
- rmqnamesrv-b:rmqnamesrv-b
networks:
- docker-br0
networks:
docker-br0:
external: true
(四)、部署
- 执行
docker compose up -d
docker compose down
-
此时已经在rocket下创建了logs和store文件夹,设置权限
chmod -R 777 logs/ store/
-
部署
docker compose up -d
-
docker部署dashboard
docker run -d -it --net docker-br0 --ip 172.16.1.18 --name dashboard -p 8080:8080 -e "JAVA_OPTS=-Drocketmq.namesrv.addr=172.16.101.13:9876;172.16.101.14:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" apacherocketmq/rocketmq-dashboard:latest /bin/bash
启动后进入宿主机ip:8080页面文章来源:https://www.toymoban.com/news/detail-490252.html
查看容器内网卡ip:hostname -i
文章来源地址https://www.toymoban.com/news/detail-490252.html
到了这里,关于RocketMQ集群部署的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!