Erlang Central

Difference between revisions of "ConnectingNodesByHand"

From ErlangCentral Wiki

Line 26: Line 26:
 
erl (or erl.exe or werl.ex on windows) -name ANode@192.168.1.2 -setcookie ACookie -mnesia '"./NodeA"  
 
erl (or erl.exe or werl.ex on windows) -name ANode@192.168.1.2 -setcookie ACookie -mnesia '"./NodeA"  
  
# Then in 3 separte windows, execute ANode.sh, BNode.sh, CNode.sh
+
# Then in 3 separate windows, execute ANode.sh, BNode.sh, CNode.sh
 
# Each window should come up with an erlang prompt of #> .
 
# Each window should come up with an erlang prompt of #> .
 
# To quit the shell, at the prompt, type > q().
 
# To quit the shell, at the prompt, type > q().

Revision as of 07:02, 11 January 2007

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

  1. Note: On windows cygwin the shell works as written.
  2. In win32 env's it's similar. except you should be creating .bat files instead of .sh files.
  3. On linux:
  4. Install erlang somewhere, say /usr/local/otp_NNN
  5. mkdir NodeStorage; mkdir NodeStorage/ANode; mkdir NodeStorage/BNode
  6. export ERL_TOP=(erlang install dir, in bash) or setenv ( csh )
  7. cd $ERL_TOP/bin
  8. 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 (ANodeStart.sh) that contains the following:
    #!/bin/bash
    HOSTNAME=`hostname`
    HDNAME=`host ${HOSTNAME} | cut -d ' ' -f 4`
    erl -name ANode@${HDNAME} -setcookie ACookie -mnesia dir '"~/NodeA"'
  1. cp ANode.sh BNode.sh
  2. sed -e 's/ANode/BNode/g' ANode.sh > BNode.sh
  3. sed -e 's/ANode/CNode/g' ANode.sh > CNode.sh
  1. Each file should now contain something like:

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

  1. Then in 3 separate windows, execute ANode.sh, BNode.sh, CNode.sh
  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@192.168.1.2'. > CNode='CNode@192.168.1.2'.

  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/startup.sh"]).

  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().