环境
主机名 | IP |
---|---|
rabbit1 | 192.168.1.160 |
rabbit2 | 192.168.1.162 |
rabbit3 | 192.168.1.166 |
部署节点一
vim docker-compose.yml
代码语言:javascript复制version: '3'
services:
rabbit1:
image: rabbitmq:3.3.8.5-management
container_name: rabbit1
hostname: rabbit1
ports:
- 4369:4369
- 5672:5672
- 15672:15672
- 15674:15674
- 25672:25672
- 35197:35197
volumes:
- /data/rabbitmq:/var/lib/rabbitmq
- /etc/localtime:/etc/localtime
environment:
- RABBITMQ_DEFAULT_USER=admin
- RABBITMQ_DEFAULT_PASS=123456
- RABBITMQ_ERLANG_COOKIE='SECERLANGCOOKIE'
extra_hosts:
- "rabbit2:192.168.1.162" # 不能加入自己,否则会一直重启
- "rabbit3:192.168.1.166"
- 启动:docker-compose up -d
部署节点二
vim docker-compose.yml
代码语言:javascript复制version: '3'
services:
rabbit2:
image: rabbitmq:3.3.8.5-management
container_name: rabbit2
hostname: rabbit2
ports:
- 4369:4369
- 5672:5672
- 15672:15672
- 15674:15674
- 25672:25672
- 35197:35197
volumes:
- /data/rabbitmq:/var/lib/rabbitmq
- /etc/localtime:/etc/localtime
environment:
- RABBITMQ_ERLANG_COOKIE='SECERLANGCOOKIE'
- RABBITMQ_DEFAULT_VHOST=/
- RABBITMQ_LOGS=/var/lib/rabbitmq/rabbitmq.log
extra_hosts:
- "rabbit1:192.168.1.160"
- "rabbit3:192.168.1.166"
- 启动:docker-compose up -d
部署节点三
vim docker-compose.yml
代码语言:javascript复制version: '3'
services:
rabbit3:
image: rabbitmq:3.3.8.5-management
container_name: rabbit3
hostname: rabbit3
ports:
- 4369:4369
- 5672:5672
- 15672:15672
- 15674:15674
- 25672:25672
- 35197:35197
volumes:
- /data/rabbitmq:/var/lib/rabbitmq
- /etc/localtime:/etc/localtime
environment:
- RABBITMQ_ERLANG_COOKIE='SECERLANGCOOKIE'
- RABBITMQ_DEFAULT_VHOST=/
- RABBITMQ_LOGS=/var/lib/rabbitmq/rabbitmq.log
extra_hosts:
- "rabbit1:192.168.1.160"
- "rabbit2:192.168.1.162"
- 启动:docker-compose up -d
把节点二和节点三加入到集群
代码语言:javascript复制docker exec -it rabbit2 bash
rabbitmqctl stop_app
rabbitmqctl join_cluster rabbit@rabbit1
rabbitmqctl start_app