连接到远程节点

Connecting to a remote node

我在一台远程机器上,它上面有一个 运行 Erlang VM 节点。我正在尝试通过 iex 连接到 Erlang VM 节点,但返回错误:

$ iex --name testing@127.0.0.1 --remsh myapp@127.0.0.1 --setcookie NMFJGSU0FwvGKlrqMuGfY1I6LtgSz1Rn2PLiDnqMS54
Erlang/OTP 18 [erts-7.3.1] [source] [64-bit] [async-threads:10] [kernel-poll:false]

Could not contact remote node myapp@127.0.0.1, reason: :nodedown. Aborting...
$

epmd -names 报告 Erlang VM 节点是 运行:

$ epmd -names
epmd: up and running on port 4369 with data:
name myapp at port 45671
$ 

这是已部署应用程序 vm.args 的内容:

-name myapp@127.0.0.1
-setcookie NMFJGSU0FwvGKlrqMuGfY1I6LtgSz1Rn2PLiDnqMS54=
-smp auto

问题:我做错了什么?

您需要将与 vm.args 中的相同的 cookie 传递给 iex:

iex --name testing@127.0.0.1 --remsh myapp@127.0.0.1 --cookie NMFJGSU0FwvGKlrqMuGfY1I6LtgSz1Rn2PLiDnqMS54=

如果 cookie 不正确,您将收到 :nodedown 错误。

来自 Shell #1:

$ iex --cookie foo --name foo@127.0.0.1

来自 Shell #2:

$ iex --name bar@localhost --remsh foo@127.0.0.1
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Could not contact remote node foo@127.0.0.1, reason: :nodedown. Aborting...
$ iex --name bar@localhost --remsh foo@127.0.0.1 --cookie foo
Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Interactive Elixir (1.3.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(foo@127.0.0.1)1>