ConnectingNodesByHand
From Erlang Community
If you wanted a simple 3 node cluster you could do the following by hand.
- On linux: (
- Note: On windows cygwin the shell works as written.
- In win32 env's it's similar. except you should be creating .bat files instead of .sh files.
- 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

