Erlang Central


From ErlangCentral Wiki



With all of these fancy packages written by Erlang experts, how do you set up a cluster by hand?


Show prospective users the basis for the Erlang magic instead of hiding it within the current set of packages that are available. But they are somewhat overwhelming for the novice user.


If you wanted a simple three node cluster, you could execute the following steps by hand.

Prepare Some Utility Scripts

Note: The following example is for Linux or other Unix variants (including Mac OS X). On windows using cygwin the shell works as written. In a win32 environment, it's similar except you should be creating .bat files instead of .sh files.

    1.  Install erlang somewhere, say /usr/local/otp_NNN
    2.  mkdir NodeStorage; mkdir NodeStorage/ANode; mkdir NodeStorage/BNode
    3.  export ERL_TOP=(erlang install dir, in bash) or setenv ( csh )
    4.  cd $ERL_TOP/bin
    5.  mkdir NodeA NodeB NodeC

The following script is useful if you have more than one box connected via NFS to the same filesystem. You will need to create a shell script (e.g., that contains the following:

    HDNAME=`host ${HOSTNAME} | cut -d ' ' -f 4`
    erl -name ANode@${HDNAME} -setcookie ACookie -mnesia dir '"~/NodeA"'

Prepare the script for use in multiple sessions by executing the following commands in your shell (or console) of choice. This assumes access to the UNIX sed command:

    # cp
    # sed -e 's/ANode/BNode/g' >
    # sed -e 's/ANode/CNode/g' >

Each file should now contain something like:

    erl (or erl.exe or werl.ex on windows) -name ANode@ -setcookie ACookie -mnesia '"./NodeA" 

Launch the Nodes

In each of three separate console sessions, execute,,

Each window should come up with an Erlang prompt:


To get the nodename, at the prompt, type:

    1> node().

You can also quit at any time by typing:

    2> q().

Verify the Node Status

For the communication between the nodes to work, they must share the same magic cookie values. Verify this using the following command:

    1> erlang:get_cookie().

If the cookies do not match, reset them by typing the following at the prompt (where SharedSecret is a value to be used in each node session):

    2> erlang:set_cookie(node(), "SharedSecret").

Go to the ANode erlang shell, define two variables to represent the other nodes. Note that the IP address values ( should match the machine where BNode and CNode are running:

    3> BNode='BNode@'.
    4> CNode='CNode@'.

Use the Remote Nodes

You can connect to other nodes from your current node:

    5> net_adm:ping(BNode).
    6> nodes().
    7> net_adm:ping(CNode).
    8> nodes().

Go to the other shells and verify that each node is connected to the other two nodes. Note that by default it's a switch topology; other topologies are allowed.

Now that you are connected you can execute any loaded erlang module in any other node via rpc.


To find out the list of all files in "/tmp" on Node C from Node A.

    9> rpc:call(CNode, file, list_dir, ["/tmp"]).

To capture this into a variable:

    10> {ok, CNodeUserLocalFileList} = rpc:call(CNode, file, list_dir, ["/usr/local"]).

Or to capture this for all connected nodes:

    11> rpc:multicall(nodes(), file, list_dir, ["/usr/local"]).

Or to startup new processes on connected nodes

    12> rpc:multicall(nodes(), os, cmd, ["/usr/local/tomcat/bin/"]).

To get an overview of your node cluster, use the process manager.

    13> pman:start()

This command brings up the process manager, where there is a Nodes sub menu which allows you to select which node's processes to inspect or trace; see the Erlang man page for details. Alternately, you can use the Erlang toolbar,

    14> toolbar:start().