docker swarm集群部署rabbit-mq

4 篇文章 0 订阅
1 篇文章 0 订阅
本文详细介绍了如何使用Docker Compose部署RabbitMQ集群,包括配置文件`rabbitmq.conf`设置默认用户和权限,以及`init.d`中的主节点和从节点初始化脚本。在`stack-compose`中定义了三个节点的集群服务,分别指定了宿主机名称、角色和网络约束,并加载了配置文件和初始化脚本。通过此部署,实现了RabbitMQ高可用集群的搭建。
摘要由CSDN通过智能技术生成

准备资料

1、rabbitmq.conf
2、init.d

1、rabbitmq.conf
default_vhost = /
default_user = admin
default_pass = admin
default_user_tags.administrator = true
default_permissions.configure = .*
default_permissions.read = .*
default_permissions.write = .*
2、init.d
1、master init
#!/bin/bash

chmod 777 /var/lib/rabbitmq/.erlang.cookie
cat /dev/null  > /var/lib/rabbitmq/.erlang.cookie
echo 'BDZXNSTIEMBUKJIQZRCX' >> /var/lib/rabbitmq/.erlang.cookie
chmod 400 /var/lib/rabbitmq/.erlang.cookie

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app

rabbitmqctl add_user admin admin
rabbitmqctl set_user_tags admin administrator

1、slave init
#!/bin/bash

chmod 777 /var/lib/rabbitmq/.erlang.cookie
cat /dev/null  > /var/lib/rabbitmq/.erlang.cookie
echo 'BDZXNSTIEMBUKJIQZRCX' >> /var/lib/rabbitmq/.erlang.cookie
chmod 400 /var/lib/rabbitmq/.erlang.cookie

rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@rabbitmq-n1
rabbitmqctl join_cluster --ram rabbit@rabbitmq-n1
rabbitmqctl start_app

rabbitmqctl add_user admin admin
rabbitmqctl set_user_tags admin administrator

#  BDZXNSTIEMBUKJIQZRCX

准备stack-compose

version: '3.7'

services:
  rabbitmq-n1:
    image: rabbitmq:3.8-management
    hostname: rabbitmq-n1
    ports:
      - 5672:5672
      - 15672:15672
      - 4369:4369
      - 25672:25672
    volumes:
      - ./data/rabbitmq-n1/data:/var/lib/rabbitmq
      - ./init.d/master:/docker-entrypoint-initdb.d
      - ./config/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
    privileged: true
    restart: always
    user: root
    networks:
      - test-overlay
    deploy:
      update_config:
        parallelism: 2
        delay: 5s
      restart_policy:
        condition: on-failure
      placement:
        constraints:
          - node.hostname == n1
          - node.role == manager
  rabbitmq-n2:
      image: rabbitmq:3.8-management
      hostname: rabbitmq-n2
      volumes:
        - ./data/rabbitmq-n2/data:/var/lib/rabbitmq
        - ./init.d/slave:/docker-entrypoint-initdb.d
        - ./config/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
      privileged: true
      user: root
      restart: always
      networks:
        - test-overlay
      deploy:
        placement:
          constraints:
            - node.hostname == n2
            - node.role == worker
  rabbitmq-n3:
    image: rabbitmq:3.8-management
    hostname: rabbitmq-n3
    volumes:
      - ./data/rabbitmq-n3/data:/var/lib/rabbitmq
      - ./init.d/slave:/docker-entrypoint-initdb.d
      - ./config/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
    privileged: true
    user: root
    restart: always
    networks:
      - test-overlay
    deploy:
      placement:
        constraints:
          - node.hostname == n3
          - node.role == worker


networks:
  test-overlay:
    driver: overlay
    #false-统自动创建网桥名,格式为: 目录名_网桥名,默认为false; true-使用外部创建的网桥,需需要自己手动创建
    external: true


node.hostname 代表宿主机的名称
node.role 代表节点的权限

启动 docker stack deploy --with-registry-auth -c stack-compose.yml rabbit-mq

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值