想在本地搭建一个rabbitmq集群玩一下,翻了N片文章,总算搭建成功,把搭建过程梳理一下,遇到问题的同学可以参考一下:
一、首先,需要安装并启动docker,这个不做赘述;
二、拉取rabbitmq镜像,我是用的是3.7版本:
docker pull rabbitmq:3.7-management
三、创建network,这里我没用之前的--link,改用了network
docker network create rabbitmq-net
四、启动docker容器:
docker run -d --hostname rabbitmq01 --name rabbitmqCluster01 -v [用户目录]/rabbitmqcluster/rabbitmq01:/var/lib/rabbitmq -p 15672:15672 -p 5672:5672 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin --network rabbitmq-net rabbitmq:3.7-management
docker run -d --hostname rabbitmq02 --name rabbitmqCluster02 -v [用户目录]/rabbitmqcluster/rabbitmq02:/var/lib/rabbitmq -p 15673:15672 -p 5673:5672 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin --network rabbitmq-net rabbitmq:3.7-management
docker run -d --hostname rabbitmq03 --name rabbitmqCluster03 -v [用户目录]/rabbitmqcluster/rabbitmq03:/var/lib/rabbitmq -p 15674:15672 -p 5674:5672 -e RABBITMQ_ERLANG_COOKIE='rabbitcookie' -e RABBITMQ_DEFAULT_USER=admin -e RABBITMQ_DEFAULT_PASS=admin --network rabbitmq-net rabbitmq:3.7-management
这里需要说明几点:
1.?RABBITMQ_ERLANG_COOKIE的值要保持一致,不然后续node无法加入集群;
2.最好加入RABBITMQ_DEFAULT_USER、RABBITMQ_DEFAULT_PASS参数,后续可以直接登录web管理后台;
五、节点加入集群
节点rabbitmqCluster01
#docker exec -it rabbitmqCluster01 bash
#rabbitmqctl stop_app
#rabbitmqctl reset
#rabbitmqctl start_app
#exit
节点rabbitmqCluster02
#docker exec -it rabbitmqCluster02 bash
#rabbitmqctl stop_app
#rabbitmqctl reset
#rabbitmqctl join_cluster --ram rabbit@rabbitmq01
#rabbitmqctl start_app
#exit
这里说明几点:
1. join_cluster加入的集群使用的是节点rabbitmqCluster01的hostname: rabbitmq01
2.如果join_cluster报错,检查一下erlang cookie是否设置一直,路径在/var/lib/rabbitmq/.erlang.cookie;
节点rabbitmqCluster03
#docker exec -it rabbitmqCluster03 bash
#rabbitmqctl stop_app
#rabbitmqctl reset
#rabbitmqctl join_cluster --ram rabbit@rabbitmq01
#rabbitmqctl start_app
#exit
到目前,如果前面流程都顺利的话,集群基本上搭建完成,用命令确认一下:
root@rabbitmq01:/# rabbitmqctl cluster_status
Cluster status of node rabbit@rabbitmq01 ...
[{nodes,[{disc,[rabbit@rabbitmq01]},
{ram,[rabbit@rabbitmq03,rabbit@rabbitmq02]}]},
{running_nodes,[rabbit@rabbitmq03,rabbit@rabbitmq02,rabbit@rabbitmq01]},
{cluster_name,<<"rabbit@rabbitmq01">>},
{partitions,[]},
{alarms,[{rabbit@rabbitmq03,[]},
{rabbit@rabbitmq02,[]},
{rabbit@rabbitmq01,[]}]}]
nodes包含了所有的节点。
六、最后一步就是web管理后台,需要开启插件:
rabbitmq-plugins enable rabbitmq_management
检查一下是否开启成功:
root@rabbitmq01:/# rabbitmq-plugins list
Listing plugins with pattern ".*" ...
Configured: E = explicitly enabled; e = implicitly enabled
| Status: * = running on rabbit@rabbitmq01
|/
[ ] rabbitmq_amqp1_0 3.7.28
[ ] rabbitmq_auth_backend_cache 3.7.28
[ ] rabbitmq_auth_backend_http 3.7.28
[ ] rabbitmq_auth_backend_ldap 3.7.28
[ ] rabbitmq_auth_mechanism_ssl 3.7.28
[ ] rabbitmq_consistent_hash_exchange 3.7.28
[ ] rabbitmq_event_exchange 3.7.28
[ ] rabbitmq_federation 3.7.28
[ ] rabbitmq_federation_management 3.7.28
[ ] rabbitmq_jms_topic_exchange 3.7.28
[E*] rabbitmq_management 3.7.28
[e*] rabbitmq_management_agent 3.7.28
[ ] rabbitmq_mqtt 3.7.28
[ ] rabbitmq_peer_discovery_aws 3.7.28
[ ] rabbitmq_peer_discovery_common 3.7.28
[ ] rabbitmq_peer_discovery_consul 3.7.28
[ ] rabbitmq_peer_discovery_etcd 3.7.28
[ ] rabbitmq_peer_discovery_k8s 3.7.28
[ ] rabbitmq_random_exchange 3.7.28
[ ] rabbitmq_recent_history_exchange 3.7.28
[ ] rabbitmq_sharding 3.7.28
[ ] rabbitmq_shovel 3.7.28
[ ] rabbitmq_shovel_management 3.7.28
[ ] rabbitmq_stomp 3.7.28
[ ] rabbitmq_top 3.7.28
[ ] rabbitmq_tracing 3.7.28
[ ] rabbitmq_trust_store 3.7.28
[e*] rabbitmq_web_dispatch 3.7.28
[ ] rabbitmq_web_mqtt 3.7.28
[ ] rabbitmq_web_mqtt_examples 3.7.28
[ ] rabbitmq_web_stomp 3.7.28
[ ] rabbitmq_web_stomp_examples 3.7.28
查看一下端口号:
? rabbitmqcluster docker port rabbitmqCluster01
5672/tcp -> 0.0.0.0:5672
5672/tcp -> :::5672
15672/tcp -> 0.0.0.0:15672
15672/tcp -> :::15672
通过http://127.0.0.1:15672/即可访问管理后台
参考文章:
https://www.cnblogs.com/alan6/p/11691229.html
|