Usually, when we speak about Standalone mode we imagine that it can’t be clustered… In fact, with JBoss it is possible, the clustering functionality is configured by default in the HA-based profiles: standalone-ha.xml and standalone-full-ha.xml.
I would like to share with you two cluster scenarios:
– Scenario 1: Two Standalone instances on one VM
– Scenario 2: Two Standalone instances on two VMs
First of all, you have to install JBoss, I installed the JBoss EAP 7.0.0 on /opt/JBoss-eap-7.
In the JBoss home directory there is a standalone folder, which is the default standalone instance location. So, the below command will start a default standalone instance with a default profile (standalone.xml):
Don’t execute it, to keep the default folder as it is for future usage.
Scenario 1: Two Standalone instances on one VM
We will create two copies of standalone folder and rename them as node1 and node2 as shown below:
cp -rp /opt/install/jboss-eap-7/standalone /opt/install/node1 cp -rp /opt/install/jboss-eap-7/standalone /opt/install/node2
It is recommended to put instance folder outside the JBoss home directory.
Below commands will start both JBoss nodes in a cluster:
/opt/install/jboss-eap-7/bin/standalone.sh -c standalone-ha.xml -Djboss.server.base.dir=/opt/install/node1 -Djboss.bind.address=vmtestjboss -Djboss.bind.address.management=vmtestjboss -Djboss.node.name=node1 -Djboss.socket.binding.port-offset=1
/opt/install/jboss-eap-7/bin/standalone.sh -c standalone-ha.xml -Djboss.server.base.dir=/opt/install/node2 -Djboss.bind.address=vmtestjboss -Djboss.bind.address.management=vmtestjboss -Djboss.node.name=node2 -Djboss.socket.binding.port-offset=2
-c : is for server configuration file to be used, it could be –server-config
-Djboss.bind.address and -Djboss.bind.address.management : are for binding address
-Djboss.server.base.dir : is for the path from where node is present
-Djboss.node.name : is the name of the node – should be different for both nodes
-Djboss.socket.binding.port-offset : is for the port offset foe each node, it should be different for both nodes because they are running on the same host.
We keep the default value of jboss.default.multicast.address (18.104.22.168), change it if you want to have multiple clusters on the same network.
Once both nodes come up properly you would not see in the log any information saying that they are in a cluster until you deploy a clustered application, but what is a clustered application?
In fact, to take advantage of the high availability features of clustered JBoss instances, an application first has to be marked as being distributable. To do so, include the distributabletag in the web.xml, as shown below:
<?xml version="1.0"?> <web-app ...> <distributable/> </web-app> ...
To deploy the application on both instances, use the Command Line Interface (CLI):
For node 1:
Use the port 9991, which is = DEFAULT MANAGEMENT HTTP PORT (9990) + PORT OFFSET (1).
[[email protected] ~]$ /opt/install/jboss-eap-7/bin/jboss-cli.sh -c --controller=vmtestjboss:9991 [[email protected]:9991 /] deploy /opt/install2/cluster.war
Then check the log and notice the below line:
20:48:59,638 INFO [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (MSC service thread 1-2) ISPN000094: Received new cluster view for channel server: [node1|0] (1) [node1]
For node 2:
Use the port 9992, which is = DEFAULT MANAGEMENT HTTP PORT (9990) + PORT OFFSET (2).
[[email protected] ~]$ /opt/install/jboss-eap-7/bin/jboss-cli.sh -c --controller=vmtestjboss:9992 [[email protected]:9992 /] deploy /opt/install2/cluster.war
Then check the log and notice the below line:
20:49:59,524 INFO [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (MSC service thread 1-2) ISPN000094: Received new cluster view for channel ejb: [node1|1] (2) [node1, node2]
The application deployed is clustered now.
Scenario 2: Two Standalone instances on two VMs
Here I have two VMs (vmtestjboss01 and vmtestjboss02), when JBoss EAP 7 is installed on both VMs, create just a single copies of standalone folder in respective VMs then start the instance:
– On vmtestjboss01:
cp -rp /opt/install/jboss-eap-7/standalone /opt/install/node1 /opt/install/jboss-eap-7/bin/standalone.sh -c standalone-ha.xml -Djboss.server.base.dir=/opt/install/node1 -Djboss.bind.address=vmtestjboss01 -Djboss.bind.address.management=vmtestjboss01 -Djboss.node.name=node1 -Djboss.default.multicast.address=22.214.171.124
– On vmtestjboss02:
cp -rp /opt/install/jboss-eap-7/standalone /opt/install/node2 /opt/install/jboss-eap-7/bin/standalone.sh -c standalone-ha.xml -Djboss.server.base.dir=/opt/install/node2 -Djboss.bind.address=vmtestjboss02 -Djboss.bind.address.management=vmtestjboss02 -Djboss.node.name=node2 -Djboss.default.multicast.address=126.96.36.199
-Djboss.socket.binding.port-offset is not needed here because we are working on two VMs, so we will not have port conflict.
-Djboss.default.multicast.address is specified here because I want to isolate this cluster from the one already configured by default (188.8.131.52)
Deploy the clustered application as explained in the first scenario.
When you have JBoss running on two separate machines, you will see the join indications on both machines so you know they are talking. But going to http://vmtestjboss01:8080/cluster and http://vmtestjboss02:8080/cluster shows no indication of session replication between the two machines. It seems like they are completely separate, whereas when you run two nodes both on the same machine it works very well. This will be explained and solved in a next blog related to session replication.
Don’t hesitate to share your experience with JBoss clusters on standalone instances!