我正在尝试学习集群 rabbitmq 节点并且我正在关注 this tutorial以及the official documentation .
我有 2 台物理机,通过 docker 在它们上面部署了 rabbitmq。 machine1 ( 192.168.1.2 ) 将成为集群,machine2 ( 192.168.1.3 ) 将加入集群。
当我尝试从 machine2 运行 rabbitmqctl join_cluster rabbit@192.168.1.2
时,失败并显示以下消息。
Clustering node rabbit@node2.rabbit with rabbit@192.168.1.2
Error: unable to perform an operation on node 'rabbit@192.168.1.2'. Please see diagnostics information and suggestions below.
Most common reasons for this are:
* Target node is unreachable (e.g. due to hostname resolution, TCP connection or firewall issues)
* CLI tool fails to authenticate with the server (e.g. due to CLI tool's Erlang cookie not matching that of the server)
* Target node is not running
In addition to the diagnostics info below:
* See the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more
* Consult server logs on node rabbit@192.168.1.2
* If target node is configured to use long node names, don't forget to use --longnames with CLI tools
DIAGNOSTICS
===========
attempted to contact: ['rabbit@192.168.1.2']
rabbit@192.168.1.3:
* connected to epmd (port 4369) on 192.168.1.2
* epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic
* TCP connection succeeded but Erlang distribution failed
* suggestion: check if the Erlang cookie identical for all server nodes and CLI tools
* suggestion: check if all server nodes and CLI tools use consistent hostnames when addressing each other
* suggestion: check if inter-node connections may be configured to use TLS. If so, all nodes and CLI tools must do that
* suggestion: see the CLI, clustering and networking guides on https://rabbitmq.com/documentation.html to learn more
Current node details:
* node name: 'rabbitmqcli-1352-rabbit@node2.rabbit'
* effective user's home directory: /var/lib/rabbitmq
* Erlang cookie hash: XXXXXXXXXXXXX
machine1 上的错误日志显示与此类连接尝试无关。我已经验证了两个 docker 容器上 cookie 的 md5sum,它们完全相同。权限也是如此。
我假设端口 4369 可能无法访问,但它是。
我不确定我做错了什么。有人可以帮忙吗?
附加信息:
我正在使用 rabbitmq:3.85-management 图像。它使用 Erlang/OTP 23 [erts-11.0.3]。
我一直在检查 troubleshooting guide,但我不确定这里有什么问题。如果我可以提供更多信息,请告诉我。
最佳答案
感谢@NeoAnderson 和@José M,我才能够理解发生了什么。
运行 RMQ 的容器需要可以通过 Erlang 在服务中使用的主机名跨网络访问。由于无法在另一台 机器上的容器中访问容器的主机名,因此此集群失败。
一个简单的修复方法是编辑容器上的/etc/hosts 文件,以便它将 IP 指向“领导”节点。
我这样做只是为了避免安装 RMQ,而不是因为我认为这是执行此操作的最佳方法。或者,docker swarm 或 k8s 会为我提供合适的网络。
但根本原因肯定是节点名问题。
关于docker - RabbitMQ 无法加入集群,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63212626/