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版Serverless系列实例进行获取接入点、创建Topic、创建订阅组、收发消息、查看消息轨迹和仪表盘。
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
相关文章
|
2月前
|
物联网 Linux 开发者
快速部署自己私有MQTT-Broker-下载安装到运行不到一分钟,快速简单且易于集成到自己项目中
本文给物联网开发的朋友推荐的是GMQT,让物联网开发者快速拥有合适自己的MQTT-Broker,本文从下载程序到安装部署手把手教大家安装用上私有化MQTT服务器。
721 5
|
3月前
|
存储 NoSQL MongoDB
Docker中安装MongoDB并配置数据、日志、配置文件持久化。
现在,你有了一个运行在Docker中的MongoDB,它拥有自己的小空间,对高楼大厦的崩塌视而不见(会话丢失和数据不持久化的问题)。这个MongoDB的数据、日志、配置文件都会妥妥地保存在你为它精心准备的地方,天旋地转,它也不会失去一丁点儿宝贵的记忆(即使在容器重启后)。
320 4
|
3月前
|
Linux iOS开发 Docker
MyEMS开源系统安装之Linux/macOS上的DOcker
本指南详细介绍了如何在Linux/macOS上使用Docker部署MyEMS系统。主要内容包括:前置条件(如安装Docker、npm和MySQL),以及分步骤部署各个组件(如myems-api、myems-admin、myems-modbus-tcp等)。每个步骤涵盖源代码复制、环境配置、镜像构建、容器运行及日志管理等操作,并提供了多平台构建的支持。最后,指南还说明了默认端口和登录凭据,帮助用户快速启动并访问MyEMS的管理界面和Web界面。
113 1
|
4月前
|
关系型数据库 MySQL 数据库
Docker 安装常用软件相关命令
本文介绍了在CentOS 7.9系统上安装Docker的详细步骤,包括添加阿里云镜像源、安装Docker及相关组件、启动服务以及配置镜像加速。同时,还展示了如何通过Docker安装MySQL 5.7版本数据库,涵盖拉取镜像、创建数据目录、运行容器及配置挂载点等操作,并提供验证安装成功的命令和截图。适合需要部署Docker与MySQL环境的用户参考。
277 7
|
Kubernetes 物联网 数据中心
DockOne微信分享( 九十五):树莓派上的Docker集群管理
本文讲的是DockOne微信分享( 九十五):树莓派上的Docker集群管理【编者的话】随着IOT市场的火热发展,Docker天然的轻量级以及帮助业务快速重构的特性,将会在IOT领域迎来巨大发展潜力,甚至有可能会比它在云端的潜力更大。
3510 0
|
2月前
|
存储 监控 测试技术
如何将现有的应用程序迁移到Docker容器中?
如何将现有的应用程序迁移到Docker容器中?
197 57
|
3月前
|
存储 运维 安全
Docker化运维:容器部署的实践指南
Docker化运维:容器部署的实践指南