无法连接远程RabbitMQ服务器,节点名称不匹配问题求助
无法连接远程RabbitMQ服务器问题
问题背景
原本在mj机器运行RabbitMQ,现在迁移到全新的mjcelery机器,已将mj的Erlang Cookie复制到mjcelery,两者Cookie哈希值一致,但仍无法通过rabbitmqctl连接服务器,本地执行命令也报错。
服务器端启动日志
Starting RabbitMQ 3.8.2 on Erlang 22.2.7 Copyright (c) 2007-2019 Pivotal Software, Inc. Licensed under the MPL 1.1. Website: https://rabbitmq.com 2022-07-31 10:18:12.381 [info] <0.311.0> node : rabbit@mjcelery home dir : /var/lib/rabbitmq config file(s) : (none) cookie hash : kbRAhyQ5I+uDT01QMYXIdg== log(s) : /var/log/rabbitmq/rabbit@mjcelery.log : /var/log/rabbitmq/rabbit@mjcelery_upgrade.log database dir : /var/lib/rabbitmq/mnesia/rabbit@mjcelery
客户端执行命令及错误
执行命令:
sudo rabbitmqctl --longnames --node rabbit@mjcelery.dubclub.win authenticate_user dubclub "password"
错误输出:
Error: unable to perform an operation on node 'rabbit@mjcelery.dubclub.win'. 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@mjcelery.dubclub.win * If target node is configured to use long node names, don't forget to use --longnames with CLI tools DIAGNOSTICS =========== attempted to contact: ['rabbit@mjcelery.dubclub.win'] rabbit@mjcelery.dubclub.win: * connected to epmd (port 4369) on mjcelery.dubclub.win * epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic * TCP connection succeeded but Erlang distribution failed * Node name (or hostname) mismatch: node "rabbit@mjcelery" believes its node name is not "rabbit@mjcelery" but something else. All nodes and CLI tools must refer to node "rabbit@mjcelery" using the same name the node itself uses (see its logs to find out what it is) Current node details: * node name: 'rabbitmqcli-459702-rabbit@mj.dubclub.win' * effective user's home directory: /var/lib/rabbitmq * Erlang cookie hash: kbRAhyQ5I+uDT01QMYXIdg==
本地服务器执行命令及错误
执行命令:
rabbitmqctl --longnames --node rabbit@mjcelery.dubclub.win authenticate_user dubclub "password"
错误输出:
Error: unable to perform an operation on node 'rabbit@mjcelery.dubclub.win'. 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@mjcelery.dubclub.win * If target node is configured to use long node names, don't forget to use --longnames with CLI tools DIAGNOSTICS =========== attempted to contact: ['rabbit@mjcelery.dubclub.win'] rabbit@mjcelery.dubclub.win: * connected to epmd (port 4369) on mjcelery.dubclub.win * epmd reports node 'rabbit' uses port 25672 for inter-node and CLI tool traffic * TCP connection succeeded but Erlang distribution failed * Node name (or hostname) mismatch: node "rabbit@mjcelery" believes its node name is not "rabbit@mjcelery" but something else. All nodes and CLI tools must refer to node "rabbit@mjcelery" using the same name the node itself uses (see its logs to find out what it is) Current node details: * node name: 'rabbitmqcli-6733-rabbit@mjcelery.dubclub.win' * effective user's home directory: /var/lib/rabbitmq * Erlang cookie hash: kbRAhyQ5I+uDT01QMYXIdg==
问题原因及解决方法
核心原因
从服务器日志可以看到,RabbitMQ节点实际名称是rabbit@mjcelery(短名称),但执行rabbitmqctl时使用的是带域名的长名称rabbit@mjcelery.dubclub.win,导致节点名称不匹配,触发Erlang分布式连接失败。
解决步骤
使用正确的节点名称执行命令
直接用服务器日志里的节点名执行命令,无需加域名:# 客户端执行 sudo rabbitmqctl --node rabbit@mjcelery authenticate_user dubclub "password" # 本地服务器执行 rabbitmqctl --node rabbit@mjcelery authenticate_user dubclub "password"如果必须使用长名称,需要调整RabbitMQ节点启动时使用长名称:
- 编辑RabbitMQ配置文件(通常是
/etc/rabbitmq/rabbitmq.conf),添加:nodename = rabbit@mjcelery.dubclub.win - 重启RabbitMQ服务:
sudo systemctl restart rabbitmq-server
之后再用长名称执行命令即可。
- 编辑RabbitMQ配置文件(通常是
验证主机名解析一致性
确保所有机器(包括本地服务器)能正确解析mjcelery和mjcelery.dubclub.win,可以通过修改/etc/hosts文件添加映射:# 替换为实际IP <mjcelery机器IP> mjcelery mjcelery.dubclub.win确认Erlang Cookie权限
确保/var/lib/rabbitmq/.erlang.cookie文件权限为400,且属主属组为rabbitmq:rabbitmq:sudo chmod 400 /var/lib/rabbitmq/.erlang.cookie sudo chown rabbitmq:rabbitmq /var/lib/rabbitmq/.erlang.cookie
内容的提问来源于stack exchange,提问作者boatcoder
相关产品推荐
相关产品推荐

