简体   繁体   中英

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. 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.

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 ? 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. And then ping those nodes by net_adm:ping/1 . Here is example(expected that terminals will start at the same time ):

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

$ ./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. Terminal #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:

$ ./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. PS The name and cookie you can set also by vm.args file .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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