In my last article we had seen How to create cluster in JBoss AS 7.1 in standalone mode now in this article we would be doing the same but in domain mode.

In domain mode we would be using two main xml files called domain.xml and host.xml files which has to be used for creating this cluster.

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 in domain mode.

Steps to create a cluster in JBoss AS 7.1 in domain mode

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. Download and unzipped jboss-as-7.1.1.Final.zip
  2. Now in “/home/user/jboss-as-7.1.1.Final/domain/configuration/domain.xml” file make the below changes, which is just adding a new server-group (i.e. ha-server-group) which would be using ha profile and ha-sockets socket binding group, where ha is for cluster enabled.
  3. <server-groups>
            <server-group name="ha-server-group" profile="ha">
                <jvm name="default">
                    <heap size="64m" max-size="512m"/>
                </jvm>
                <socket-binding-group ref="ha-sockets"/>
            </server-group>
    .
    .
    </server-groups>
    

    Where:

    1. profile: tells which type of profile is been used (i.e. web, messaging, cluster, full)
    2. socket-binding-group: tells which all type of protocols is been used (i.e. web [http,ajp], messaging, jgroups [udp, tcp], full)
    3. server-group : tells what profile is been used and what type of sockets is been used

     

  4. After that you would have to make the below changes in “/home/user/jboss-as-7.1.1.Final/domain/configuration/host.xml” file which is just adding two new JBoss nodes with the name ha-server-1 and ha-server-2 which are using the ha-server-group server group created in the pervious setp and making this servers clusterd enabled
  5.     <servers>
          <server name="ha-server-1" group="ha-server-group" auto-start="true">
                <socket-bindings port-offset="100"/>
            </server>
            <server name="ha-server-2" group="ha-server-group" auto-start="true">
                <socket-bindings port-offset="200"/>
            </server>
    .
    .
    </servers>
    

    Note: You are giving unique name and port offset for these servers, as both the servers are running on the same box.

  6. Create a Management User using the add-user.sh script as shown below. This is done so that we can access admin console.
  7. bin]$ ./add-user.sh 
    
    What type of user do you wish to add? 
     a) Management User (mgmt-users.properties) 
     b) Application User (application-users.properties)
    (a): a
    
    Enter the details of the new user to add.
    Realm (ManagementRealm) : 
    Username : testuser
    Password : testpassword
    Re-enter Password : testpassword
    About to add user 'testuser' for realm 'ManagementRealm'
    Is this correct yes/no? yes
    Added user 'testuser' to file '/home/user/jboss-as-7.1.1.Final/standalone/configuration/mgmt-users.properties'
    Added user 'testuser' to file '/home/user/jboss-as-7.1.1.Final/domain/configuration/mgmt-users.properties'
    
  8. Once everything is done start your server by using the below command, however you would not see that the nodes ha-server-1 and ha-server-2 are in a cluster for that you would have to deploy an application which has the distributable tag in web.xml .
  9. ./domain.sh
    
  10. Now you can download one of our sample clustered application by : clicking here and deploy it from admin console from the URL “http://localhost:9990/console
  11. Adding the application

    Choosing application file

    Verifying the deployed applicaiton name

    Adding the deployed applicaiton to a server group

    Selecting ha-server-group for getting the application deployed

  12. Just after deploying application and adding it to ha-server-group you would see the below cluster view in the prompt in which the domain is running.
  13. [Server:ha-server-2] 15:12:33,971 INFO  [org.jboss.web] (MSC service thread 1-1) JBAS018210: Registering web context: /ClusterWebApp
    [Server:ha-server-2] 15:12:34,239 INFO  [org.jboss.as.clustering.impl.CoreGroupCommunicationService.lifecycle.web] (Incoming-1,null) JBAS010247: New cluster view for partition web (id: 1, delta: 1, merge: false) : [master:ha-server-2/web, master:ha-server-1/web]
    [Server:ha-server-2] 15:12:34,242 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (Incoming-1,null) ISPN000094: Received new cluster view: [master:ha-server-2/web|1] [master:ha-server-2/web, master:ha-server-1/web]
    .
    .
    [Server:ha-server-1] 15:12:34,377 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (pool-14-thread-3) ISPN000078: Starting JGroups Channel
    [Server:ha-server-1] 15:12:34,378 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (pool-14-thread-3) ISPN000094: Received new cluster view: [master:ha-server-2/web|1] [master:ha-server-2/web, master:ha-server-1/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 ] choose which one of the boxes would be working as a domain controller and other as host controller
  2. Suppose you choose box-1 [10.10.10.10] as domain controller then you would have to follow Step-2 and Step-3 of Scenario 1, creating only one JBoss server which is ha-server-1
  3. For the box-2 [20.20.20.20] which would be working as a host controller having the name host1, now only follow Step-3 of Scenario 1, this is because we would be using domain.xml of the domain controller and creating the other JBoss server which is ha-server-2 .
  4. Once you have done with the above changes you would have to follow the steps given in the article How to start JBoss AS 7.1 in domain mode ? and the below image would give you a better understanding of the architecture
  5. Now the last thing which you would have to do is to deploy the application using the console which would be running in the domain controller hence you would be using the URL http://10.10.10.10:9990/console and repeat the Step 6 of Scenario 1
  6. Once everything is done properly you would see similar below lines in respective prompts of domain and host controller
  7. [Server:ha-server-1] 19:39:29,458 INFO  [org.jboss.as.clustering.impl.CoreGroupCommunicationService.lifecycle.web] (Incoming-20,null) JBAS010247: New cluster view for partition web (id: 7, delta: 0, merge: true) : [master:ha-server-1/web, host1:ha-server-2/web]
    
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.