erlang - 如何连接在网络中不同主机上运行的两个 Erlang 节点?

标签 erlang ping erlang-shell

我有两台使用 LAN 电缆连接的 Linux 机器。每台机器都可以 ping 另一台机器。
机器 A 在其以太网 eth0 上有 IP:192.168.137.1。
机器 B 在其以太网 eth0 上有 IP:192.168.137.2。

在机器 A 的终端上:

ping 192.168.137.2

返回回复,B 上的 Wireshark 能够捕获传入的 ping。

在机器 B 的终端上:
ping 192.168.137.1

返回回复,A 上的 Wireshark 能够捕获传入的 ping。

因此,我们在 A 和 B 之间具有完全连接。

现在,我怎样才能让两个 Erlang shell,一个在 A 上运行,另一个在 B 上运行,能够相互 ping/通话?如果有人可以通过提供详细的步骤来帮助我实现这一目标,那就太好了。我一直在搜索论坛和浏览文档,但到目前为止,我还没有让它工作。我能找到的所有工作都是在同一台主机上的两个节点之间进行通信。

最佳答案

正在运行的 Erlang VM 实例称为节点。如果你启动一个 Erlang shell,你最终会得到一个禁用分发的节点。您可以调用 is_alive/0 进行检查。功能。

$ erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.3  (abort with ^G)
1> is_alive().
false

所有节点都有一个名称——即使是那些没有启用分发的节点:
2> node().
nonode@nohost

...并且由于禁用了分发,因此集群中没有节点(目前):
3> nodes().
[]
4> q().
ok

启用分发后,有两种通信方式:我们可以在 shell 中调用各种函数,让 Erlang VM
在启动时自动处理它等。
$ erl -sname earth
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.3  (abort with ^G)
(earth@uplink)1> is_alive().
true
(earth@uplink)2> node().
earth@uplink
(earth@uplink)3> nodes().
[]

NOTE: uplink is the name of my machine. The full node name is always name@host. You can also see that the prompt is a little different than from the one at very first time/example.



...但是,仍然没有人连接!在另一台机器上启动另一个节点并将其命名为 pluto这次。
$ erl -sname pluto
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.3  (abort with ^G)
(pluto@uplink)1> is_alive().
true
(pluto@uplink)2> node().    
pluto@uplink
(pluto@uplink)3> nodes().
[]
(pluto@uplink)4> net_adm:ping(earth@uplink).
pong
(pluto@uplink)5> nodes().
[earth@uplink]

你的 Erlang 集群现在已经启动并运行了。还有其他一些方法可以做到这一点。我建议您阅读 Learn You Some Erlang for Great Good! ...非常好的一个。

IMPORTANT: If you don't have the same "cookie" in both machines you might get a hard time trying to communicate the nodes. Instead you can start the node(s) and set the cookie at the same time: $ erl -sname your_node_name -setcookie 'acookietorulethemall'.

关于erlang - 如何连接在网络中不同主机上运行的两个 Erlang 节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49827564/

相关文章:

windows-xp - 禁用 Windows 响应 ping 请求的能力

erlang - 如何让 Erlang 在 Linux 上显示 UI 组件 "debugger"和 "observer"?

erlang - 使用 make 编译 LFE 文件

scala - Scala,Actor,未读收件箱邮件会如何处理?

erlang - 如何在交互式 Erlang session 中取消绑定(bind)变量?

file-io - 如何使用 Erlang OTP 模块修改文件中的一行

java - 强制android立即发送UDP数据包?

go - 如何通过 Go 中的特定网络接口(interface)发送 ICMP 消息?

erlang - 为什么 Erlang shell 中没有定义 gen_tcp?

windows - ejabberd模块编译错误