- 搭建集群
mkdir /software/docker/rabbitmq
cd /software/docker/rabbitmq
mkdir rabbitmq01 rabbitmq02 rabbitmq03
docker run --hostname rabbitmq01 --name rabbitmq01 -v /software/docker/rabbitmq/rabbitmq01:/var/lib/rabbitmq -p 15673:15672 -p 5673:5672 -e RABBITMQ_ERLANG_COOKIE='yzk' -d rabbitmq:3.12-management
docker run --hostname rabbitmq02 --name rabbitmq02 -v /software/docker/rabbitmq/rabbitmq02:/var/lib/rabbitmq -p 15674:15672 -p 5674:5672 -e RABBITMQ_ERLANG_COOKIE='yzk' --link rabbitmq01:rabbitmq01 -d rabbitmq:3.12-management
docker run --hostname rabbitmq03 --name rabbitmq03 -v /software/docker/rabbitmq/rabbitmq03:/var/lib/rabbitmq -p 15675:15672 -p 5675:5672 -e RABBITMQ_ERLANG_COOKIE='yzk' --link rabbitmq01:rabbitmq01 --link rabbitmq02:rabbitmq02 -d rabbitmq:3.12-management
- 节点加入集群
#第一个节点
docker exec -it rabbitmq01 bash
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
exit
#第二个节点
docker exec -it rabbitmq02 bash
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbitmq01
rabbitmqctl start_app
exit
#第三个节点
docker exec -it rabbitmq03 bash
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbitmq01
rabbitmqctl start_app
exit
- 实现镜像集群
docker exec -it rabbitmq01 bash
rabbitmqctl set_policy -p / ha "^" '{"ha-mode":"all","ha-sync-mode":"automatic"}'
// 查看vhost下面的所有policy
rabbitmqctl list_policies -p /