02_单机docker搭建rocketmq集群

1. 要求

在一台机器上使用docker搭建rocketmq集群(2m2s)

2. 创建挂载目录

mkdir -p /data/rocketmq/{logs-nameserver-m,logs-nameserver-s,logs-a,logs-a-s,logs-b,logs-b-s,conf,store-a,store-b,store-a-s,store-b-s}

chmod -R 777 /data/rocketmq

3. 创建配置文件

在/data/rocketmq/conf目录下创建broker配置文件 并赋777权限(chmod -R 777 文件名)

  1. broker-a.conf
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#所属集群名字,同一个集群名字相同
brokerClusterName=DefaultCluster
#broker名字
brokerName=broker-a
#0表示master >0 表示slave
brokerId=0
#删除文件的时间点,凌晨4点
deleteWhen=04
#文件保留时间 默认是48小时
fileReservedTime=48
#异步复制Master
brokerRole=ASYNC_MASTER
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘 
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口端口号对应docker启动时候的端口号
listenPort=10911
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.56.10:9876;192.168.56.10:9877
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#设置BrokerIP
brokerIP1=192.168.56.10
# 限制的消息⼤⼩
maxMessageSize=65536
# commitLog每个⽂件的⼤⼩默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个⽂件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
  1. broker-b.conf
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#所属集群名字,同一个集群名字相同
brokerClusterName=DefaultCluster
#broker名字
brokerName=broker-b
#0表示master >0 表示slave
brokerId=0
#删除文件的时间点,凌晨4点
deleteWhen=04
#文件保留时间 默认是48小时
fileReservedTime=48
#异步复制Master
brokerRole=ASYNC_MASTER
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘 
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口端口号对应docker启动时候的端口号
listenPort=11912
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.56.10:9876;192.168.56.10:9877
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#设置BrokerIP
brokerIP1=192.168.56.10
# 限制的消息⼤⼩
maxMessageSize=65536
# commitLog每个⽂件的⼤⼩默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个⽂件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
  1. broker-a-s.conf
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#所属集群名字,同一个集群名字相同
brokerClusterName=DefaultCluster
#broker名字
brokerName=broker-a
#0表示master >0 表示slave
brokerId=1
#删除文件的时间点,凌晨4点
deleteWhen=04
#文件保留时间 默认是48小时
fileReservedTime=48
#Broker 的角色,ASYNC_MASTER=异步复制Master,SYNC_MASTER=同步双写Master,SLAVE=slave节点
brokerRole=SLAVE
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘 
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口端口号对应docker启动时候的端口号
listenPort=11013
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.56.10:9876;192.168.56.10:9877
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#设置BrokerIP
brokerIP1=192.168.56.10
# 限制的消息⼤⼩
maxMessageSize=65536
# commitLog每个⽂件的⼤⼩默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个⽂件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
  1. broker-b-s.conf
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

#所属集群名字,同一个集群名字相同
brokerClusterName=DefaultCluster
#broker名字
brokerName=broker-b
#0表示master >0 表示slave
brokerId=1
#删除文件的时间点,凌晨4点
deleteWhen=04
#文件保留时间 默认是48小时
fileReservedTime=48
#Broker 的角色,ASYNC_MASTER=异步复制Master,SYNC_MASTER=同步双写Master,SLAVE=slave节点
brokerRole=SLAVE
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘 
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口端口号对应docker启动时候的端口号
listenPort=11014
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.56.10:9876;192.168.56.10:9877
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#设置BrokerIP
brokerIP1=192.168.56.10
# 限制的消息⼤⼩
maxMessageSize=65536
# commitLog每个⽂件的⼤⼩默认1G
mapedFileSizeCommitLog=1073741824
# ConsumeQueue每个⽂件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000

4. 拉取镜像

docker pull foxiswho/rocketmq:4.8.0

5. 安装nameserver

#启动 rmqnamesrv-master
docker run -d -v /data/rocketmq/logs-nameserver-m:/home/rocketmq/logs \
--name rmqnamesrv-master \
--restart=always \
-e "JAVA_OPT_EXT=-Xms256M -Xmx256M -Xmn128m" \
-p 9876:9876 \
foxiswho/rocketmq:4.8.0  \
sh mqnamesrv
 
#启动 rmqnamesrv-slave
docker run -d -v /data/rocketmq/logs-nameserver-s:/home/rocketmq/logs \
--name rmqnamesrv-slave \
--restart=always \
-e "JAVA_OPT_EXT=-Xms256M -Xmx256M -Xmn128m" \
-p 9877:9876 \
foxiswho/rocketmq:4.8.0 \
sh mqnamesrv

6. 安装broker

# 启动 mq-a-master
docker run -d    \
--name mq-a-master  \
--restart=always \
-v /data/rocketmq/logs-a:/home/rocketmq/logs \
-v /data/rocketmq/store-a:/home/rocketmq/store \
-v /data/rocketmq/conf/broker-a.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf \
-e "NAMESRV_ADDR=192.168.56.10:9876;192.168.56.10:9877" \
-e "JAVA_OPT_EXT= -server -Xms128M -Xmx128M -Xmn128m" \
-p 10911:10911 \
foxiswho/rocketmq:4.8.0 \
sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
 
#启动 mq-b-master
docker run -d \
--name mq-b-master \
--restart=always \
-v /data/rocketmq/logs-b:/home/rocketmq/logs  \
-v /data/rocketmq/store-b:/home/rocketmq/store \
-v /data/rocketmq/conf/broker-b.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf \
-e "NAMESRV_ADDR=192.168.56.10:9876;192.168.56.10:9877" \
-e "JAVA_OPT_EXT= -server -Xms128M -Xmx128M -Xmn128m" \
-p 11912:11912  \
--privileged=true \
foxiswho/rocketmq:4.8.0 \
sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
 
#启动 mq-a-slave
docker run -d   \
--name mq-a-slave \
--restart=always \
-v /data/rocketmq/logs-a-s:/home/rocketmq/logs \
-v /data/rocketmq/store-a-s:/home/rocketmq/store \
-v /data/rocketmq/conf/broker-a-s.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf \
-e "NAMESRV_ADDR=192.168.56.10:9876;192.168.56.10:9877" \
-e "JAVA_OPT_EXT= -server -Xms128M -Xmx128M -Xmn128m" \
-p  11013:11013 \
foxiswho/rocketmq:4.8.0 \
sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
 
#启动 mq-b-slave
docker run -d  \
--name mq-b-slave \
--restart=always \
-v /data/rocketmq/logs-b-s:/home/rocketmq/logs \
-v /data/rocketmq/store-b-s:/home/rocketmq/store \
-v /data/rocketmq/conf/broker-b-s.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf \
-e "NAMESRV_ADDR=192.168.56.10:9876;192.168.56.10:9877" \
-e "JAVA_OPT_EXT= -server -Xms128M -Xmx128M -Xmn128m" \
-p 11014:11014  \
foxiswho/rocketmq:4.8.0 \
sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf

7. 验证

# 拉取rocketmq-console-ng镜像
docker pull styletang/rocketmq-console-ng:1.0.0

# 运行rocketmq-console-ng容器
docker run -d \
--name rmq-console \
--restart=always \
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=192.168.56.10:9876;192.168.56.10:9877 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
-p 8888:8080 \
styletang/rocketmq-console-ng:1.0.0

在这里插入图片描述

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

层巅余落日

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值