erlang - 在启动时动态设置节点名称

标签 erlang relx

我正在使用 relx 构建我的版本,但无法使用默认的 -sname someuser@127.0.0.1。 相反,我想做类似 -sname someuser@`hostname -i` 的操作来在启动时定义节点的公共(public) IP。使用 -sname someuser@hostname -i`` 不起作用,因为 hostname -i 未扩展为真实 IP。我尝试使用 net_kernel:start(xxxxxxx) 但没有成功。

有没有办法使用 relx 在 vm.args 中获取动态 -sname

谢谢:)

最佳答案

如所写in the documentation (并在 @Soup d'Campbells 的评论中回答),-sname-name 标志不需要主机名,并且将使用主机的 sid 自动填充节点 ID 的 Host 部分(对于 -sname 来说,短格式不完全限定,对于 -name 来说,FQDN 不完全限定):

-sname Name Makes the Erlang runtime system into a distributed node, similar to -name, but the host name portion of the node name Name@Host will be the short name, not fully qualified.

This is sometimes the only way to run distributed Erlang if the DNS (Domain Name System) is not running. There can be no communication between nodes running with the -sname flag and those running with the -name flag, as node names must be unique in distributed Erlang systems.

-name Name Makes the Erlang runtime system into a distributed node. This flag invokes all network servers necessary for a node to become distributed. See net_kernel(3). It is also ensured that epmd runs on the current host before Erlang is started. See epmd(1).

The name of the node will be Name@Host, where Host is the fully qualified host name of the current host. For short names, use the -sname flag instead.

如果您计划使用分布式节点,并且您的域中确实有 DNS,请使用 -name 标志,因为它还将调用所有必要的网络服务器(如上所述)。

亲自看看:

$> erl -sname bouly
(bouly@myserver)1>

$> erl -name bouly
(bouly@myserver.myhome.net)1>

关于erlang - 在启动时动态设置节点名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24916967/

相关文章:

使用relx时erlang dbg模块不工作

erlang - 使用 Erlang 生成 RSA key 对?

erlang - 我如何从 Erlang Pid 中获取每个部分?

erlang - 钢筋外壳 - 传递配置文件

erlang - 如何在 CouchDB 中创建 Erlang View

Erlang 生成问题

erlang - 如何在使用 relx 发布汇编程序构建的应用程序中正确使用同步?

erlang - OTP - 添加 Couchbeam 作为依赖项 - ** 异常错误 : undefined function jsx:decode/1