We have seen that JBoss AS 7 is totally different then the earlier versions of JBoss, hence if you want to create a cluster in JBoss AS 7 there are few things which has been change and has to be known or else you would face issues.

In JBoss AS 7 we have by default two modes which are domain mode and standalone mode , in this article we would be using standalone mode. However in standalone mode also we have different xml files under the configuration folder from which cluster is enabled in standalone-ha.xml and standalone-full-ha.xml, thus make sure you would be using them and not other xml files.

In this article we would be using JBoss AS 7.1.1 Final which is the latest version of JBoss in community version. Now lets see how can we create cluster in JBoss AS 7.1

Steps to create a cluster in JBoss AS 7.1

We would be seeing two scenarios here one would be creating a cluster on the same box and second when creating a cluster between different boxes.

Scenario 1: Cluster on same box

  1. Once you have unzipped jboss-as-7.1.1.Final.zip , you would have to create two copies of standalone folder and rename them as standalone-node1 and standalone-node2 as shown below
  2. /home/user/jboss-as-7.1.1.Final/standalone-node1
    /home/user/jboss-as-7.1.1.Final/standalone-node2
    

    Note: Make sure you keep the original copy for standalone folder as it is for future usage.

  3. Now you would have to run the below command to start both the JBoss node in a cluster
  4. Node1

    ./standalone.sh -c standalone-ha.xml -b 10.10.10.10 -u 230.0.0.4 -Djboss.server.base.dir=../standalone-node1 -Djboss.node.name=node1 -Djboss.socket.binding.port-offset=100
    

    Node2

    ./standalone.sh -c standalone-ha.xml -b 10.10.10.10 -u 230.0.0.4 -Djboss.server.base.dir=../standalone-node2 -Djboss.node.name=node2 -Djboss.socket.binding.port-offset=200
    

    Where:
    -c = is for server configuration file to be used
    -b = is for binding address
    -u = is for multicast address
    -Djboss.server.base.dir = is for the path from where node is present
    -Djboss.node.name = is for the name of the node
    -Djboss.socket.binding.port-offset = is for the port offset on which node would be running

      Note: However we need to keep in mind the following things 

    1. Both the nodes should have same multicast address
    2. Both the nodes should have different node names
    3. Both the nodes should have different socket binding port-offsets
  5. Once both the node comes up properly you would not see them in cluster, hence to make sure if both of the nodes are in a cluster then you would need to deploy the an application which has the distributable tag in web.xml . You can download one of our sample clustered application by : clicking here
  6. After downloading the ClusterWebApp.war you just have to keep it in (/home/user/jboss-as-7.1.1.Final/standalone-nodeX/deployments) both nodes deployments folder, just after that you would see similar below messages in both the nodes prompt, having both node names in there cluster view.
  7. 18:32:46,863 INFO  [stdout] (pool-13-thread-1) -------------------------------------------------------------------
    18:32:46,863 INFO  [stdout] (pool-13-thread-1) GMS: address=node1/web, cluster=web, physical address=10.10.10.10:55300
    18:32:46,863 INFO  [stdout] (pool-13-thread-1) -------------------------------------------------------------------
    18:32:47,572 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (MSC service thread 1-8) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be pasivated.
    18:32:47,581 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (MSC service thread 1-1) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be pasivated.
    18:32:47,771 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (pool-15-thread-1) ISPN000078: Starting JGroups Channel
    18:32:47,791 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (pool-15-thread-1) ISPN000094: Received new cluster view: [node1/web|1] [node1/web, node2/web]
    

Scenario 2: Cluster on different boxes

  1. After unzipping JBoss AS 7 in both the boxes [i.e. box-1=10.10.10.10 and box-2=20.20.20.20 ] then you can create just a single copies of standalone folder in respective boxes
  2. Box-1 : 10.10.10.10

    /home/user/jboss-as-7.1.1.Final/standalone-node1
    

    Box-2 : 20.20.20.20

    /home/user/jboss-as-7.1.1.Final/standalone-node2
    
  3. Now you would have to run the below command to start both the JBoss node in a cluster
      Note: However we need to keep in mind the following things 

    1. Both the nodes should have same multicast address
    2. Both the nodes should have different node names
    3. Both the nodes should be running on the IP_ADDRESS or HOST_NAME of the box
  4. Node1 on Box-1 [10.10.10.10]

    ./standalone.sh -c standalone-ha.xml -b 10.10.10.10 -u 230.0.0.4 -Djboss.server.base.dir=../standalone-node1 -Djboss.node.name=node1
    

    Node2 on Box-2 [20.20.20.20]

    ./standalone.sh -c standalone-ha.xml -b 20.20.20.20 -u 230.0.0.4 -Djboss.server.base.dir=../standalone-node2 -Djboss.node.name=node2
    

    Here we would not have to worry about the port conflicts as we are running both the nodes on different boxes having different binding address.

  5. Repeat the same step-3 and step-4 of Scenario-1 and you would then see the same cluster view in each running nodes prompts.

If you are looking for running multiple clusters, then you would have to make sure you give a different set of multicast address (i.eĀ  -u option) for each cluster.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.