Docker安装多主多备rocketMQ集群之Docker-compose方式

本文涉及的产品
传统型负载均衡 CLB,每月750个小时 15LCU
EMR Serverless StarRocks,5000CU*H 48000GB*H
应用型负载均衡 ALB,每月750个小时 15LCU
简介: Docker安装多主多备rocketMQ集群之Docker-compose方式

正文


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


一、安装docker-compose


假设你电脑已经安装了docker了


1、下载docker-compose


[root@bogon ~]# sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/do


2、授权


[root@bogon ~]# sudo chmod +x /usr/local/bin/docker-compose


3、检测是否安装成功


[root@bogon bin]# docker-compose --version或者docker-compose -v


4、卸载


[root@bogon bin]# sudo rm /usr/local/bin/docker-compose


二、安装rocketmq


配置文件


1、创建配置文件目录


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


2、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
#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


3、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=11911
#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


4、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=12911
#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


5、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=13911
#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


yml配置文件


1、创建目录存放docker-compose.yml


[root@bogon ~]# mkdir -p /usr/local/docker-compose/rocketmq


2、vi docker-compose.yml 如下内容


version: '2'
services:
  namesrv1:
    image: foxiswho/rocketmq:4.8.0
    container_name: rmqnamesrv1
    ports:
      - 9876:9876
    volumes:
      - /data/rocketmq/logs-nameserver-m:/home/rocketmq/logs
    environment:
      JAVA_OPT_EXT: -server -Xms256M -Xmx256M -Xmn128m
    command: sh mqnamesrv
  namesrv2:
    image: foxiswho/rocketmq:4.8.0
    container_name: rmqnamesrv2
    ports:
      - 9877:9877
    volumes:
      - /data/rocketmq/logs-nameserver-s:/home/rocketmq/logs
    environment:
      JAVA_OPT_EXT: -server -Xms256M -Xmx256M -Xmn128m
    command: sh mqnamesrv
  broker-a-m:
      image: foxiswho/rocketmq:4.8.0
      container_name: rmqbroker-a-master
      ports:
        - 10909:10909
        - 10911:10911
        - 10912:10912
      volumes:
      - /data/rocketmq/logs-a:/home/rocketmq/logs
      - /data/rocketmq/store-a:/home/rocketmq/store
      - /data/rocketmq/conf/broker-a.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf
      environment:
        JAVA_OPT_EXT: -server -Xms256m -Xmx256m -Xmn128m
        NAMESRV_ADDR: 192.168.139.156:9876;192.168.139.156:9877
      command: sh mqbroker  -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
  broker-b-m:
    image: foxiswho/rocketmq:4.8.0
    container_name: rmqbroker-b-master
    ports:
      - 11909:11909
      - 11911:11911
      - 11912:11912
    volumes:
    - /data/rocketmq/logs-b:/home/rocketmq/logs
    - /data/rocketmq/store-b:/home/rocketmq/store
    - /data/rocketmq/conf/broker-b.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf
    environment:
      JAVA_OPT_EXT: -server -Xms256m -Xmx256m -Xmn128m
      NAMESRV_ADDR: 192.168.139.156:9876;192.168.139.156:9877
    command: sh mqbroker  -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
  broker-a-s:
    image: foxiswho/rocketmq:4.8.0
    container_name: rmqbroker-a-slave
    ports:
      - 12909:12909
      - 12911:12911
      - 12912:12912
    volumes:
      - /data/rocketmq/logs-a-s:/home/rocketmq/logs
      - /data/rocketmq/store-a-s:/home/rocketmq/store
      - /data/rocketmq/conf/broker-a-s.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf
    environment:
      JAVA_OPT_EXT: -server -Xms256m -Xmx256m -Xmn128m
      NAMESRV_ADDR: 192.168.139.156:9876;192.168.139.156:9877
    command: sh mqbroker  -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
  broker-b-s:
    image: foxiswho/rocketmq:4.8.0
    container_name: rmqbroker-b-slave
    ports:
      - 13909:13909
      - 13911:13911
      - 13912:13912
    volumes:
      - /data/rocketmq/logs-b-s:/home/rocketmq/logs
      - /data/rocketmq/store-b-s:/home/rocketmq/store
      - /data/rocketmq/conf/broker-b-s.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf
    environment:
      JAVA_OPT_EXT: -server -Xms256m -Xmx256m -Xmn128m
      NAMESRV_ADDR: 192.168.139.156:9876;192.168.139.156:9877
    command: sh mqbroker  -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
    depends_on:
      - namesrv1
      - namesrv2


注意:yml文件格式一定要写对,建议修改完成之后在线校验一下。一定要对新建的存储目录和配置文件chmod 777授权,否则启动不起来!!!


3、启动


docker-compose.yml的目录下启动


docker-compose up
#后台启动
docker-compose up -d


三、安装成功


222.png


端口号说明


listenPort参数是broker的监听端口号,是remotingServer服务组件使用,作为对Producer和Consumer提供服务的端口号,默认为10911。


fastListenPort参数是fastRemotingServer服务组件使用,默认为listenPort - 2,#主要用于slave同步master ,fastListenPort=10909。


haListenPort参数是HAService服务组件使用,用于Broker的主从同步,默认为listenPort - 1, haService中使用 haListenPort=10912

相关实践学习
消息队列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
相关文章
|
19天前
|
Prometheus 监控 Cloud Native
基于Docker安装Grafana和Prometheus
Grafana 是一款用 Go 语言开发的开源数据可视化工具,支持数据监控和统计,并具备告警功能。通过 Docker 部署 Grafana 和 Prometheus,可实现系统数据的采集、展示和告警。默认登录用户名和密码均为 admin。配置 Prometheus 数据源后,可导入主机监控模板(ID 8919)进行数据展示。
53 2
|
22天前
|
消息中间件 Linux RocketMQ
在Red Hat Enterprise Linux 9上使用Docker快速安装并部署
通过以上步骤,你可以在Red Hat Enterprise Linux 9上使用Docker快速安装并部署RocketMQ。这种方法不仅简化了安装过程,还提供了一个灵活的环境来管理和扩展消息队列系统。RocketMQ作为一款高性能的分布式消息系统,通过Docker可以实现快速部署和高效管理。
51 2
|
23天前
|
消息中间件 Linux RocketMQ
在Red Hat Enterprise Linux 9上使用Docker快速安装并部署
通过以上步骤,你可以在Red Hat Enterprise Linux 9上使用Docker快速安装并部署RocketMQ。这种方法不仅简化了安装过程,还提供了一个灵活的环境来管理和扩展消息队列系统。RocketMQ作为一款高性能的分布式消息系统,通过Docker可以实现快速部署和高效管理。
32 3
|
9天前
|
Docker 容器
【赵渝强老师】使用二进制包方式安装Docker
本文介绍了在企业生产环境中无法直接访问外网时,如何使用Docker官方提供的二进制包进行Docker的离线安装。文章详细列出了从安装wget、下载Docker安装包、解压、复制命令到启动Docker服务的具体步骤,并提供了相关命令和示例图片。最后,还介绍了如何设置Docker为开机自启模式。
|
9天前
|
缓存 Ubuntu Linux
如何安装Docker
如何安装Docker
72 0
|
7天前
|
Kubernetes Cloud Native Docker
云原生时代的容器化实践:Docker和Kubernetes入门
【10月更文挑战第37天】在数字化转型的浪潮中,云原生技术成为企业提升敏捷性和效率的关键。本篇文章将引导读者了解如何利用Docker进行容器化打包及部署,以及Kubernetes集群管理的基础操作,帮助初学者快速入门云原生的世界。通过实际案例分析,我们将深入探讨这些技术在现代IT架构中的应用与影响。
30 2
|
Kubernetes 物联网 数据中心
DockOne微信分享( 九十五):树莓派上的Docker集群管理
本文讲的是DockOne微信分享( 九十五):树莓派上的Docker集群管理【编者的话】随着IOT市场的火热发展,Docker天然的轻量级以及帮助业务快速重构的特性,将会在IOT领域迎来巨大发展潜力,甚至有可能会比它在云端的潜力更大。
3451 0
|
5天前
|
运维 Cloud Native 虚拟化
一文吃透云原生 Docker 容器,建议收藏!
本文深入解析云原生Docker容器技术,涵盖容器与Docker的概念、优势、架构设计及应用场景等,建议收藏。关注【mikechen的互联网架构】,10年+BAT架构经验倾囊相授。
一文吃透云原生 Docker 容器,建议收藏!
|
13天前
|
关系型数据库 MySQL API
|
9天前
|
运维 持续交付 Docker
深入理解Docker容器化技术
深入理解Docker容器化技术