Clustering JBoss AS 5, the easy way

There are a couple of simple steps to get JBoss clustering working in a way that is easy to deploy, and with minimal editing of files.

  1. Download JBoss AS, and extract it.
  2. Copy the "all" server (jboss/server/all) to "nodetemplate" (jboss/server/nodetemplate)
  3. Install Railo or JBoss into the "nodetemplate" server (you may want to use a central location for Railo or ColdFusion libraries, see the railo EAR example)
  4. Edit the server.xml file (jboss/server/nodetemplate/deploy/jbossweb.sar/server.xml) and add this to the "Engine" tag: jvmRoute="node${jboss.messaging.ServerPeerID}" (Ex: <Engine name="jboss.web" defaultHost="localhost" jvmRoute="node${jboss.messaging.ServerPeerID}"> )
  5. Change the JMS datasource database
  6. Edit jboss/server/nodetemplate/messaging/messaging-service.xml and messaging-jboss-beans.xml and change the "MessageSucker" password.
  7. Create a user named "jboss", if you don't have one already. Be sure it's a system account (not a real user account)
  8. Copy the "nodetemplate" directory to "node1" (Ex. cp -R nodetemplate node1)
  9. Give ownership of the jboss folder to the jboss user
  10. Create a startup script for your nodes in the jboss/bin directory, called "jbossnode".
  11. Put this in there, and edit the settings (ip addresss, and perhaps your multicast address (jgroups.bind_addr))
    jboss.messaging.ServerPeerID will be a unique node number, for use with load balancing later on, and to avoid node conflicts
    (this script isn't good for automatic startup without editing, eventually I'll get a new one posted)
    #!/bin/sh
    ## jboss home
    jboss_home="/path/to/jboss"
    ## node ips
    node_ip_1=10.0.1.8
    node_ip_2=10.0.2.1

    if [ $# -eq 0 ]; then
        echo "please specify node number and an action (start|stop) - Example: jbossnode 2 start"
        exit 0
    fi

    if [ $1 -eq 1 ]; then
    instance_number=1
    instance_host=$node_ip_1
    fi
    if [ $1 -eq 2 ]; then
    instance_number=2
    instance_host=$node_ip_2
    fi

    if [ $2 = "start" ]; then

    sudo -u jboss $jboss_home/bin/run.sh -c node$instance_number -b $instance_host \
    -Djboss.messaging.ServerPeerID=$instance_number -Djgroups.bind_addr=127.0.0.1 \
    -Djgroups.tcpping.initial_hosts=127.0.0.1[7800] -Djava.net.preferIPv4Stack=true &

    fi
    if [ $2 = "stop" ]; then
    sudo -u jboss $jboss_home/bin/shutdown.sh -s $instance_host -S
    fi

    echo "$2ing node $instance_number ($instance_host)"
  12. make it executable: ./chmod +x jbossnode
  13. start node 1 like this: ./jbossnode 1 start
  14. start node 2 like this: ./jbossnode 2 start
  15. stop node 1 like this: ./jbossnode 1 stop
  16. stop node 2 like this: ./jbossnode 2 stop

Create a CFM file containing the following:

<cfscript>
mySession = getPageContext().getRequest().getSession(true);
ival = mySession.getAttribute("simplesession.counter");
if (NOT isDefined("ival")){
    ival = 1;
} else {
    ival = ival + 1;
}
mySession.setAttribute("simplesession.counter", ival);
</cfscript>
<cfoutput>
CFSESSIONID:
<br /><strong>#session.URLToken#</strong>
<br />
JSESSIONID:
<cfdump var="#mySession.getID()#">
Number of refreshes:
<cfdump var="#ival#">
Cookies:
<cfdump var="#cookie#">
<cfif NOT structKeyExists(cookie,"JSESSIONID")>
NO JSESSIONID! Are you proxy/rewriting? Did you remember to change the cookie path (ProxyPassReverseCookiePath)?<br />
</cfif>
Session:
<cfdump var="#session#">
</cfoutput>

This should display something like:

V4VJ3xd4NRn82z6OkPncww__.node1 (emphasis added)

Plus the dumps. Refresh a couple times and verify your sessions are working. Play around with the balance-manager stuff if you want.

Oh, guess you should read the load balancing entry first!

Assuming you already did that, and set up sticky sessions and whatnot, you can bring various nodes up or down and hit that page to see what node you are being served from.

Some helpful links:

http://docs.hp.com/en/5991-5855/ar01s07.html

http://www.yorku.ca/dkha/jboss/docs/ClusterTesting.htm

http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.3/doc/messaging/JBoss_Messaging_User_Guide/html-single/index.html

http://wiki.jboss.org/wiki/UsingMod_proxyWithJBoss

http://www.jboss.org/file-access/default/members/jbossas/freezone/docs/Clustering_Guide/beta500/html_single/index.html

More later

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Gary Gilbert's Gravatar Hi,

You mention in your post about keeping the railo files in a central location step 3, and refer to a link that isn't there. I would be very interested to know what you mean :). I have had some problems trying to get as 5 and railo to play nice with apache.

I cant seem to get my railo to work external to the deploy folder regardless of how I set my profile.xml file.

Thanks!
# Posted By Gary Gilbert | 9/22/09 1:27 AM
shen's Gravatar I've updated the link to point at an EAR example. You could also keep the jars in some random spot and add them to the classpath probably.
# Posted By shen | 9/22/09 9:35 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.3.000. Contact Blog Owner