将笔记本电脑移动到另一个网络后无法连接到 rabbitmq(甚至停止它)

Cannot connect to rabbitmq (or even stop it) after moving laptop to another network

我已经在笔记本电脑上安装了 RabbitMQ。我启动服务器 (rabbitmq-server -detached),然后 rabbitmqctl start_app,一切正常(我的 Java 应用程序可以连接和 send/receive 消息)。

$ rabbitmqctl start_app
Starting node 'rabbit@11-020-7206' ...

但是当我去到另一个网络不同的地方时,笔记本电脑获得了另一个主机名,我无法再用它做任何事情。如果我尝试停止或启动它,我会收到节点已关闭的错误消息。

$ rabbitmqctl stop
Stopping and halting node 'rabbit@Mahdis-MacBook-Pro' ...
Error: unable to connect to node 'rabbit@Mahdis-MacBook-Pro': nodedown

DIAGNOSTICS
===========

attempted to contact: ['rabbit@Mahdis-MacBook-Pro']

rabbit@Mahdis-MacBook-Pro:
  * connected to epmd (port 4369) on Mahdis-MacBook-Pro
  * epmd reports node 'rabbit' running on port 25672
  * TCP connection succeeded but Erlang distribution failed
  * suggestion: hostname mismatch?
  * suggestion: is the cookie set correctly?
  * suggestion: is the Erlang distribution using TLS?

current node details:
- node name: 'rabbitmq-cli-14528@Mahdis-MacBook-Pro'
- home dir: /Users/mahdi
- cookie hash: HBqyY/jYPLAyrH1wt3dTWQ==

如果我尝试完全启动服务器,它说节点是 运行:

$ rabbitmq-server -detached
Warning: PID file not written; -detached was passed.
ERROR: node with name "rabbit" already running on "Mahdis-MacBook-Pro"

如何修改主机名以避免这种混淆?

您将 rabbitmq 节点启动为 11-020-7206 然后将主机名(与网络相关)更改为 Mahdis-MacBook-Pro

通常您应该始终使用相同的 hostname,但如果不可能,您可以使用 rabbitmqctl -n node_name

举个例子:

gabrielesMacBookPro:sbin gabriele$ ./rabbitmqctl status
Status of node rabbit@gabrielesMacBookPro ...
[{pid,59273},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.5.5"},
     ...

这里我更改主机名:

gabrielesMacBookPro:sbin gabriele$ sudo hostname temp_hostname
Password:
gabrielesMacBookPro:sbin gabriele$ ./rabbitmqctl status
Status of node rabbit@temp_hostname ...
Error: unable to connect to node rabbit@temp_hostname: nodedown

DIAGNOSTICS
===========

attempted to contact: [rabbit@temp_hostname]

这样我就可以连接到运行节点:

gabrielesMacBookPro:sbin gabriele$ ./rabbitmqctl -n rabbit@gabrielesMacBookPro status
Status of node rabbit@gabrielesMacBookPro ...
[{pid,59273},
 {running_applications,
     [{rabbitmq_management,"RabbitMQ Management Console","3.5.5"},
      {rabbitmq_web_dispatch,"RabbitMQ Web Dispatcher","3.5.5"},

希望对您有所帮助

受@Gas 的启发,我找到了解决方法。如果我将主机名更改回将笔记本电脑移至第二个位置之前的主机名,rabbitmq(及其工具)将再次开始工作。

$ sudo hostname 11-020-7206
$ rabbitmqctl status
Status of node 'rabbit@11-020-7206' ...
[{pid,16230},
 {running_applications,[{rabbit,"RabbitMQ","3.5.4"},
....