docker-compose部署生产环境EMQX集群(六节点)

版本

名称 版本号
CentOS 7.9
Docker-Compose 2.21.0
Emqx 3.5

Docker-Compose脚本

version: '3'
 
services:
  emqx1:
    image: emqx:5.3.0
    container_name: emqx1
    environment:
    - "EMQX_NODE_NAME=emqx@node1.emqx.gx.hengtong"
    - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
    - "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.gx.hengtong,emqx@node2.emqx.gx.hengtong]"
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5
    networks:
      emqx-bridge:
        aliases:
        - node1.emqx.gx.hengtong
    ports:
      - 1883:1883
      - 8083:8083
      - 8084:8084
      - 8883:8883
      - 18083:18083 
    volumes:
      - emqx1Volume:/opt/emqx/data
  emqx2:
    image: emqx:5.3.0
    container_name: emqx2
    environment:
    - "EMQX_NODE_NAME=emqx@node2.emqx.gx.hengtong"
    - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
    - "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.gx.hengtong,emqx@node2.emqx.gx.hengtong,emqx@node3.emqx.gx.hengtong,emqx@node4.emqx.gx.hengtong,emqx@node5.emqx.gx.hengtong,emqx@node6.emqx.gx.hengtong]" 
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5
    networks:
      emqx-bridge:
        aliases:
        - node2.emqx.gx.hengtong
    volumes:
       - emqx2Volume:/opt/emqx/data
  emqx3:
    image: emqx:5.3.0
    container_name: emqx3
    environment:
    - "EMQX_NODE_NAME=emqx@node3.emqx.gx.hengtong"
    - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
    - "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.gx.hengtong,emqx@node2.emqx.gx.hengtong,emqx@node3.emqx.gx.hengtong,emqx@node4.emqx.gx.hengtong,emqx@node5.emqx.gx.hengtong,emqx@node6.emqx.gx.hengtong]"
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5
    networks:
      emqx-bridge:
        aliases:
        - node3.emqx.gx.hengtong
    volumes:
       - emqx3Volume:/opt/emqx/data
  emqx4:
    image: emqx:5.3.0
    container_name: emqx4
    environment:
    - "EMQX_NODE_NAME=emqx@node4.emqx.gx.hengtong"
    - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
    - "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.gx.hengtong,emqx@node2.emqx.gx.hengtong,emqx@node3.emqx.gx.hengtong,emqx@node4.emqx.gx.hengtong,emqx@node5.emqx.gx.hengtong,emqx@node6.emqx.gx.hengtong]"
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5
    networks:
      emqx-bridge:
        aliases:
        - node4.emqx.gx.hengtong
    volumes:
       - emqx4Volume:/opt/emqx/data
  emqx5:
    image: emqx:5.3.0
    container_name: emqx5
    environment:
    - "EMQX_NODE_NAME=emqx@node5.emqx.gx.hengtong"
    - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
    - "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.gx.hengtong,emqx@node2.emqx.gx.hengtong,emqx@node3.emqx.gx.hengtong,emqx@node4.emqx.gx.hengtong,emqx@node5.emqx.gx.hengtong,emqx@node6.emqx.gx.hengtong]"
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5
    networks:
      emqx-bridge:
        aliases:
        - node5.emqx.gx.hengtong
    volumes:
       - emqx5Volume:/opt/emqx/data
  emqx6:
    image: emqx:5.3.0
    container_name: emqx6
    environment:
    - "EMQX_NODE_NAME=emqx@node6.emqx.gx.hengtong"
    - "EMQX_CLUSTER__DISCOVERY_STRATEGY=static"
    - "EMQX_CLUSTER__STATIC__SEEDS=[emqx@node1.emqx.gx.hengtong,emqx@node2.emqx.gx.hengtong,emqx@node3.emqx.gx.hengtong,emqx@node4.emqx.gx.hengtong,emqx@node5.emqx.gx.hengtong,emqx@node6.emqx.gx.hengtong]"
    healthcheck:
      test: ["CMD", "/opt/emqx/bin/emqx_ctl", "status"]
      interval: 5s
      timeout: 25s
      retries: 5
    networks:
      emqx-bridge:
        aliases:
        - node6.emqx.gx.hengtong
    volumes:
       - emqx6Volume:/opt/emqx/data
 
networks:
  emqx-bridge:
    driver: bridge

volumes:
  emqx1Volume:
    name: emqx1_data
  emqx2Volume:
    name: emqx2_data
  emqx3Volume:
    name: emqx3_data
  emqx4Volume:
    name: emqx4_data
  emqx5Volume:
    name: emqx5_data
  emqx6Volume:
    name: emqx6_data

启动脚本

docker-compose -f 文件名.yml up -d

查看集群状态

docker exec -it emqx1 sh -c "emqx ctl cluster status"

查看emqx dashboard

http://serverIp:18083/#/dashboard/overview

结果展示