【问题标题】:Node naming problems节点命名问题
【发布时间】:2020-05-16 01:07:49
【问题描述】:

有两台机器: M1 有两个 ip 地址 192.168.5.47、192.168.1.250。 而 M2 的 ip 为 192.168.5.250。

我在 M1 上启动了一个 erlang 节点:

nik@nik-PC:~/erlsrc/test_mk$ erl -name 'test@127.0.0.1' -setcookie cook
Erlang/OTP 22 [erts-10.6.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Eshell V10.6.2  (abort with ^G)
(test@127.0.0.1)1> 

然后,我在 M2 上创建另一个节点并尝试 ping M1:

nik2@nik2-PC:~$ erl -name 'test2@127.0.0.1' -setcookie cook
Erlang/OTP 22 [erts-10.6.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]

Eshell V10.6.2  (abort with ^G)
(test2@127.0.0.1)1> 
(test2@127.0.0.1)1> net_adm:ping('test@192.168.5.47').
pang
(test2@127.0.0.1)2> 

如果远程机器上的一个节点有多个 ip 地址并以 'name@localhost' 或 'name@127.0.0.1' 启动,如何在远程机器上的节点之间进行通信? 还是用域名比较好?

【问题讨论】:

    标签: erlang erlang-otp


    【解决方案1】:

    如果节点在一个 LAN 网络中运行,但在不同的计算机上运行,​​您可以尝试在每台计算机上检测您的 IP,例如运行:

    $ hostname -I
    

    让我们假设 ma​​chine 1 的 IP 地址为 192.168.5.47,而 ma​​chine 2 的 IP 地址为 192.168.5.250。 现在您需要在 ma​​chine 1 上运行带有标志 name 的节点,其中包括 IP - ma​​chine #1

    $ erl -name 'test@192.168.5.47' -setcookie cook
    

    现在在 ma​​chine 2 中执行相同操作,但使用 ma​​chine 2 - ma​​chine #2 的 IP:

    $ erl -name 'test@192.168.5.250' -setcookie cook
    

    现在您可以尝试将pingtest@192.168.5.47 发送到test@192.168.5.250 - 机器#1

    (test@192.168.5.47)1> net_adm:ping('test@192.168.5.250').
    pong
    

    【讨论】:

    • 感谢您的回复。它非常有用,我曾经这样做过,但它就像节点名称中的硬编码。如果我尝试从另一个子网(192.168.1.X)连接这个节点,我们该怎么办?因为对于我的示例,机器 M1 有两个子网的两个 IP 别名。或者最好的方法是使用域名?..
    • 是的,如果您的服务器配置正确,您可以使用域名。
    • 但是域名会匹配一些IP,我想你需要检测你可以使用的确切IP并尝试使用它。此外,您可能无法将 ping 从 M1 发送到 M2,因为您需要对服务器进行一些配置,在这种情况下,您可以查看工具 iptables - 使用此工具您可以只允许从计算机中的特定 IP,因为如果没有特定技能来允许从外部从所有 IP 完全访问计算机 - 可能很危险。
    猜你喜欢
    • 2011-08-10
    • 1970-01-01
    • 1970-01-01
    • 2014-10-13
    • 1970-01-01
    • 2019-01-29
    • 1970-01-01
    • 1970-01-01
    • 2012-06-05
    相关资源
    最近更新 更多