ConnectingNodesByHand
From Erlang Community
(Difference between revisions)
| Revision as of 19:36, 10 January 2007 (edit) Patricknharris (Talk | contribs) ← Previous diff |
Revision as of 20:05, 10 January 2007 (edit) (undo) Patricknharris (Talk | contribs) Next diff → |
||
| 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 '"~ | + | 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.
- On linux:
- Install erlang somewhere, say /usr/local/otp_NNN
- mkdir NodeStorage; mkdir NodeStorage/ANode; mkdir NodeStorage/BNode
- export ERL_TOP=(erlang install dir, in bash) or setenv ( csh )
- 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:
- !/bin/bash
HOSTNAME=`hostname`
HDNAME=`host ${HOSTNAME} | cut -d ' ' -f 4`
erl -name ANode@${HDNAME} -setcookie ACookie -mnesia dir '"~/NodeA"'
- cp ANode.sh BNode.sh
- sed -e 's/ANode/BNode/g' ANode.sh > BNode.sh
- sed -e 's/ANode/CNode/g' ANode.sh > CNode.sh
- 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"
- 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().

Digg It
Del.icio.us
Reddit
Facebook
Stumble Upon
Technorati

