RabbitMQ自动聚类|Docker Swarm

e7arh2l6  于 2023-06-23  发布在  RabbitMQ
关注(0)|答案(1)|浏览(121)

我想在docker swarm中创建一个rabbitmq集群。我已经阅读了文档,我想我已经尝试了所有方法,但自动集群对我不起作用:将只创建独立节点。
你可以在下面看到我的docker-compose v3文件:

version: "3.9"

services:
  rabbitmq-01:
    image: bitnami/rabbitmq:3.11
    #user: "1001"
    hostname: rabbitmq-01
    healthcheck:
      test: ["CMD", "rabbitmq-diagnostics", "check_running"]
      interval: 60s
      timeout: 10s
      retries: 3
    environment:
      - RABBITMQ_USERNAME=admin
      - RABBITMQ_PASSWORD=admin
      - RABBITMQ_FORCE_BOOT=true
      - RABBITMQ_ERL_COOKIE=$ecure$string
      - RABBITMQ_NODE_NAME=rabbit@rabbitmq-01
      - RABBITMQ_VM_MEMORY_HIGH_WATERMARK=300M
      - RABBITMQ_DISK_FREE_ABSOLUTE_LIMIT=500M
    configs:
      - source: rabbitmq-01
        target: /bitnami/rabbitmq/conf/custom.conf
        uid: "1001"
        gid: "1001"
        mode: 0644
    ports:
      - target: 15672
        published: 15672
        protocol: tcp
        mode: host
    networks:
      - rabbitmq
    volumes:
      - rabbitmq-01-data:/bitnami/rabbitmq/mnesia
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 300M
        reservations:
          cpus: '0.25'
          memory: 150M
      restart_policy:
        condition: any
        delay: 30s
        max_attempts: 3
        window: 120s
      placement:
        constraints: [node.labels.rabbitmq == 01]

  rabbitmq-02:
    image: bitnami/rabbitmq:3.11
    #user: "1001"
    hostname: rabbitmq-02
    healthcheck:
      test: ["CMD", "rabbitmq-diagnostics", "check_running"]
      interval: 60s
      timeout: 10s
      retries: 3
    environment:
      - RABBITMQ_USERNAME=admin
      - RABBITMQ_PASSWORD=admin
      - RABBITMQ_FORCE_BOOT=true
      - RABBITMQ_ERL_COOKIE=$ecure$string
      - RABBITMQ_NODE_NAME=rabbit@rabbitmq-02
      - RABBITMQ_CLUSTER_NODE_NAME=rabbit@rabbitmq-02
      - RABBITMQ_VM_MEMORY_HIGH_WATERMARK=300M
      - RABBITMQ_DISK_FREE_ABSOLUTE_LIMIT=500M
    configs:
      - source: rabbitmq-02
        target: /bitnami/rabbitmq/conf/custom.conf
        uid: "1001"
        gid: "1001"
        mode: 0644
    ports:
      - target: 15672
        published: 15672
        protocol: tcp
        mode: host
    networks:
      - rabbitmq
    volumes:
      - rabbitmq-02-data:/bitnami/rabbitmq/mnesia
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 300M
        reservations:
          cpus: '0.25'
          memory: 150M
      restart_policy:
        condition: any
        delay: 30s
        max_attempts: 3
        window: 120s
      placement:
        constraints: [node.labels.rabbitmq == 02]

  rabbitmq-03:
    image: bitnami/rabbitmq:3.11
    #user: "1001"
    hostname: rabbitmq-03
    healthcheck:
      test: ["CMD", "rabbitmq-diagnostics", "check_running"]
      interval: 60s
      timeout: 10s
      retries: 3
    environment:
      - RABBITMQ_USERNAME=admin
      - RABBITMQ_PASSWORD=admin
      - RABBITMQ_FORCE_BOOT=true
      - RABBITMQ_ERL_COOKIE=$ecure$string
      - RABBITMQ_NODE_NAME=rabbit@rabbitmq-03
      - RABBITMQ_CLUSTER_NODE_NAME=rabbit@rabbitmq-02
      - RABBITMQ_VM_MEMORY_HIGH_WATERMARK=300M
      - RABBITMQ_DISK_FREE_ABSOLUTE_LIMIT=500M
    configs:
      - source: rabbitmq-03
        target: /bitnami/rabbitmq/conf/custom.conf
        uid: "1001"
        gid: "1001"
        mode: 0644
    ports:
      - target: 15672
        published: 15672
        protocol: tcp
        mode: host
    networks:
      - rabbitmq
    volumes:
      - rabbitmq-03-data:/bitnami/rabbitmq/mnesia
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 300M
        reservations:
          cpus: '0.25'
          memory: 150M
      restart_policy:
        condition: any
        delay: 30s
        max_attempts: 3
        window: 120s
      placement:
        constraints: [node.labels.rabbitmq == 03]

networks:
  rabbitmq:
configs:
  rabbitmq-01:
    file: config/rabbitmq/rabbitmq-01.conf
  rabbitmq-02:
    file: config/rabbitmq/rabbitmq-02.conf
  rabbitmq-03:
    file: config/rabbitmq/rabbitmq-03.conf
volumes:
  rabbitmq-01-data:
  rabbitmq-02-data:
  rabbitmq-03-data:

rabbitmq配置:

listeners.tcp.default = 5672
loopback_users.guest = false
cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config
cluster_formation.classic_config.nodes.1 = rabbit@rabbitmq-01
cluster_formation.classic_config.nodes.2 = rabbit@rabbitmq-02
cluster_formation.classic_config.nodes.3 = rabbit@rabbitmq-03
# Don't remove cluster members unknown to the peer discovery backend but log
# warnings.
#
# This setting can only be used if a compatible peer discovery plugin is enabled.
cluster_formation.node_cleanup.only_log_warning = true
# perform the check every 90 seconds
cluster_formation.node_cleanup.interval = 90
# Retry peer discovery operations up to ten times
cluster_formation.discovery_retry_limit = 10
# 500 milliseconds
cluster_formation.discovery_retry_interval = 5000

我已经尝试了我能想象到的所有可能的配置组合:

  • 在每个容器下附加相同的rabbitmq.conf文件
  • 将不同的配置文件附加到每个容器。
  • 将不同的配置文件附加到包含不同配置的每个容器
listeners.tcp.default = 5672
loopback_users.guest = false
cluster_formation.peer_discovery_backend = classic_config
cluster_formation.classic_config.nodes.1 = rabbit@rabbitmq-01
#cluster_formation.classic_config.nodes.2 = rabbit@rabbitmq-02
#cluster_formation.classic_config.nodes.3 = rabbit@rabbitmq-03
# Don't remove cluster members unknown to the peer discovery backend but log
# warnings.
#
# This setting can only be used if a compatible peer discovery plugin is enabled.
cluster_formation.node_cleanup.only_log_warning = true
# perform the check every 90 seconds
cluster_formation.node_cleanup.interval = 90
# Retry peer discovery operations up to ten times
cluster_formation.discovery_retry_limit = 10
# 500 milliseconds
cluster_formation.discovery_retry_interval = 5000
  • 未附加配置文件并尝试使用bitnami env变量设置集群:RABBITMQ_CLUSTER_节点名称
  • 所有之前的场景除了rabbitmq官方形象。。

我删除了每个退休区之间的所有底层存储,以防止rabbitmq被以前的配置混淆。在rabbitmq的官方镜像中,日志中有一些条目告诉我,系统正在尝试进行对等点发现,但这些进程总是超时,无论重试之间增加了多大的阈值……Bitnami容器不会记录这样的东西,但配置已经读取,因为如果我执行到容器,我可以在日志中看到使用过的配置,如果我“cat”它,那里有我的值...
这些成功…当然,如果stack deploy成功创建了独立节点(不管附加的配置如何,每次创建独立节点时都只创建),我可以执行到容器中并使用rabbitmqcli命令设置集群。
自动集群应该如何工作?
感谢您的评分

rhfm7lfc

rhfm7lfc1#

什么样的网络rabbitmq?尝试创建网络:

docker network create -d overlay --opt encrypted name_network

相关问题