Making Cluster in JBoss AS 7 1

Lets try to make cluster in JBoss AS 7.

First of all What is Clustering?

If there are 3-4 nodes that can communicate with each other with the help of some application or by some other mean, we can say these are in a cluster. Or Some load balancing scenario or failOver scenarios in which if one node fails then all other subseqent request will go to another node in that cluster.

Below are the steps which we will be going to follow by which we will make a cluster:

1. Folder Structure

2. Running JBoss7 through

3. Lets make two nodes.

4. How to run these two nodes seperately on different ports.

5. Lets deploy one wb application which makes use of Replicated Ehcache.

    Lets Start:

I have copied a fresh new Jboss7.

1. Below is the Folder Structre:


We will be making use of Standalone for making the cluster.

2. Running JBoss7 through

Now if i need to run the Jboss, then i simply run the in Terminal.
By default it run on port 8080. And the debug port is 8787.
We can chage the debug port by editing the file standalone.conf

3. Making two nodes.

Now we will going to make 2 Nodes. Just copy the standalone folder and paste it two times. Rename the two pasted standalone to Node1 and another one to Node2. So now the folder structure will get changed to below:


Fine upto here. Now we have two nodes, now the question is we have to start these two nodes on different http port i.e. they should listen on different port and also there debig port should be different.

So for this in bin folder make 4 files:


How to make above files: Just copy the and standalone.conf two times and changed the name as above. Just edit the node1.conf and node2.conf file and make the debug ports different.

4. How to run these two nodes seperately on different ports.

Now we will need two .sh files for staring the node1 and node2. Since we have created two different folders so we need to tell where they reside.
So make two files named as : and

These are new files and below is the source code for them:


./ -c standalone-ha.xml -b -u -Djboss.server.base.dir=/var/opt/jboss-as-7.1.1.Final/node1 -Djboss.socket.binding.port-offset=100 -Djgroups.udp.mcast_addr=  -Djgroups.bind_addr=


./ -c standalone-ha.xml -b -u -Djboss.server.base.dir=/var/opt/jboss-as-7.1.1.Final/node2 -Djboss.socket.binding.port-offset=200 -Djgroups.udp.mcast_addr=  -Djgroups.bind_addr=

When we start node1 it will listen on port 8180 and node 2 will listen on 8280 since offset for node1 is 100 and node2 is 200.

Now just run theses in terminal.

5. Deploying one wb application which makes use of Replicated Ehcache.

I made one web app which makes use of ehcahce. Below is the ehcache.xml file for that:

<?xml  version="1.0"  encoding="UTF-8"?>
    class="net.sf.ehcache.distribution.RMICacheManagerPeerListenerFactory" />
    class="com.pract.cluster.cache.EhcacheCacheManagerPeerProviderFactory" />    
    diskPersistent="false" > 
      class="net.sf.ehcache.distribution.RMICacheReplicatorFactory" />
      properties="bootstrapAsynchronously=true" />

Here the main file is EhcacheCacheManagerPeerProviderFactory. Below is the code for that:

package com.pract.cluster.cache;

import java.util.Properties;

import net.sf.ehcache.CacheException;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.distribution.CacheManagerPeerProvider;
import net.sf.ehcache.distribution.RMICacheManagerPeerProviderFactory;

public class EhcacheCacheManagerPeerProviderFactory extends RMICacheManagerPeerProviderFactory{

    public CacheManagerPeerProvider createCachePeerProvider(CacheManager cacheManager, Properties properties) throws CacheException {
        if (properties == null) {
            properties = new Properties();

        String mcastAddr = "";
        String mcastPort = "47713";

        properties.setProperty("multicastGroupAddress", mcastAddr);
        properties.setProperty("multicastGroupPort", mcastPort);
        properties.setProperty("socketTimeoutMillis", "8000");

        try {
            return createAutomaticallyConfiguredCachePeerProvider(cacheManager, properties);
        } catch (IOException e) {
            throw new CacheException("Failed to create multicast peer provider from Jboss GMS configuration", e);

I made the build and copy the war file in node1 and node2 deployment folder.
Below are the screen shots.
Opening Web App on node1 and setting the key and value
Opening Web App on node2 and giving key
Web App on node2 after pressing get

One comment on “Making Cluster in JBoss AS 7

  1. Reply eebest8 Feb 20,2015 9:15 pm

    Major thanks for the blog.Much thanks again. Really Great.

Leave a Reply