Interconnecting Elixir nodes

Interconnecting Elixir nodes

Elixir is a functional language built on top of Erlang VM. Therefore it uses Erlang mechanism for communication with nodes. Erlang has one simple rule: everyone connects to everyone. It provides a simple authentication mechanism by tokens called cookie.
In this article I want to show how to use remote shell for interconnection between Elixir nodes.

Start elixir shell

We use sname and cookie parameters to specify short name and cookie.
Make sure that settings were applied successfully:

Start another shell, but without cookie:

In this shell we’ll use Node module to set cookie. We can try to ping our first node:

:pang atom was returned because cookies weren’t matched and connection wasn’t established. Setup identical cookie for the second node and try again:

Connect to remote shell using Job Control Mode JCL

Activate this mode using Control + G:

Show list of jobs:

We have only one job which is our current shell. Start remote Elixir shell:

Very important to specify the second parameter as Elixir.IEx module, otherwise Erlang shell will be started instead of Elixir.

Make sure that the shell was started:

Connect to job number 2 which is our first node:

Succeed! Make sure that we were connected to the right node:

Now we’re able to monitor, change configuration, execute any code in the connected node.

Disconnect node

Once all the work was done, don’t forget to disconnect remote shell in the right way. Press Control + G:

Kill job number 2 and make sure that shell was disconnected

And switch back to second node: