Docker安装rocketMQ集群之挂载方式安装

本文涉及的产品
传统型负载均衡 CLB,每月750个小时 15LCU
网络型负载均衡 NLB,每月750个小时 15LCU
应用型负载均衡 ALB,每月750个小时 15LCU
简介: Docker安装rocketMQ集群之挂载方式安装

正文


本人是在一台虚拟机上搭建的,如果是生产部署请做相应的修改!!!


1、创建挂载目录


[root@bogon ~]# mkdir -p /data/rocketmq/{logs-nameserver-m,logs-nameserver-s,logs-a,logs-a-s,lo


2、对这些创建的文件授权(注意是所有的这些创建的文件,包括对应的配置文件!!!


chmod 777 对应的文件名称


3、创建配置文件


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=rocketmq-cluster
#broker名字
brokerName=broker-a
#0表示master >0 表示slave
brokerId=0
#删除文件的时间点,凌晨4点
deleteWhen=04
#文件保留时间 默认是48小时
fileReservedTime=168
#异步复制Master
brokerRole=ASYNC_MASTER
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘 
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=10911 端口号对应docker启动时候的端口号
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.139.156:9876;192.168.139.156:9877
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#设置BrokerIP
brokerIP1=192.168.139.156


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=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样  例如:在a.properties 文件中写 broker-a  在b.properties 文件中写 broker-b
brokerName=broker-b
#0 表示 Master,>0 表示 Slave
brokerId=0
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=168
#Broker 的角色,ASYNC_MASTER=异步复制Master,SYNC_MASTER=同步双写Master,SLAVE=slave节点
brokerRole=ASYNC_MASTER
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘 
flushDiskType=SYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=11912
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.139.156:9876;192.168.139.156:9877
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#设置BrokerIP
brokerIP1=192.168.139.156


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=rocketmq-cluster
#broker名字,注意此处不同的配置文件填写的不一样  例如:在a.properties 文件中写 broker-a  在b.properties 文件中写 broker-b
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=1
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=168
#Broker 的角色,ASYNC_MASTER=异步复制Master,SYNC_MASTER=同步双写Master,SLAVE=slave节点
brokerRole=SLAVE
#刷盘方式,ASYNC_FLUSH=异步刷盘,SYNC_FLUSH=同步刷盘 
flushDiskType=SYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=11013
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.139.156:9876;192.168.139.156:9877
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#设置BrokerIP
brokerIP1=192.168.139.156


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=rocketmq-cluster
brokerName=broker-b
#slave
brokerId=1
deleteWhen=04
fileReservedTime=168
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
#Broker 对外服务的监听端口
listenPort=11014
#nameServer地址,这里nameserver是单台,如果nameserver是多台集群的话,就用分号分割(即namesrvAddr=ip1:port1;ip2:port2;ip3:port3)
namesrvAddr=192.168.139.156:9876;192.168.139.156:9877
#每个topic对应队列的数量,默认为4,实际应参考consumer实例的数量,值过小不利于consumer负载均衡
defaultTopicQueueNums=8
#是否允许 Broker 自动创建Topic,生产建议关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,生产建议关闭
autoCreateSubscriptionGroup=true
#设置BrokerIP
brokerIP1=192.168.139.156


注意如果拷贝出来的文件格式不对请做相应的修改


解决方法,拷贝的文件格式错乱使用下面命令乎看到文件后面多了^M

[root@bogon bin]# vim -b broker-a.conf


去掉^M 再重新启动

[root@bogon bin]# sed -i 's/\r//g' broker-a.conf  


4、拉取镜像


[root@bogon ~]# 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 \
-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 \
-e "JAVA_OPT_EXT=-Xms256M -Xmx256M -Xmn128m" \
-p 9877:9877 \
foxiswho/rocketmq:4.8.0 \
sh mqnamesrv


6、安装broker


启动 mq-a-master
docker run -d --name mq-a-master  \
-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.139.156:9876;192.168.139.156: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 \
-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.139.156:9876;192.168.139.156: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 \
-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.139.156:9876;192.168.139.156: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 \
-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.139.156:9876;192.168.139.156: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、验证


111.png


搭建成功,有不对的地方请大神不吝赐教。


参考:Docker Hub

相关实践学习
消息队列RocketMQ版:基础消息收发功能体验
本实验场景介绍消息队列RocketMQ版的基础消息收发功能,涵盖实例创建、Topic、Group资源创建以及消息收发体验等基础功能模块。
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
相关文章
|
26天前
|
消息中间件 编解码 Docker
【Docker项目实战】Docker部署RabbitMQ消息中间件
【10月更文挑战第8天】Docker部署RabbitMQ消息中间件
69 1
【Docker项目实战】Docker部署RabbitMQ消息中间件
|
1月前
|
消息中间件 数据安全/隐私保护 Docker
Docker安装rabbitmq
如何使用Docker安装和配置RabbitMQ服务,包括拉取RabbitMQ镜像、创建容器、配置持久化和访问管理界面的步骤。
84 0
Docker安装rabbitmq
|
2月前
|
NoSQL 关系型数据库 Redis
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
mall在linux环境下的部署(基于Docker容器),docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongodb、minio详细教程,拉取镜像、运行容器
mall在linux环境下的部署(基于Docker容器),Docker安装mysql、redis、nginx、rabbitmq、elasticsearch、logstash、kibana、mongo
|
2月前
|
消息中间件 Linux
centos7安装rabbitmq
centos7安装rabbitmq
|
3月前
|
消息中间件 存储 负载均衡
|
2月前
|
消息中间件 Linux
linux之centos安装rabbitmq
linux之centos安装rabbitmq
|
3月前
|
存储 C# 关系型数据库
“云端融合:WPF应用无缝对接Azure与AWS——从Blob存储到RDS数据库,全面解析跨平台云服务集成的最佳实践”
【8月更文挑战第31天】本文探讨了如何将Windows Presentation Foundation(WPF)应用与Microsoft Azure和Amazon Web Services(AWS)两大主流云平台无缝集成。通过具体示例代码展示了如何利用Azure Blob Storage存储非结构化数据、Azure Cosmos DB进行分布式数据库操作;同时介绍了如何借助Amazon S3实现大规模数据存储及通过Amazon RDS简化数据库管理。这不仅提升了WPF应用的可扩展性和可用性,还降低了基础设施成本。
76 0
|
消息中间件 算法 Java
弥补延时消息的不足,RocketMQ 基于时间轮算法实现了定时消息!
弥补延时消息的不足,RocketMQ 基于时间轮算法实现了定时消息!
763 1
弥补延时消息的不足,RocketMQ 基于时间轮算法实现了定时消息!
|
消息中间件 uml RocketMQ
3 张图带你彻底理解 RocketMQ 事务消息
3 张图带你彻底理解 RocketMQ 事务消息
67760 2
3 张图带你彻底理解 RocketMQ 事务消息
|
消息中间件 Java uml
5张图带你理解 RocketMQ 顺序消息实现机制
5张图带你理解 RocketMQ 顺序消息实现机制
676 1
5张图带你理解 RocketMQ 顺序消息实现机制