rocketmq 集群搭建

创建文件 134
mkdir -p /disk/rocketmq
mkdir -p /disk/rocketmq/logs/mqnamesrv-a
mkdir -p /disk/rocketmq/store/mqnamesrv-a
mkdir -p /disk/rocketmq/logs/broker-a
mkdir -p /disk/rocketmq/store/broker-a
mkdir -p /disk/rocketmq/logs/broker-s0
mkdir -p /disk/rocketmq/store/broker-s0
mkdir -p /disk/rocketmq/conf/broker-a
mkdir -p /disk/rocketmq/conf/broker-s0

touch /disk/rocketmq/conf/broker-a/broker.conf
touch /disk/rocketmq/conf/broker-s0/broker.conf
创建文件 135
mkdir -p /disk/rocketmq
mkdir -p /disk/rocketmq/logs/mqnamesrv-b
mkdir -p /disk/rocketmq/store/mqnamesrv-b
mkdir -p /disk/rocketmq/logs/broker-b
mkdir -p /disk/rocketmq/store/broker-b
mkdir -p /disk/rocketmq/logs/broker-s1
mkdir -p /disk/rocketmq/store/broker-s1
mkdir -p /disk/rocketmq/conf/broker-b
mkdir -p /disk/rocketmq/conf/broker-s1

touch /disk/rocketmq/conf/broker-b/broker.conf
touch /disk/rocketmq/conf/broker-s1/broker.conf

# 查看当前所开放的端口
firewall-cmd --zone=public --list-ports

/broker端口
firewall-cmd --zone=public --add-port=10909/tcp --permanent
firewall-cmd --zone=public --add-port=10912/tcp --permanent
firewall-cmd --zone=public --add-port=10911/tcp --permanent

firewall-cmd --zone=public --add-port=10913/tcp --permanent
firewall-cmd --zone=public --add-port=10915/tcp --permanent
firewall-cmd --zone=public --add-port=10916/tcp --permanent

/nameserver端口
firewall-cmd --zone=public --add-port=9876/tcp --permanent

/rocketmq console端口
firewall-cmd --zone=public --add-port=8080/tcp --permanent
firewall-cmd --zone=public --add-port=9001/tcp --permanent


# 更新防火墙规则,使端口生效
firewall-cmd --complete-reload


修改broker.conf

brokerClusterName = DefaultCluster
brokerName = broker-a #对应容器名称和
brokerId = 0 #主0 从1
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER #主从权限设置
flushDiskType = ASYNC_FLUSH
namesrvAddr = 172.17.5.134:9876;172.17.5.135:9876 #nameserver
brokerIP1 = 172.17.5.135 #本机ip

 


创建docker-compose 134
version: '3.7'
services:
  mqnamesrv-a:
    image: foxiswho/rocketmq:server-4.6.1
    container_name: mqnamesrv-a
    restart: always
    ports:
      - 9876:9876
    command: sh mqnamesrv
    volumes:
      - /disk/rocketmq/logs/mqnamesrv-a:/opt/logs
      - /disk/rocketmq/store/mqnamesrv-a:/opt/store
    networks:
      rmq:
        aliases:
          - mqnamesrv-a


  mqbroke-a:
    image: foxiswho/rocketmq:broker-4.6.1
      container_name: mqbroke-a
      restart: always
      ports:
        - 10911:10911
        - 10909:10909
        - 10912:10912
      command: sh mqbroker -c /home/rocketmq/rocketmq-4.6.1/conf/broker.conf autoCreateTopicEnable=true &
      environment:
        TZ: Asia/Shanghai
        JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m -XX:MaxDirectMemorySize=1g"
      volumes:
        - /disk/rocketmq/logs/broker-a:/opt/logs
        - /disk/rocketmq/store/broker-a:/opt/store
        - /disk/rocketmq/conf/broker-a/broker.conf:/home/rocketmq/rocketmq-4.6.1/conf/broker.conf
      depends_on:
        - mqnamesrv-a
      networks:
        rmq:
          aliases:
            - mqbroke-a


  mqbroke-s0:
    image: foxiswho/rocketmq:broker-4.6.1
      container_name: mqbroke-s0
      restart: always
      ports:
        - 10915:10911
        - 10913:10909
        - 10916:10912
      command: sh mqbroker -c /home/rocketmq/rocketmq-4.6.1/conf/broker.conf autoCreateTopicEnable=true &
      environment:
        TZ: Asia/Shanghai
        JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
      volumes:
        - /disk/rocketmq/logs/broker-s0:/opt/logs
        - /disk/rocketmq/store/broker-s0:/opt/store
        - /disk/rocketmq/conf/broker-s0/broker.conf:/home/rocketmq/rocketmq-4.6.1/conf/broker.conf
      networks:
        rmq:
          aliases:
            - mqbroke-s0

  rmqconsole:
    image: styletang/rocketmq-console-ng
    container_name: rmqconsole
    ports:
      -  9001:9001
      - 8080:8080
    environment:
      JAVA_OPTS: -Drocketmq.namesrv.addr=172.17.5.134:9876;172.17.5.135:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
    networks:
      rmq:
        aliases:
          - rmqconsole


networks:
  rmq:
    name: rmq
      driver: bridge

 

创建docker-compose 135

version: '3.7'
services:
  mqnamesrv-b:
    image: foxiswho/rocketmq:server-4.6.1
    container_name: mqnamesrv-b
    restart: always
    ports:
      - 9876:9876
    command: sh mqnamesrv
    volumes:
      - /disk/rocketmq/logs/mqnamesrv-b:/opt/logs
      - /disk/rocketmq/store/mqnamesrv-b:/opt/store
    networks:
      rmq:
        aliases:
          - mqnamesrv-b

  mqbroke-b:
    image: foxiswho/rocketmq:broker-4.6.1
    container_name: mqbroke-b
    restart: always
    ports:
      - 10911:10911
      - 10909:10909
      - 10912:10912
    command: ["sh","mqbroker","-c","/home/rocketmq/rocketmq-4.6.1/conf/broker.conf"]
    environment:
      TZ: Asia/Shanghai
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    volumes:
      - /disk/rocketmq/logs/broker-b:/opt/logs
      - /disk/rocketmq/store/broker-b:/opt/store
      - /disk/rocketmq/conf/broker-b/broker.conf:/home/rocketmq/rocketmq-4.6.1/conf/broker.conf
    networks:
      rmq:
        aliases:
          - mqbroke-b

  mqbroke-s1:
    image: foxiswho/rocketmq:broker-4.6.1
    container_name: mqbroke-s1
    restart: always
    ports:
      - 10915:10911
      - 10913:10909
      - 10916:10912
    command: sh mqbroker -c /home/rocketmq/rocketmq-4.6.1/conf/broker.conf autoCreateTopicEnable=true &
    environment:
      TZ: Asia/Shanghai
      JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    volumes:
      - /disk/rocketmq/logs/broker-s1:/opt/logs
      - /disk/rocketmq/store/broker-s1:/opt/store
      - /disk/rocketmq/conf/broker-s1/broker.conf:/home/rocketmq/rocketmq-4.6.1/conf/broker.conf
    networks:
      rmq:
        aliases:
          - mqbroke-s1

networks:
  rmq:
    name: rmq
      driver: bridge


启动rocketmq
docker-compose up -d

posted @ 2022-04-27 17:07  梦里前进  阅读(29)  评论(0编辑  收藏  举报