首页 > 解决方案 > RabbitMQ 无法加入集群

问题描述

我正在尝试学习集群 rabbitmq 节点,我正在关注本教程以及官方文档

我有 2 台物理机,它们通过 docker 部署了 rabbitmq。machine1 ( 192.168.1.2 ) 将成为集群,machine2 ( 192.168.1.3 ) 将加入它。

当我尝试rabbitmqctl join_cluster rabbit@192.168.1.2从 machine2 运行时,失败并显示以下消息。

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]。

我一直在检查故障排除指南,但我不确定这里似乎有什么问题。如果我能提供更多信息,请告诉我。

标签: dockerrabbitmqrabbitmqctl

解决方案


所以感谢@NeoAnderson 和@José M,我能够理解发生了什么。

运行 RMQ 的容器需要通过 Erlang 在服务中使用的主机名通过网络进行访问。由于无法在另一台机器上的容器中访问容器的主机名,因此此集群失败。

一个简单的解决方法是编辑容器上的 /etc/hosts 文件,以便它将 IP 指向“领导者”节点。

我这样做只是为了避免安装 RMQ,而不是因为我认为这是最好的方法。或者,docker swarm 或 k8s 会为我提供正确的网络。

但根本原因肯定是节点名问题。


推荐阅读