1.下载rabbitmq镜像
docker run -d --hostname rabbit1 --name myrabbit1 -p 15672:15672 -p 5672:5672 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.7
docker run -d --hostname rabbit2 --name myrabbit2 -p 5673:5672 --link myrabbit1:rabbit1 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.7
docker run -d --hostname rabbit3 --name myrabbit3 -p 5674:5672 --link myrabbit1:rabbit1 --link myrabbit2:rabbit2 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' rabbitmq:3.7
2.配置集群
设置节点一
docker exec -it myrabbit1 bash
root@rabbit1:/# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbit1
root@rabbit1:/# rabbitmqctl reset
Resetting node rabbit@rabbit1
root@rabbit1:/# rabbitmqctl start_app
Starting node rabbit@rabbit1
设置节点2,加入到集群:
[root@node03 ~]# docker exec -it myrabbit2 bash
root@rabbit2:/# rabbitmqctl stop_app
Stopping rabbit application on node rabbit@rabbit2
root@rabbit2:/# rabbitmqctl reset
Resetting node rabbit@rabbit2
root@rabbit2:/# rabbitmqctl join_cluster --ram rabbit@rabbit1
Clustering node rabbit@rabbit2 with rabbit@rabbit1
root@rabbit2:/# rabbitmqctl start_app
Starting node rabbit@rabbit2
root@rabbit2:/# exit
参数"--ram"表示设置为内存节点,忽略次参数默认为磁盘节点。
设置节点3,加入到集群:
docker exec -it myrabbit3 bash
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbit1
rabbitmqctl start_app
exit
3.测试搭建结果
http://192.168.123.105:15672/#/
4.配置相同Erlang Cookie
查找Erlang Cookie的位置
docker logs myrabbit3
=INFO REPORT==== 7-Mar-2019::08:25:04 ===
node : rabbit@rabbit3
home dir : /var/lib/rabbitmq ##这个目录下面
root@rabbit3:/# cat /var/lib/rabbitmq/.erlang.cookie
rabbitcookie
复制容器里的文件到本地
docker cp myrabbit2:/var/lib/rabbitmq/.erlang.cookie .
- 我的微信
- 这是我的微信扫一扫
- 我的微信公众号
- 我的微信公众号扫一扫