Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to connect two Erlang nodes running on different host machines in the network?

I have two Linux machines connected using a LAN cable. Each machine is able to ping the other. Machine A has IP: 192.168.137.1 on its Ethernet eth0. Machine B has IP: 192.168.137.2 on its Ethernet eth0.

On Machine A's terminal:

ping 192.168.137.2

returns replies, and Wireshark on B is able to capture the incoming pings.

On Machine B's terminal:

ping 192.168.137.1

returns replies, and Wireshark on A is able to capture the incoming pings.

So, we have full connectivity between A and B.

Now, how can I have two Erlang shells, one running on A and the other running on B, be able to ping/ talk to each other? It would be great if someone could help me achieve this by giving detailed steps. I have been searching forums and browsing documentation but so far, I haven't got it to work. All the work I could find was for communicating between two nodes on the same host machine.

like image 996
aeon Avatar asked Apr 14 '18 03:04

aeon


People also ask

How does distributed Erlang work?

A distributed Erlang system consists of a number of Erlang runtime systems communicating with each other. Each such runtime system is called a node. Message passing between processes at different nodes, as well as links and monitors, are transparent when pids are used. Registered names, however, are local to each node.


2 Answers

A running Erlang VM instance is called a node. If you start an Erlang shell you are going to end up with a node that has distribution disabled. You can check this by calling the is_alive/0 function.

$ erl
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.3  (abort with ^G)
1> is_alive().
false

All nodes have a name – even those that don't have distribution enabled:

2> node().
nonode@nohost

...and because distribution is disabled, there are no nodes in the cluster (for now):

3> nodes().
[]
4> q().
ok

With distribution enabled, there are a couple of ways to communicate: we can call the various functions within the shell, let the Erlang VM handle it automatically at startup, etc.

$ erl -sname earth
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.3  (abort with ^G)
(earth@uplink)1> is_alive().
true
(earth@uplink)2> node().
earth@uplink
(earth@uplink)3> nodes().
[]

NOTE: uplink is the name of my machine. The full node name is always name@host. You can also see that the prompt is a little different than from the one at very first time/example.

...but still, nobody is connected! Start another node in your other machine and name it pluto this time.

$ erl -sname pluto
Erlang/OTP 20 [erts-9.3] [source] [64-bit] [smp:12:12] [ds:12:12:10] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V9.3  (abort with ^G)
(pluto@uplink)1> is_alive().
true
(pluto@uplink)2> node().    
pluto@uplink
(pluto@uplink)3> nodes().
[]
(pluto@uplink)4> net_adm:ping(earth@uplink).
pong
(pluto@uplink)5> nodes().
[earth@uplink]

You have your Erlang cluster up and running now. There are some other ways to do this. I would recommend you to read Learn You Some Erlang for Great Good!...very good one.

IMPORTANT: If you don't have the same "cookie" in both machines you might get a hard time trying to communicate the nodes. Instead you can start the node(s) and set the cookie at the same time: $ erl -sname your_node_name -setcookie 'acookietorulethemall'.

like image 193
x80486 Avatar answered Sep 22 '22 08:09

x80486


I think Throw Away Account's comment hits the nail in the head: this is mostly a networking problem, and there are plenty of duplicates of this question (here on Stackoverflow, and on other sites) that seem prove this (as most of them are unanswered):

Based on these links, it seems that things only seem to work out of the box when the networking setup is trivial (machines are in the same subnet, and they are running the same network stack). Otherwise I would assume that DNS needs to be set up properly, SSH tunnels need to be used, etc., but not sure how yet.


Posted this as a community wiki, because (1) it is not really an answer, and (2) hopefully someone, with more knowledge, will provide some pointers. (Or just give a standalone answer, whatever.)

like image 23
2 revs Avatar answered Sep 18 '22 08:09

2 revs