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)
    ## jboss home
    ## node ips

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

    if [ $1 -eq 1 ]; then
    if [ $1 -eq 2 ]; then

    if [ $2 = "start" ]; then

    sudo -u jboss $jboss_home/bin/ -c node$instance_number -b $instance_host \
    -Djboss.messaging.ServerPeerID=$instance_number -Djgroups.bind_addr= \
    -Djgroups.tcpping.initial_hosts=[7800] &

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

    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:

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);
<br /><strong>#session.URLToken#</strong>
<br />
<cfdump var="#mySession.getID()#">
Number of refreshes:
<cfdump var="#ival#">
<cfdump var="#cookie#">
<cfif NOT structKeyExists(cookie,"JSESSIONID")>
NO JSESSIONID! Are you proxy/rewriting? Did you remember to change the cookie path (ProxyPassReverseCookiePath)?<br />
<cfdump var="#session#">

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:

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.

# 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 Contact Blog Owner