[英]How to run an application distributed using Rebar
所以我有一个我想在两个节点(一个主节点和一个故障转移)上运行的应用程序。
我为每个节点有 2 个配置文件。 现在我正在使用以下两个节点上运行我的应用程序:
rebar3 shell --sname a --config a
rebar3 shell --sname b --config b
问题是应用程序在两个节点上都启动,因为我想在我发出rebar
命令时它们没有预先连接。
配置文件
{kernel,[{distributed,[{ex_banking,['a@AdrianB-LAPTOP','b@Adrian-LAPTOP']}]},
{sync_nodes_timeout,3000}]},
{ex_banking,[{port,3000}]}].
{kernel,[{distributed,[{ex_banking,['a@AdrianB-LAPTOP','b@Adrian-LAPTOP']}]},
{sync_nodes_mandatory,['a@AdrianB-LAPTOP'},
{sync_nodes_timeout,3000}]},
{ex_banking,[{port,3000}]}].
使用rebar shell
时/之后连接节点的策略是什么? 有什么方法可以创建脚本之类的吗?
我只想连接节点,但只有主节点从应用程序启动开始,而第二个节点在第一个崩溃时启动。
要连接两个或多个节点,您还需要为每个节点设置相同的 cookies。 然后通过net_adm:ping/1 ping 这些节点。 这是示例(预计终端将同时启动):
1号航站楼:
$ ./rebar3 shell --sname a --setcookie test
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
Eshell V12.1.5 (abort with ^G)
(a@pc)1> nodes().
[]
2号航站楼:
$ ./rebar3 shell --sname b --setcookie test
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
Eshell V12.1.5 (abort with ^G)
(b@pc)1> nodes().
[]
如您所见,当您运行它时 - 我们没有任何节点。 现在让我们尝试使用net_adm:ping/1
来连接它们。 1号航站楼:
$ ./rebar3 shell --sname a --setcookie test
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
Eshell V12.1.5 (abort with ^G)
(a@pc)1> nodes().
[]
(a@pc)2> net_adm:ping('b@pc').
pong
(a@pc)3> nodes().
[b@pc]
2号航站楼:
$ ./rebar3 shell --sname b --setcookie test
Erlang/OTP 24 [erts-12.1.5] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1]
Eshell V12.1.5 (abort with ^G)
(b@pc)1> nodes().
[a@pc]
另外,我想您可以加入https://erlangforums.com/ - 在 Erlang 社区论坛中,您可以足够快地找到与 Erlang/OTP 相关的任何问题的答案。 PS 您也可以通过vm.args
文件设置名称和 cookie。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.