热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

dockercompose搭建多主多从RocketMQ集群

1.创建目录mkdir-phomerocketmqnamesvr1data&&mkdir-phomerocketmqnamesvr1log&&mkdir-phomerocketm

1.创建目录

mkdir -p /home/rocketmq/namesvr1/data &&
 
mkdir -p /home/rocketmq/namesvr1/log &&
 
mkdir -p /home/rocketmq/namesvr2/data &&
 
mkdir -p /home/rocketmq/namesvr2/log &&
 
mkdir -p /home/rocketmq/broker-m-1/data &&
 
mkdir -p /home/rocketmq/broker-m-1/log &&
 
mkdir -p /home/rocketmq/broker-m-1/conf &&
 
mkdir -p /home/rocketmq/broker-m-2/data &&
 
mkdir -p /home/rocketmq/broker-m-2/log &&
 
mkdir -p /home/rocketmq/broker-m-2/conf &&
 
mkdir -p /home/rocketmq/broker-s-1/data &&
 
mkdir -p /home/rocketmq/broker-s-1/log &&
 
mkdir -p /home/rocketmq/broker-s-1/conf &&
 
mkdir -p /home/rocketmq/broker-s-2/data &&
 
mkdir -p /home/rocketmq/broker-s-2/log &&
 
mkdir -p /home/rocketmq/broker-s-2/conf
目录结构:

2.进入每个broker的conf目录下创建配置文件

broker-m-1.conf

#集群名称
brokerClusterName=DefaultCluster
#broker名称
brokerName=broker1
#brokerId master用0 slave用其他
brokerId=0
#清理时机
deleteWhen=4
#文件保留时长 48小时
fileReservedTime=48
#broker角色 -ASYNC_MASTER异步复制 -SYNC_MASTER同步双写 -SLAVE
brokerRole=SYNC_MASTER
#刷盘策略 - ASYNC_FLUSH 异步刷盘 - SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
#主机ip
brokerIP1=192.168.88.3
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=10911
#namesvr
namesrvAddr=192.168.88.3:9876;192.168.88.3:9877
#是否能够自动创建topic
autoCreateTopicEnable=true
broker-s-1.conf

#集群名称
brokerClusterName=DefaultCluster
#broker名称
brokerName=broker1
#brokerId master用0 slave用其他
brokerId=1
#清理时机
deleteWhen=4
#文件保留时长 48小时
fileReservedTime=48
#broker角色 -ASYNC_MASTER异步复制 -SYNC_MASTER同步双写 -SLAVE
brokerRole=SLAVE
#刷盘策略 - ASYNC_FLUSH 异步刷盘 - SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
#主机ip
brokerIP1=192.168.88.3
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=11911
#namesrv
namesrvAddr=192.168.88.3:9876;192.168.88.3:9877
#是否能够自动创建topic
autoCreateTopicEnable=true
broker-m-2.conf

#集群名称
brokerClusterName=DefaultCluster
#broker名称
brokerName=broker2
#brokerId master用0 slave用其他
brokerId=0
#清理时机
deleteWhen=4
#文件保留时长 48小时
fileReservedTime=48
#broker角色 -ASYNC_MASTER异步复制 -SYNC_MASTER同步双写 -SLAVE
brokerRole=SYNC_MASTER
#刷盘策略 - ASYNC_FLUSH 异步刷盘 - SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
#主机ip
brokerIP1=192.168.88.3
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=12911
#namesrv
namesrvAddr=192.168.88.3:9876;192.168.88.3:9877
#是否能够自动创建topic
autoCreateTopicEnable=true
broker-s-2.conf

#集群名称
brokerClusterName=DefaultCluster
#broker名称
brokerName=broker2
#brokerId master用0 slave用其他
brokerId=1
#清理时机
deleteWhen=4
#文件保留时长 48小时
fileReservedTime=48
#broker角色 -ASYNC_MASTER异步复制 -SYNC_MASTER同步双写 -SLAVE
brokerRole=SLAVE
#刷盘策略 - ASYNC_FLUSH 异步刷盘 - SYNC_FLUSH 同步刷盘
flushDiskType=SYNC_FLUSH
#主机ip
brokerIP1=192.168.88.3
#对外服务的监听接口,同一台机器上部署多个broker,端口号要不相同
listenPort=13911
#namesrv
namesrvAddr=192.168.88.3:9876;192.168.88.3:9877
#是否能够自动创建topic
autoCreateTopicEnable=true
 

3.创建docker-compose.yml

version: '3.5'
services:
  namesrv1:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: namesrv1
    ports:
      - 9876:9876
    volumes:
      - /home/rocketmq/namesrv1/log:/opt/logs
      - /home/rocketmq/namesrv1/data:/opt/store
    command: sh mqnamesrv
    networks:
      rocketmq:
        aliases:
          - namesrv1
  namesrv2:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: namesrv2
    ports:
      - 9877:9876
    volumes:
      - /home/rocketmq/namesrv2/log:/opt/logs
      - /home/rocketmq/namesrv2/data:/opt/store
    command: sh mqnamesrv
    networks:
      rocketmq:
        aliases:
          - namesrv2
  broker-m-1:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: broker-m-1
    links:
      - namesrv1:namesrv1
      - namesrv2:namesrv2
    ports:
      - 10911:10911
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "namesrv1:9876"
      JAVA_OPTS: "-Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    volumes:
      - /home/rocketmq/broker-m-1/log:/opt/logs
      - /home/rocketmq/broker-m-1/data:/opt/store
      - /home/rocketmq/broker-m-1/conf/broker-m-1.conf:/opt/rocketmq-4.3.0/conf/broker-m-1.conf
    command: sh mqbroker -c /opt/rocketmq-4.3.0/conf/broker-m-1.conf autoCreateTopicEnable=true &
    networks:
      rocketmq:
        aliases:
          - broker-m-1
  broker-s-1:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: broker-s-1
    links:
      - namesrv1:namesrv1
      - namesrv2:namesrv2
    ports:
      - 11911:11911
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "namesrv1:9876"
      JAVA_OPTS: "-Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    volumes:
      - /home/rocketmq/broker-s-1/log:/opt/logs
      - /home/rocketmq/broker-s-1/data:/opt/store
      - /home/rocketmq/broker-s-1/conf/broker-s-1.conf:/opt/rocketmq-4.3.0/conf/broker-s-1.conf
    command: sh mqbroker -c /opt/rocketmq-4.3.0/conf/broker-s-1.conf autoCreateTopicEnable=true &
    networks:
      rocketmq:
        aliases:
          - broker-s-1
  broker-m-2:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: broker-m-2
    links:
      - namesrv1:namesrv1
      - namesrv2:namesrv1
    ports:
      - 12911:12911
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "namesrv1:9876"
      JAVA_OPTS: "-Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    volumes:
      - /home/rocketmq/broker-m-2/log:/opt/logs
      - /home/rocketmq/broker-m-2/data:/opt/store
      - /home/rocketmq/broker-m-2/conf/broker-m-2.conf:/opt/rocketmq-4.3.0/conf/broker-m-2.conf
    command: sh mqbroker -c /opt/rocketmq-4.3.0/conf/broker-m-2.conf autoCreateTopicEnable=true &
    networks:
      rocketmq:
        aliases:
          - broker-m-2
  broker-s-2:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: broker-s-2
    links:
      - namesrv1:namesrv1
      - namesrv2:namesrv2
    ports:
      - 13911:13911
    environment:
      TZ: Asia/Shanghai
      NAMESRV_ADDR: "namesrv1:9876"
      JAVA_OPTS: "-Duser.home=/opt"
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    volumes:
      - /home/rocketmq/broker-s-2/log:/opt/logs
      - /home/rocketmq/broker-s-2/data:/opt/store
      - /home/rocketmq/broker-s-2/conf/broker-s-2.conf:/opt/rocketmq-4.3.0/conf/broker-s-2.conf
    command: sh mqbroker -c /opt/rocketmq-4.3.0/conf/broker-s-2.conf autoCreateTopicEnable=true &
    networks:
      rocketmq:
        aliases:
          - broker-s-2
  rocketmq-console:
    image: styletang/rocketmq-console-ng
    container_name: rocketmq-console
    ports:
      - 8090:8080
    environment:
      JAVA_OPTS: -Drocketmq.namesrv.addr=namesrv1:9876;namesrv2:9877 -Dcom.rocketmq.sendMessageWithVIPChannel=false
    networks:
      rocketmq:
        aliases:
          - rocketmq-console
networks:
  rocketmq:
    name: rocketmq
    driver: bridge
4.执行命令

docker-compose -f docker-compose.yml up -d


推荐阅读
author-avatar
手机用户2502938015
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有