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
- 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
- Now you would have to run the below command to start both the JBoss node in a cluster
- Both the nodes should have same multicast address
- Both the nodes should have different node names
- Both the nodes should have different socket binding port-offsets
- 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.
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
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
- 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
- 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
- Both the nodes should have same multicast address
- Both the nodes should have different node names
- Both the nodes should be running on the IP_ADDRESS or HOST_NAME of the box
- 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.
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
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.
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.
June 7th, 2012 on 11:43 pm
Hey there – I have tried this out and it seems to work great in scenario 1 but not quite in scenario 2 for me. When I have JBoss running on two separate machines, I see the join indications on both machines so I know they are talking… “Number of cluster members:2”, etc.
But going to http://node1/ClusterWebApp and http://node2/ClusterWebApp shows no indication of session replication between the two machines. It seems like they are completely separate. Whereas when I run two nodes both on the same machine, it does seem to work.
And if I run 3 nodes (2 on one machine, 1 on another) then again the two on the same machine share the same session information but the other server has its own, even though at this point I see “Number of cluster members: 3”. Any ideas on why the session isn’t being replicated across machines?
June 8th, 2012 on 12:03 am
Hi rc1,
This article was written keeping in mind for just letting our subscribers know how to create a cluster in JBoss AS7 using standalone mode, however the test you are trying to do is for session replication, for which you would need an Apache in front of this created cluster only then you would be able to achieve it.
We are planning on writing more on complete working cluster architecture, which would be coming part by part so stay tune š as more is coming on your way š
Keep Posting
Regards,
Middleware Magic Team
June 8th, 2012 on 2:43 am
Understood. Thanks – great article, will look forward to the next.
June 28th, 2012 on 3:05 pm
Hi,
One of our LINUX machine hat two IPs so I try the scenario 2 on this machine. But as I start the Jboss I got ERROR and WARN such like:
…
11:13:32,966 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]
…
Any idea?
June 28th, 2012 on 3:27 pm
HI thomas2004,
Looks like there is already some issue going on related to OSGI as mentione din the JIRA: https://issues.jboss.org/browse/AS7-5022
Which seems to to be fix in 7.1.3.Final (EAP), 7.2.0.Alpha1
.
.
Thanks
MiddlewareMagic Team š
November 29th, 2013 on 5:08 pm
Hi,
In Jboss AS 7 clustering can be done using Standalone mode and also using domain mode. Can you tell me whats the difference between these 2 modes considering clustering aspects(Like advatages/disadvantages if any, or how should one decide on which mode to be used etc..)
Thanks,
Ajit
February 22nd, 2014 on 1:11 am
hi there: Thank you for the wonderful article. This is what i was looking for. I am in the process of setting up prod jboss app server cluster.
After going through our article i have a question
1- how we can make running standalone.bat as a windows service.
FYI, i knwo how to do it in a non cluster standalone environemnt. but i don’t how we can configure the parameters you gave in the command line so that we can set up a windows service.
February 6th, 2015 on 12:34 pm
Hi Author_2 ,I setup cluster in jboss, but i see log console on two mechine is : Number of cluster members: 1 (All mechine one , two same log Number of cluster members: 1). I Want is: Number of cluster members: 2?/ Help me
February 18th, 2015 on 10:51 pm
Thank You for sharing knowledge and doing great work. I am new to this and was able to start JBoss in Standalone Cluster mode.
I was able to deploy ClusterWebApp and can see from Console that it is deployed succesfully.
But when I try and open http://localhost:port/ConsoleWebApp
I just get a blank page. I also tried http://localhost:port/ConsoleWebApp/index.jsp but still a blank page.
I wonder why? I tried my logs to granular level and I see 404 in them.
Do I need to make any changes in ClusterWebApp?
Please advise
July 13th, 2018 on 9:52 pm
I have tried this out and it seems to work great in scenario 1, but I don’t know how cluster allocates requests to different servers, much appreciated if anyone could provide more detail information