准备资料
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