搭建RabbitMQ集群

创建RabbitMQ集群网络

docker network create rabbitnet

创建rabbit1节点

docker run -itd --name rabbit1 --hostname rabbit1 -e RABBITMQ_ERLANG_COOKIE='rabbitmqCookie' --network rabbitnet --network-alias rabbit1 rabbitmq:management

创建rabbit2节点

docker run -itd --name rabbit2 --hostname rabbit2 -e RABBITMQ_ERLANG_COOKIE='rabbitmqCookie' --network rabbitnet --network-alias rabbit2 -p 15672:15672 rabbitmq:management

需要注意,环境变量RABBITMQ_ERLANG_COOKIE需要一样

--hostname--network-alias需要一样,因为加入集群使用的是主机名,所以这里把主机名当作网络别名

docker exec -it rabbit2 /bin/bash
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app

rabbit1加入到rabbit2节点中

docker exec -it rabbit1 /bin/bash
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster rabbit@'rabbit2'
rabbitmqctl start_app

rabbitmqctl join_cluster rabbit@'rabbit2',rabbit2是主机名,--hostname指定的

image.png

# RabbitMQ 

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×