RabbitMQ普通集群同一宿主机docker搭建
1.准备3个节点安装rabbitmq,搭建集群(注意:每个节点启动间隔15~20s,如果启动失败,需删除宿主机文件重新启动)
2.宿主机文件目录手动创建,并设置可操作权限
- 准备宿主机文件目录
cd /usr/local/
- 创建rabbitmq映射目录
mkdir rabbitmq
cd rabbitmq
mkdir 1
mkdir 2
mkdir 3
cd 1
mkdir lib
mkdir log
chmod 777 lib
chmod 777 log
注意:1.2.3个节点文件目录一致
3.rabbitmq安装命令 - 获取rabbitmq镜像
docker pull rabbitmq:management
- 节点1安装命令(主节点,创建-v映射目录)
docker run -d --hostname rabbitmq_host1 --name rabbitmq1 -p 15672:15672 -p 5672:5672 -e RABBITMQ_NODENAME=rabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=xxx333.78 -e RABBITMQ_ERLANG_COOKIE='rabbitmq_cookie' --privileged=true -v /usr/local/rabbitmq/1/lib:/var/lib/rabbitmq -v /usr/local/rabbitmq/1/log:/var/log/rabbitmq rabbitmq:management
- 节点2安装命令(创建-v映射目录)
docker run -d --hostname rabbitmq_host2 --name rabbitmq2 -p 15673:15672 -p 5673:5672 --link rabbitmq1:rabbitmq_host1 -e RABBITMQ_NODENAME=rabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=xxx333.78 -e RABBITMQ_ERLANG_COOKIE='rabbitmq_cookie' --privileged=true -v /usr/local/rabbitmq/2/lib:/var/lib/rabbitmq -v /usr/local/rabbitmq/2/log:/var/log/rabbitmq rabbitmq:management
- 节点3安装命令(-v映射目录)
docker run -d --hostname rabbitmq_host3 --name rabbitmq3 -p 15674:15672 -p 5674:5672 --link rabbitmq1:rabbitmq_host1 --link rabbitmq2:rabbitmq_host2 -e RABBITMQ_NODENAME=rabbit -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=xxx333.78 -e RABBITMQ_ERLANG_COOKIE='rabbitmq_cookie' --privileged=true -v /usr/local/rabbitmq/3/lib:/var/lib/rabbitmq -v /usr/local/rabbitmq/3/log:/var/log/rabbitmq rabbitmq:management
4.3个节点启动完毕,配置集群 - 节点1(主节点配置集群)
docker exec -it rabbitmq1 bash
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl start_app
exit
- 节点2加入集群(--ram以内存方式加入,默认为磁盘节点)
docker exec -it rabbitmq2 bash
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbitmq_host1
rabbitmqctl start_app
exit
- 节点3加入集群(--ram以内存方式加入,默认为磁盘节点)
docker exec -it rabbitmq3 bash
rabbitmqctl stop_app
rabbitmqctl reset
rabbitmqctl join_cluster --ram rabbit@rabbitmq_host1
rabbitmqctl start_app
exit
5.打开web端http:ip:端口号/15672,主节点上创建队列,进行测试
posted on 2024-08-13 10:04 走马川行奉送出师西征 阅读(32) 评论(0) 编辑 收藏 举报