docker-compose 搭建rabbitmq镜像集群

centos安装:略

docker安装:

yum -y install docker

docker-compose 安装:

https://blog.csdn.net/weixin_40165163/article/details/94351035

docker-compose.yaml:

version: '3.1'

services:
  rabbit1:
    image: bijukunjummen/rabbitmq-server:3.7.0
    hostname: rabbit1
    ports:
      - "5672:5672"
      - "15672:15672"
    environment:
      - RABBITMQ_DEFAULT_USER=myrabbitmq
      - RABBITMQ_DEFAULT_PASS=myrabbitmq

  rabbit2:
    image: bijukunjummen/rabbitmq-server:3.7.0
    hostname: rabbit2
    links:
       - rabbit1
    environment:
       - CLUSTERED=true
       - CLUSTER_WITH=rabbit1
       - RAM_NODE=true
    ports:
        - "5673:5672"
        - "15673:15672"

  rabbit3:
    image: bijukunjummen/rabbitmq-server:3.7.0
    hostname: rabbit3
    links:
        - rabbit1
        - rabbit2
    environment:
        - CLUSTERED=true
        - CLUSTER_WITH=rabbit1
    ports:
        - "5674:5672"


运行容器:

docker-compose up -d  

docker ps

镜像集群设置:

登录rabbitmq管理界面:

docker-compose 搭建rabbitmq镜像集群_第1张图片

或者命令:

策略名称为ha-allqueue,策略模式为 all 即复制到所有节点,包含新增节点,策略正则表达式为 “^” 表示所有匹配所有队列名称。

rabbitmqctl set_policy -p ha-allqueue"^" '{"ha-mode":"all"}'

添加一个queue 如上图所示即成功 

你可能感兴趣的:(docker)