简体   繁体   English

如何运行使用 Rebar 分发的应用程序

[英]How to run an application distributed using Rebar

So i have an application that i want to run distributed on two nodes (one main and one failover).所以我有一个我想在两个节点(一个主节点和一个故障转移)上运行的应用程序。

I have 2 config files for each node.我为每个节点有 2 个配置文件。 Now i am running my application on the two nodes using:现在我正在使用以下两个节点上运行我的应用程序:

rebar3 shell --sname a --config a 
rebar3 shell --sname b --config b

The problem is that the application starts on both nodes since i suppose they are not pre-connected when i am issuing the rebar command.问题是应用程序在两个节点上都启动,因为我想在我发出rebar命令时它们没有预先连接。

Config files配置文件

    {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}]}].

What is the strategy to connect the nodes when/after using rebar shell ?使用rebar shell时/之后连接节点的策略是什么? Is there any way to create scripts or something?有什么方法可以创建脚本之类的吗?

I just want the nodes connected but only the main one starting witht the application started,while the second one takes on when the first crashes.我只想连接节点,但只有主节点从应用程序启动开始,而第二个节点在第一个崩溃时启动。

To connect two or more nodes, you need also set same cookies for each node.要连接两个或多个节点,您还需要为每个节点设置相同的 cookies。 And then ping those nodes by net_adm:ping/1 .然后通过net_adm:ping/1 ping 这些节点。 Here is example(expected that terminals will start at the same time ):这是示例(预计终端将同时启动):

Terminal #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().
[]

Terminal #2: 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().
[]

As you see, when you run it - we don't have any nodes.如您所见,当您运行它时 - 我们没有任何节点。 Now lets try use net_adm:ping/1 to connect them.现在让我们尝试使用net_adm:ping/1来连接它们。 Terminal #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]

Terminal #2: 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]

Also, I suppose you can join to https://erlangforums.com/ - in the Erlang community forum you can find answers to any questions related to Erlang/OTP fast enough.另外,我想您可以加入https://erlangforums.com/ - 在 Erlang 社区论坛中,您可以足够快地找到与 Erlang/OTP 相关的任何问题的答案。 PS The name and cookie you can set also by vm.args file . PS 您也可以通过vm.args文件设置名称和 cookie。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM