Docker部署RocketMQ集群

Posted Luther-

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker部署RocketMQ集群相关的知识,希望对你有一定的参考价值。

最近搭建RocketMQ踩了一些坑,更新下

第一步,创建目录

mkdir -p /opt/rocketmq/logs/nameserver-a
mkdir -p /opt/rocketmq/logs/nameserver-b
mkdir -p /opt/rocketmq/store/nameserver-a
mkdir -p /opt/rocketmq/store/nameserver-b
mkdir -p /opt/rocketmq/logs/broker-a
mkdir -p /opt/rocketmq/logs/broker-b
mkdir -p /opt/rocketmq/store/broker-a
mkdir -p /opt/rocketmq/store/broker-b
mkdir -p /opt/rocketmq/broker-a/
mkdir -p /opt/rocketmq/broker-b/

第二步,创建broker.conf

vim /opt/rocketmq/broker-a/broker-a.conf
vim /opt/rocketmq/broker-b/broker-b.conf

brokerClusterName = rocketmq-cluster
brokerName = broker-a
brokerId = 0
#这个很有讲究 如果是正式环境 这里一定要填写内网地址(安全)
#如果是用于测试或者本地这里建议要填外网地址,因为你的本地代码是无法连接到阿里云内网,只能连接外网。
brokerIP1 = IP
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 内网的(阿里云有内网IP和外网IP)
namesrvAddr=IP:9876;IP:9877
autoCreateTopicEnable=true
#Broker 对外服务的监听端口,
listenPort = 10911
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH

=================================================================

brokerClusterName = rocketmq-cluster
brokerName = broker-b
brokerId = 0
brokerIP1 = IP
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 内网的(阿里云有内网IP和外网IP)
namesrvAddr=IP:9876;IP:9877
autoCreateTopicEnable=true
#Broker 对外服务的监听端口,
listenPort = 10912
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH

第三步,编写 docker-compose.yml

vim /opt/rocketmq/docker-compose.yml

version: '3.5'
services:
  rmqnamesrv-a:
    image: rocketmqinc/rocketmq:4.4.0
    container_name: rmqnamesrv-a
    ports:
      - 9876:9876
    volumes:
      - /opt/rocketmq/logs/nameserver-a:/home/rocketmq/logs
      - /opt/rocketmq/store/nameserver-a:/home/rocketmq/store
    command: sh mqnamesrv
    networks:
        rmq:
          aliases:
            - rmqnamesrv-a

  rmqnamesrv-b:
    image: rocketmqinc/rocketmq:4.4.0
    container_name: rmqnamesrv-b
    ports:
      - 9877:9877
    volumes:
      - /opt/rocketmq/logs/nameserver-b:/home/rocketmq/logs
      - /opt/rocketmq/store/nameserver-b:/home/rocketmq/store
    command: sh mqnamesrv
    networks:
        rmq:
          aliases:
            - rmqnamesrv-b

  rmqbroker-a:
    image: rocketmqinc/rocketmq:4.4.0
    container_name: rmqbroker-a
    ports:
      - 10911:10911
    volumes:
      - /opt/rocketmq/logs/broker-a:/opt/logs
      - /opt/rocketmq/store/broker-a:/opt/store
      - /opt/rocketmq/broker-a/broker-a.conf:/opt/rocketmq-4.4.0/conf/broker.conf
    environment:
        TZ: Asia/Shanghai
        NAMESRV_ADDR: "rmqnamesrv-a:9876"
        JAVA_OPTS: " -Duser.home=/opt"
        JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf
    links:
      - rmqnamesrv-a:rmqnamesrv-a
      - rmqnamesrv-b:rmqnamesrv-b
    networks:
      rmq:
        aliases:
          - rmqbroker-a

  rmqbroker-b:
    image: rocketmqinc/rocketmq:4.4.0
    container_name: rmqbroker-b
    ports:
      - 10912:10912
    volumes:
      - /opt/rocketmq/logs/broker-b:/opt/logs
      - /opt/rocketmq/store/broker-b:/opt/store
      - /opt/rocketmq/broker-b/broker-b.conf:/opt/rocketmq-4.4.0/conf/broker.conf
    environment:
        TZ: Asia/Shanghai
        NAMESRV_ADDR: "rmqnamesrv-b:9877"
        JAVA_OPTS: " -Duser.home=/opt"
        JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf
    links:
      - rmqnamesrv-a:rmqnamesrv-a
      - rmqnamesrv-b:rmqnamesrv-b
    networks:
      rmq:
        aliases:
          - rmqbroker-b
  rmqconsole:
    image: styletang/rocketmq-console-ng
    container_name: rmqconsole
    ports:
      - 8087:8080
    environment:
        JAVA_OPTS: -Drocketmq.namesrv.addr=rmqnamesrv-a:9876;rmqnamesrv-b:9877 -Dcom.rocketmq.sendMessageWithVIPChannel=false
    networks:
      rmq:
        aliases:
          - rmqconsole
networks:
  rmq:
    name: rmq
    driver: bridge

最后一步,执行docker-compose

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

 http://IP:8087/#/

以上是关于Docker部署RocketMQ集群的主要内容,如果未能解决你的问题,请参考以下文章

Docker部署RocketMQ集群

Docker部署RocketMQ集群

docker-compose部署rocketmq集群

SpringBoot整合RocketMQ

SpringBoot(17)---SpringBoot整合RocketMQ

docker-compose安装RocketMQ集群