本文主要是介绍docker-compose单机部署rocketmq集群(双主双从,同步双写),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
1.本文以RocketMQ 5.3.0 版本的镜像为例。
2.首先先更新docker,之前旧版docker,导致rocketmq一直起不来,一直报错。
3.安装docker-compose。
服务器环境(目前只用192.168.25.135后期改ip地址即可)
| 1 | 192.168.25.135 | nameserver、brokerserver | Master1、Slave2 |
| ---- | -------------- | ------------------------ | --------------- |
| 2 | 192.168.25.138 | nameserver、brokerserver | Master2、Slave1 |Host添加信息
vim /etc/hosts配置如下:
# nameserver
192.168.25.135 rocketmq-nameserver1
192.168.25.138 rocketmq-nameserver2
# broker
192.168.25.135 rocketmq-master1
192.168.25.135 rocketmq-slave2
192.168.25.138 rocketmq-master2
192.168.25.138 rocketmq-slave1配置完成后, 重启网卡
systemctl restart network开放端口号
* `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/storemkdir -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/storemkdir -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/storemkdir -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.25.135
#从节点ip(目前是本机ip)
brokerIP2=192.168.25.135
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=10911
#是否能够自动创建topic
autoCreateTopicEnable=true
8.修改/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.25.135
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=11911
#是否能够自动创建topic
autoCreateTopicEnable=true
9.修改/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.171.134
#从节点ip(目前是本机ip)
brokerIP2=192.168.25.135
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=12911
#是否能够自动创建topic
autoCreateTopicEnable=true
10.修改/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.25.135
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=13911
#是否能够自动创建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.0container_name: mqnamesrvports:- 9876:9876environment:JAVA_OPT_EXT: "-Duser.home=/opt -Xms512m -Xmx512m -Xmn150m"command: sh mqnamesrvmqbroker-1-m:image: apache/rocketmq:5.3.0container_name: mqbroker-1-mports:- 10911:10911- 10909:10909- 10912:10912volumes:- /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/storeenvironment:NAMESRV_ADDR: "mqnamesrv:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"command: sh mqbroker -c /home/rocketmq/conf/broker.confdepends_on:- mqnamesrvmqbroker-2-s:image: apache/rocketmq:5.3.0container_name: mqbroker-2-sports:- 11911:11911- 11909:11909- 11912:11912volumes:- /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/storeenvironment:NAMESRV_ADDR: "mqnamesrv:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"command: sh mqbroker -c /home/rocketmq/conf/broker.confdepends_on:- mqnamesrvmqbroker-2-m:image: apache/rocketmq:5.3.0container_name: mqbroker-2-mports:- 12911:12911- 12909:12909- 12912:12912volumes:- /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/storeenvironment:NAMESRV_ADDR: "mqnamesrv:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"command: sh mqbroker -c /home/rocketmq/conf/broker.confdepends_on:- mqnamesrvmqbroker-1-s:image: apache/rocketmq:5.3.0container_name: mqbroker-1-sports:- 13911:13911- 13909:13909- 13912:13912volumes:- /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/storeenvironment:NAMESRV_ADDR: "mqnamesrv:9876"JAVA_OPTS: " -Duser.home=/opt"JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"command: sh mqbroker -c /home/rocketmq/conf/broker.confdepends_on:- mqnamesrvmqconsole:image: styletang/rocketmq-console-ng:1.0.0container_name: mqconsoleports:- 19876:8080environment:JAVA_OPTS: -Drocketmq.namesrv.addr=mqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=falsesdepends_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地址换成自己的。如果是云服务器,则需要把以上的端口都打开。注意路径不要错了。
这篇关于docker-compose单机部署rocketmq集群(双主双从,同步双写)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!