docker-compose安裝rocketmq雙主叢集

潑墨畫丹青發表於2020-12-30

簡介

使用docker-compose搭建rocketmq雙主叢集,之所以使用docker-compose是因為啟動部署都比較簡單,不用每次啟動容器傳入引數,可以統一管理等等。這裡使用兩臺伺服器(前提需要安裝docker,安裝docker-compose),一臺101伺服器是放nameserver,一臺102伺服器是放broker以及控制檯,因為只是開發使用,所以broker並未放在兩臺伺服器上

部署nameserver

  1. 101伺服器新建一個/docker/rocketmq-cluster-docker目錄,在裡面新建logs目錄以及store目錄
  2. 新建一個docker-compose.yaml檔案
    在這裡插入圖片描述
  3. docker-compose檔案
version: '3.5'
services:
  rmqnamesrv-a:
    image: foxiswho/rocketmq:server-4.5.2
    restart: always
    container_name: rmqnamesrv-a
    ports:
      - 9876:9876
    volumes:
      - ./logs/nameserver-a:/opt/logs
      - ./store/nameserver-a:/opt/store
    environment:
      JAVA_OPT_EXT: "-Duser.home=/opt -Xms512m -Xmx512m -Xmn150m"


  rmqnamesrv-b:
    image: foxiswho/rocketmq:server-4.5.2
    restart: always
    container_name: rmqnamesrv-b
    ports:
      - 9877:9876
    volumes:
      - ./logs/nameserver-b:/opt/logs
      - ./store/nameserver-b:/opt/store
    environment:
      JAVA_OPT_EXT: "-Duser.home=/opt -Xms512m -Xmx512m -Xmn150m"

  1. 啟動nameserver並檢視是否啟動成功

注意啟動命令要在docker-compose.yaml檔案同級目錄

docker-compose up -d

在這裡插入圖片描述
啟動成功

部署broker以及console

  1. 101伺服器新建一個/docker/rocketmq-cluster-docker目錄,在裡面新建logs目錄以及store目錄
  2. 新建一個docker-compose.yaml檔案
  3. docker-compose.yaml檔案內容
version: '3.5'
services:
  rmqbroker-a:
    image: foxiswho/rocketmq:broker-4.5.2
    container_name: rmqbroker-a
    restart: always
    ports:
      - 10909:10909
      - 10911:10911
    volumes:
      - ./logs/broker-a:/opt/logs
      - ./store/broker-a:/opt/store
      - ./broker-a/broker-a.conf:/etc/rocketmq/broker.conf
    environment:
        TZ: Asia/Shanghai
        JAVA_OPTS: " -Duser.home=/opt"
        JAVA_OPT_EXT: "-server  -Xms512m -Xmx512m -Xmn150m"  
    command: sh mqbroker -c /etc/rocketmq/broker.conf autoCreateTopicEnable=true &

  rmqbroker-b:
    image: foxiswho/rocketmq:broker-4.5.2
    container_name: rmqbroker-b
    restart: always
    ports:
      - 10916:10909
      - 10915:10915
    volumes:
      - ./logs/broker-b:/opt/logs
      - ./store/broker-b:/opt/store
      - ./broker-b/broker-b.conf:/etc/rocketmq/broker.conf
    environment:
        TZ: Asia/Shanghai
        JAVA_OPTS: " -Duser.home=/opt"
        JAVA_OPT_EXT: "-server -Xms512m -Xmx512m -Xmn150m"  
    command: sh mqbroker -c /etc/rocketmq/broker.conf autoCreateTopicEnable=true &


  rmqconsole:
    image: styletang/rocketmq-console-ng
    container_name: rmqconsole
    restart: always
    ports:
      - 9001:8080
    environment:
        JAVA_OPTS: -Drocketmq.namesrv.addr=192.168.10.101:9876;192.168.10.101:9877 -Dcom.rocketmq.sendMessageWithVIPChannel=false

注意配置改成自己的
4. 啟動broker以及console並檢視是否啟動成功
在這裡插入圖片描述
啟動成功
然後訪問console目錄:192.168.10.102:9001,叢集已經存在!部署成功
在這裡插入圖片描述

相關文章