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