Erlang Central


Revision as of 20:05, 10 January 2007 by GeScript (Talk | contribs)

If you wanted a simple 3 node cluster you could do the following by hand.

  1. On linux:
  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
  1. The following script is useful if you have more than one box connected via NFS to the same filesystem.
  2. create a shell script ( that contains the following:
    1. !/bin/bash
    HDNAME=`host ${HOSTNAME} | cut -d ' ' -f 4`
    erl -name ANode@${HDNAME} -setcookie ACookie -mnesia dir '"~/NodeA"'
  1. cp
  2. sed -e 's/ANode/BNode/g' >
  3. sed -e 's/ANode/CNode/g' >
  1. Each file should now contain something like:

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

  1. Then in 3 separte windows, execute,,
  2. Each window should come up with an erlang prompt of #> .
  3. To quit the shell, at the prompt, type > q().
  4. To get nodename, at the prompt, type > node().
  5. To get the node cookie, at the prompt, type > erlang:get_cookie().
  6. Verify in each shell that the cookie is the same.
  7. If not reset the cookie, at the prompt, type > erlang:set_cookie(node(), "SharedSecret").
  8. Go to the ANode erlang shell, define 2 variables

> BNode='BNode@'. > CNode='CNode@'.

  1. To Connect

> net_adm:ping(BNode). > nodes(). > net_adm:ping(CNode). > nodes().

  1. Go to the other shells and verify that each node is connected to the other 2 nodes.
  2. By default it's a switch topology; other topologies are allowed.
  3. Now that you are connected you can execute any loaded erlang module in any other node via rpc.
  4. To find out the list of all files in "/tmp" on Node C from Node A.

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

  1. To capture this into a variable:

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

  1. Or to capture this for all connected nodes:

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

  1. Or to startup new processes on connected nodes

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

  1. To see what's going on in your node cluster, use

> pman:start()

  1. This brings up the process manager, 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.
  2. Alternately, you can use the toolbar,

> toolbar:start().