Erlang Central

Difference between revisions of "ConnectingNodesByHand"

From ErlangCentral Wiki

Line 5:Line 5:
 
# mkdir NodeStorage; mkdir NodeStorage/ANode; mkdir NodeStorage/BNode
 
# mkdir NodeStorage; mkdir NodeStorage/ANode; mkdir NodeStorage/BNode
 
# export ERL_TOP=(erlang install dir, in bash) or setenv ( csh )
 
# export ERL_TOP=(erlang install dir, in bash) or setenv ( csh )
# cd $ERL_TOP
+
# cd $ERL_TOP/bin
 +
# mkdir NodeA NodeB NodeC
  
 +
# The following script is useful if you have more than one box connected via NFS to the same filesystem.
 
# create a shell script (ANodeStart.sh) that contains the following:
 
# create a shell script (ANodeStart.sh) that contains the following:
 
##
 
##
Line 13:Line 15:
 
     HOSTNAME=`hostname`
 
     HOSTNAME=`hostname`
 
     HDNAME=`host ${HOSTNAME} | cut -d ' ' -f 4`
 
     HDNAME=`host ${HOSTNAME} | cut -d ' ' -f 4`
     erl -name ANode@${HDNAME} -setcookie ACookie -mnesia dir '"~/NodeStorage/NodeA"'
+
     erl -name ANode@${HDNAME} -setcookie ACookie -mnesia dir '"~/NodeA"'
  
 
# cp ANode.sh BNode.sh
 
# cp ANode.sh BNode.sh
Line 20:Line 22:
  
 
# Each file should now contain something like:
 
# Each file should now contain something like:
erl (or erl.exe or werl.ex on windows) -name
+
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
 +
# Each window should come up with an erlang prompt of #> .
 +
# To quit the shell, at the prompt, type > q().
 +
# To get nodename, at the prompt, type > node().
 +
# To get the node cookie, at the prompt, type > erlang:get_cookie().
 +
# Verify in each shell that the cookie is the same.
 +
# If not reset the cookie, at the prompt, type > erlang:set_cookie(node(), "SharedSecret").
 +
#
 +
# Go to the ANode erlang shell, define 2 variables
 +
> BNode='BNode@192.168.1.2'.
 +
> CNode='CNode@192.168.1.2'.
 +
# To Connect
 +
> net_adm:ping(BNode).
 +
> nodes().
 +
> net_adm:ping(CNode).
 +
> nodes().
 +
# Go to the other shells and verify that each node is connected to the other 2 nodes.
 +
# 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.
 +
> rpc:call(CNode, file, list_dir, ["/tmp"]).
 +
# To capture this into a variable:
 +
> {ok, CNodeUserLocalFileList} = rpc:call(CNode, file, list_dir, ["/usr/local"]).
 +
# Or to capture this for all connected nodes:
 +
> rpc:multicall(nodes(), file, list_dir, ["/usr/local"]).
 +
# Or to startup new processes on connected nodes
 +
> rpc:multicall(nodes(), os, cmd, ["/usr/local/tomcat/bin/startup.sh"]).
 +
# To see what's going on in your node cluster, use
 +
> pman:start()
 +
# 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.
 +
# Alternately, you can use the toolbar,
 +
> toolbar:start().

Revision as of 20:05, 10 January 2007

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 (ANodeStart.sh) that contains the following:
    1. !/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 separte 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().