docker-compose安装rocketmq双主集群

简介

使用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,集群已经存在!部署成功
docker-compose安装rocketmq双主集群_第1张图片

你可能感兴趣的:(rocketmq,docker-compose,rocketmq)