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

简介: 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一站式入门使用
从源码编译、部署broker、部署namesrv,使用java客户端首发消息等一站式入门RocketMQ。
消息队列 MNS 入门课程
1、消息队列MNS简介 本节课介绍消息队列的MNS的基础概念 2、消息队列MNS特性 本节课介绍消息队列的MNS的主要特性 3、MNS的最佳实践及场景应用 本节课介绍消息队列的MNS的最佳实践及场景应用案例 4、手把手系列:消息队列MNS实操讲 本节课介绍消息队列的MNS的实际操作演示 5、动手实验:基于MNS,0基础轻松构建 Web Client 本节课带您一起基于MNS,0基础轻松构建 Web Client
相关文章
|
1天前
|
Linux Docker 容器
最全树莓派4B安装docker-compose(64位Linux)(1),2024年最新一文说清
最全树莓派4B安装docker-compose(64位Linux)(1),2024年最新一文说清
|
4天前
|
Docker 容器
docker部署omni_usdt 0.8.0版本私有链集群环境
docker部署omni_usdt 0.8.0版本私有链集群环境
|
4天前
|
jenkins 持续交付 数据安全/隐私保护
Docker 安装 Jenkins
Jenkins 是一个独立的开源自动化服务器,可用于自动化与构建、测试、交付或部署软件相关的各种任务。
26 1
|
4天前
|
Linux Docker 容器
安装新版本Docker报错container-selinux >= 2:2.74 - 蓝易云
以上步骤应该能够帮助你解决遇到的问题。如果问题仍然存在,你可能需要寻求专业的技术支持。
22 0
|
5天前
|
Ubuntu Linux Docker
window10下安装ubuntu系统以及docker使用
window10下安装ubuntu系统以及docker使用
|
6天前
|
并行计算 Ubuntu Docker
Docker环境Ubuntu20.04安装Python3.10版本
Docker环境Ubuntu20.04安装Python3.10版本
50 0
|
6天前
|
Ubuntu Docker 容器
Ubuntu 22.04.3 LTS_安装Docker
Ubuntu 22.04.3 LTS_安装Docker
59 1
|
6天前
|
消息中间件 Java API
MQ产品使用合集之RocketMQ dledger集群模式的dledgerpeers端口是集群之间通讯吗
消息队列(MQ)是一种用于异步通信和解耦的应用程序间消息传递的服务,广泛应用于分布式系统中。针对不同的MQ产品,如阿里云的RocketMQ、RabbitMQ等,它们在实现上述场景时可能会有不同的特性和优势,比如RocketMQ强调高吞吐量、低延迟和高可用性,适合大规模分布式系统;而RabbitMQ则以其灵活的路由规则和丰富的协议支持受到青睐。下面是一些常见的消息队列MQ产品的使用场景合集,这些场景涵盖了多种行业和业务需求。
14 0
|
存储 消息中间件 RocketMQ
自己制作的RocketMQ的Docker镜像
RocketMQ的Docker镜像简要配置说明
3731 0
|
1天前
|
Prometheus 监控 Cloud Native
构建高效稳定的Docker容器监控体系
【5月更文挑战第20天】 在微服务架构日益普及的今天,Docker作为其重要的实现技术之一,承载着大量应用的运行。然而,随之而来的是对于容器健康状态、资源使用情况以及性能指标的监控需求急剧增加。本文旨在探讨构建一个高效且稳定的Docker容器监控体系,不仅涵盖了监控工具的选择与配置,还详细阐述了监控数据的分析与处理流程。通过精心设计的监控策略和实时响应机制,我们能够确保系统的稳定性,并及时发现及处理潜在的问题。

热门文章

最新文章