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
- 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
- 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
- We have replaced default-stack=”udp” to default-stack=”tcp” in the subsystem element.
- And added “TCPPING” protocol element with its sub-elements
- Now you would have to run the below command to start both the JBoss node in a cluster
- Both the nodes should have unique node names
- Both the nodes should have unique socket binding port-offsets as they are running on the same box
- 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
- 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.
/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.
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
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.
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
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
- 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
- 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
- Now you would have to run the below command to start both the JBoss node in a cluster
- Both the nodes should have unique node names
- Both the nodes should be running on the IP_ADDRESS or HOST_NAME of the box
- 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.
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
<protocol type="TCPPING"> <property name="initial_hosts">10.10.10.10[7600],20.20.20.20[7600]</property> . . . </protocol>
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
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.
June 28th, 2012 on 4:01 pm
Hi,
I try your 2. scenario. As I start the node1 there i sno problem. But as I start the node2, I got ERRORs as follow:
…
12:16:47,954 ERROR [org.jboss.as.controller.management-operation] (ServerService Thread Pool — 43) JBAS014612: Operation (“add”) failed – address: ([(“subsystem” => “osgi”)]): org.jboss.msc.service.DuplicateServiceException: Service jbosgi.integration.PersistentBundlesHandler is already registered
at org.jboss.msc.service.ServiceRegistrationImpl.setInstance(ServiceRegistrationImpl.java:154) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl.startInstallation(ServiceControllerImpl.java:227) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]
at org.jboss.msc.service.ServiceContainerImpl.install(ServiceContainerImpl.java:560) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]
at org.jboss.msc.service.ServiceTargetImpl.install(ServiceTargetImpl.java:201) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]
at org.jboss.msc.service.ServiceControllerImpl$ChildServiceTarget.install(ServiceControllerImpl.java:2228) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]
at org.jboss.msc.service.ServiceBuilderImpl.install(ServiceBuilderImpl.java:307) [jboss-msc-1.0.2.GA-redhat-1.jar:1.0.2.GA-redhat-1]
at org.jboss.as.controller.OperationContextImpl$ContextServiceBuilder.install(OperationContextImpl.java:955) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
at org.jboss.as.osgi.service.PersistentBundlesIntegration.addService(PersistentBundlesIntegration.java:75)
at org.jboss.as.osgi.parser.OSGiSubsystemAdd$1.execute(OSGiSubsystemAdd.java:100)
at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:397) [jboss-as-controller-7.1.2.Final-redhat-1.jar:7.1.2.Final-redhat-1]
…
Any idea?
March 11th, 2013 on 8:07 pm
Considering port offsets, I think the inial_hosts property should be :
10.10.10.10[7700],10.10.10.10[7800]
Correct me if I am wrong.
Regards,
Jerome