docker 部署 rabbitmq 集群
单机部署
docker run -id -p 15672:15672 -p 56732:5672 \ --name rabbitmq \ --restart always \ -v /docker/rabbitmq:/var/lib/rabbitmq \ -e RABBITMQ_DEFAULT_USER=admin \ -e RABBITMQ_DEFAULT_PASS=****** \ rabbitmq:3.12.0-management
集群部署
#node01 docker run -id -p 15673:15672 -p 5673:5672 \ --name rabbitmqNode01 \ --hostname=node01 \ --restart always \ -v /docker/rabbitmqCluster/rabbitmq01:/var/lib/rabbitmq \ -e RABBITMQ_DEFAULT_USER=admin \ -e RABBITMQ_DEFAULT_PASS=****** \ rabbitmq:3.12.0-management # 把rabbitmqNode01容器中的/var/lib/rabbitmq/.erlang.cookie复制到宿主机中储存 # 集群.erlang.cookie需要一致 #node02 docker run -id -p 15674:15672 -p 5674:5672 \ --name rabbitmqNode02 \ --hostname=node02 \ --restart always \ --link rabbitmqNode01:node01 \ -v /xfgit/docker/rabbitmqCluster/rabbitmq02:/var/lib/rabbitmq \ -e RABBITMQ_DEFAULT_USER=admin \ -e RABBITMQ_DEFAULT_PASS=****** \ rabbitmq:3.12.0-management #node03 docker run -id -p 15675:15672 -p 5675:5672 \ --name rabbitmqNode03 \ --hostname=node03 \ --restart always \ --link rabbitmqNode01:node01 \ --link rabbitmqNode02:node02 \ -v /docker/rabbitmqCluster/rabbitmq03:/var/lib/rabbitmq \ -e RABBITMQ_DEFAULT_USER=admin \ -e RABBITMQ_DEFAULT_PASS=****** \ rabbitmq:3.12.0-management
集群设置
# 进入第一个rabbitmq节点容器 docker exec -it rabbitmqNode01 /bin/bash # rabbitmqctl stop 会将 Erlang 虚拟机关闭,rabbitmqctl stop_app只关闭RabbitMQ 服务 rabbitmqctl stop_app # 重置节点,将 RabbitMQ 节点返回到其原始状态。 rabbitmqctl reset # 只启动应用服务 rabbitmqctl start_app # 退出容器 exit # 进入第二个rabbitmq节点容器 docker exec -it rabbitmqNode02 /bin/bash rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl join_cluster rabbit@node01 rabbitmqctl start_app exit # 进入第三个rabbitmq节点容器 docker exec -it rabbitmqNode03 /bin/bash rabbitmqctl stop_app rabbitmqctl reset rabbitmqctl join_cluster rabbit@node01 rabbitmqctl start_app exit
3.查看集群状态
# 进入任一节点容器
docker exec -it rabbitmqNode01 /bin/bash
命令查看
rabbitmqctl cluster_status
4.访问以下任意一个登录查看
http://host-ip:15673
http://host-ip:15674
http://host-ip:15675