设置 Erlang 节点失败 "Can't set long node name! Please check your configuration"

Setting up Erlang node fails with "Can't set long node name! Please check your configuration"

$ erl -name lofa
{error_logger,{{2008,6,18},{21,43,13}},"Can't set long node name! 
\nPlease check your configuration\n",[]}
# ... several stacktrace lines follow ...

Quoting José Valim:

This is likely happening because hostname -f is not returning a value, i.e. your machine doesn't know how it should be named in the network. You can use --sname, give the fullname, like --name foo@IP_ADDRESS or something that makes sense between machines (so they can find each other).

另一个解决方案是set the hostname directlysudo hostname <FQDN>),或者更新hosts文件(例如Linux中的/etc/hosts)。

TL;DR 使用 erl -sname lofa 而不是 erl -name lofa.

解释:

  • --name 需要一个完全限定的名称,即 <username>@<host>.
  • --sname 接受短名称,即仅用户名,从 hostname -f
  • 推断主机

因此,

iex --sname joe
erl -sname joe

相当于下面的

iex --name joe@$(hostname -f)
erl -name joe@$(hostname -f)

我从 Elixir 1.7.4 & Erlang/OTP 22.3.4.20 到 1.12.1 & Erlang/OTP 24.0.2(本答案的最新版本)测试了以上内容。

参考资料: