人的知识就好比一个圆圈,圆圈里面是已知的,圆圈外面是未知的。你知道得越多,圆圈也就越大,你不知道的也就越多。

0%

基于 Docker 搭建 RabbitMQ 集群

  1. 创建 network

    1
    docker network create --driver bridge --subnet 172.22.0.0/16 --gateway 172.22.0.1  op_net
  2. 创建 rabbitmq.yml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    version: '3.6'

    services:
    rabbitmq-1:
    image: rabbitmq:3-management
    restart: always
    hostname: rabbitmq-1
    container_name: rabbitmq-1
    ports:
    - 5672:5672
    - 15672:15672
    environment:
    RABBITMQ_NODENAME: rabbitmq-1
    RABBITMQ_ERLANG_COOKIE: secret-cookie
    networks:
    default:
    ipv4_address: 172.22.0.17
    rabbitmq-2:
    image: rabbitmq:3-management
    restart: always
    hostname: rabbitmq-2
    container_name: rabbitmq-2
    ports:
    - 5673:5672
    - 15673:15672
    environment:
    RABBITMQ_NODENAME: rabbitmq-2
    RABBITMQ_ERLANG_COOKIE: secret-cookie
    networks:
    default:
    ipv4_address: 172.22.0.18
    rabbitmq-3:
    image: rabbitmq:3-management
    restart: always
    hostname: rabbitmq-3
    container_name: rabbitmq-3
    ports:
    - 5674:5672
    - 15674:15672
    environment:
    RABBITMQ_NODENAME: rabbitmq-3
    RABBITMQ_ERLANG_COOKIE: secret-cookie
    networks:
    default:
    ipv4_address: 172.22.0.19

    networks:
    default:
    external:
    name: op_net
  3. 启动 RabbitMQ 集群

    1
    docker-compose -f rabbitmq.yml up -d
  4. 将 rabbitmq-2 添加到集群(RAM 类型)

    1
    2
    3
    4
    rabbitmqctl stop_app
    rabbitmqctl reset
    rabbitmqctl join_cluster --ram rabbitmq-1@rabbitmq-1
    rabbitmqctl start_app
  5. 将 rabbitmq-3 添加到集群

    1
    2
    3
    4
    rabbitmqctl stop_app
    rabbitmqctl reset
    rabbitmqctl join_cluster --ram rabbitmq-3@rabbitmq-3
    rabbitmqctl start_app

参考资料:

  1. docker-compose配置rabbitmq集群服务器
  2. 使用 docker-compose 安装搭建 RabbitMQ 集群
小礼物走一走,来 Github 关注我