In my previous article we had seen How to create cluster in JBoss AS 7.1 in standalone mode? which was using UDP protocol.

By default JBoss AS7 uses UDP protocol, but for security constrains some companies do not open/allow to use UDP protocol or multicast addresses, hence during that time TCP protocol or unicast address can be used to create a cluster which is also supported by JBoss AS 7.

In this article we would be showing you how you use standalone mode to create a cluster using TCP protocol. However as we all know in standalone mode 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.

Steps to create a TCP cluster in JBoss AS 7.1 in standalone 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. 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. In both the standalone-nodex you would have to make the following changes in standalone-ha.xml files to tell JBoss to start the cluster in TCP protocol
  4. From:

    <subsystem xmlns="urn:jboss:domain:jgroups:1.1" default-stack="udp">
                <stack name="udp">
               .
               .
               .
                </stack>
                <stack name="tcp">
                    <transport type="TCP" socket-binding="jgroups-tcp" diagnostics-socket-binding="jgroups-diagnostics"/>
                    <protocol type="MPING" socket-binding="jgroups-mping"/>
                    <protocol type="MERGE2"/>
                    <protocol type="FD_SOCK" socket-binding="jgroups-tcp-fd"/>
                    <protocol type="FD"/>
                    <protocol type="VERIFY_SUSPECT"/>
                    <protocol type="BARRIER"/>
                    <protocol type="pbcast.NAKACK"/>
                    <protocol type="UNICAST2"/>
                    <protocol type="pbcast.STABLE"/>
                    <protocol type="pbcast.GMS"/>
                    <protocol type="UFC"/>
                    <protocol type="MFC"/>
                    <protocol type="FRAG2"/>
                </stack>
            </subsystem>
    

    To:

    <subsystem xmlns="urn:jboss:domain:jgroups:1.1" default-stack="tcp">
                <stack name="udp">
               .
               .
               .
                </stack>
                <stack name="tcp">
                    <transport type="TCP" socket-binding="jgroups-tcp" diagnostics-socket-binding="jgroups-diagnostics"/>
                    <protocol type="TCPPING">
                        <property name="initial_hosts">10.10.10.10[7600],10.10.10.10[7600]</property>
                        <property name="num_initial_members">2</property>
                        <property name="port_range">0</property>
                        <property name="timeout">2000</property>
                    </protocol>
                    <protocol type="MERGE2"/>
                    <protocol type="FD_SOCK" socket-binding="jgroups-tcp-fd"/>
                    <protocol type="FD"/>
                    <protocol type="VERIFY_SUSPECT"/>
                    <protocol type="BARRIER"/>
                    <protocol type="pbcast.NAKACK"/>
                    <protocol type="UNICAST2"/>
                    <protocol type="pbcast.STABLE"/>
                    <protocol type="pbcast.GMS"/>
                    <protocol type="UFC"/>
                    <protocol type="MFC"/>
                    <protocol type="FRAG2"/>
                </stack>
            </subsystem>
    
      Note: Following are the changes made

    1. We have replaced default-stack=”udp” to default-stack=”tcp” in the subsystem element.
    2. And added “TCPPING” protocol element with its sub-elements

    Where:
    initial_hosts = is a list of comma-seperated combo of IP_ADDRESS and PORT for pinging.
    num_initial_members = specifies the maximum number of responses to wait for.
    port_range = specifies the range of ports to ping on each host in the initial_hosts list.
    timeout = specifies the maximum number of milliseconds to wait for any responses.

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

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

    Node2

    ./standalone.sh -c standalone-ha.xml -b 10.10.10.10 -Djboss.server.base.dir=../standalone-2 -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
    -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 unique node names
    2. Both the nodes should have unique socket binding port-offsets as they are running on the same box
  7. 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
  8. 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.
  9. 21:49:11,988 INFO  [stdout] (pool-14-thread-1) -------------------------------------------------------------------
    21:49:11,989 INFO  [stdout] (pool-14-thread-1) GMS: address=node2/web, cluster=web, physical address=10.10.10.10:7800
    21:49:11,989 INFO  [stdout] (pool-14-thread-1) -------------------------------------------------------------------
    .
    .
    21:49:15,954 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. In both the standalone-nodex you would have to follow the same Step-2 of Scenario 1, however only one change would be there in “initial_hosts” you would have to give both boxes IP_ADDRESS as shown below
  4. <protocol type="TCPPING">
    	<property name="initial_hosts">10.10.10.10[7600],20.20.20.20[7600]</property>
    	.
    	.
    	.
    </protocol>
    
  5. Now you would have to run the below command to start both the JBoss node in a cluster
  6. Node1 on Box-1 [10.10.10.10]

    ./standalone.sh -c standalone-ha.xml -b 10.10.10.10 -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 -Djboss.server.base.dir=../standalone-node2 -Djboss.node.name=node2
    
      Note: However we need to keep in mind the following things 

    1. Both the nodes should have unique node names
    2. Both the nodes should be running on the IP_ADDRESS or HOST_NAME of the box

    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.

  7. Repeat the same step-4 and step-5 of Scenario-1 and you would then see the same cluster view in each running nodes prompts.
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.