赞
踩
docker pull rabbitmq
docker run -d --name rabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 -p 25672:25672 -p 61613:61613 -p 1883:1883 rabbitmq
docker network create mq-net
注意:3.8以上的mq不需要设置镜像策略;直接用Quorum类型队列代替
docker exec -it rabbit cat /var/lib/rabbitmq/.erlang.cookie
- cd /home/mxy
- # 创建cookie文件
- touch .erlang.cookie
- # 写入cookie
- echo "GIIKNSACLCUKKXCZEHQD" > .erlang.cookie
- # 修改cookie文件的权限
- chmod 600 .erlang.cookie
docker rm -f rabbit
- cd /home/mxy
- # 创建文件
- touch rabbitmq.conf
- loopback_users.guest = false #禁用默认账号
- listeners.tcp.default = 5672 #监听对外通信端口配置
- cluster_formation.peer_discovery_backend = rabbit_peer_discovery_classic_config #集群节点发现配置
- cluster_formation.classic_config.nodes.1 = rabbit@rabbitmq1 #集群节点1
- cluster_formation.classic_config.nodes.2 = rabbit@rabbitmq2 #集群节点2 多个节点就多加几行配置
docker run -d --name rabbitmq1 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 -p 4369:4369 -p 25672:25672 -v mq-plugins:/plugins --net mq-net --hostname rabbitmq1 -v /home/mxy/rabbitmq.conf:/etc/rabbitmq.conf -v /home/mxy/.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie --add-host rabbitmq2:服务2的ip --restart unless-stopped rabbitmq
docker run -d --name rabbitmq2 -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin -p 15672:15672 -p 5672:5672 -p 4369:4369 -p 25672:25672 -v mq-plugins:/plugins --net mq-net --hostname rabbitmq2 -v /home/mxy/rabbitmq.conf:/etc/rabbitmq.conf -v /home/mxy/.erlang.cookie:/var/lib/rabbitmq/.erlang.cookie --add-host rabbitmq1:服务1的ip --restart unless-stopped rabbitmq
docker exec -it 容器id /bin/bash
rabbitmq-plugins enable rabbitmq_management
- docker exec -it rabbitmq2 /bin/bash
- rabbitmqctl stop_app
- rabbitmqctl reset
- rabbitmqctl join_cluster --ram rabbit@rabbitmq1
- rabbitmqctl start_app
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。