创建 network
1
docker network create --driver bridge --subnet 172.22.0.0/16 --gateway 172.22.0.1 op_net
创建 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
50version: '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启动 RabbitMQ 集群
1
docker-compose -f rabbitmq.yml up -d
将 rabbitmq-2 添加到集群(RAM 类型)
1
2
3
4rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbitmq-1@rabbitmq-1
rabbitmqctl start_app将 rabbitmq-3 添加到集群
1
2
3
4rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbitmq-3@rabbitmq-3
rabbitmqctl start_app
参考资料: