January 4, 2013

How to Cluster Standalone JBoss EAP 6 and AS 7

In this blog I will show you how to cluster two JBoss standalone servers.

Prerequisites:

When you have the prerequisites up and running we are ready to start the JBoss servers. Here I will start with the most simple configuration, i.e. standalone-ha mode.

To simulate a more real situation I have unziped jboss-eap-6.0.1.zip to two different folders, jb1 and jb2. Now lets start each JBoss server.

$ ./jb1/bin/standalone.sh -Djboss.node.name=jb1 --server-config=standalone-ha.xml

Since we will be running two servers on the same machine we need to differentiate the servers ports. This can easy be made with the JBoss property port-offset.

$ ./jb2/bin/standalone.sh -Djboss.node.name=jb2 --server-config=standalone-ha.xml -Djboss.socket.binding.port-offset=200

Now you should see in each JBoss log file that it picked up mod_cluster.

04:26:42,195 INFO  [org.jboss.modcluster.ModClusterService] (ServerService Thread Pool -- 54) Initializing mod_cluster 1.2.3.Final-redhat-1
04:26:51,782 INFO  [org.jboss.modcluster.ModClusterService] (ContainerBackgroundProcessor[StandardEngine[jboss.web]]) Engine [jboss.web] will use jvmRoute: 4e6189af-0502-3305-8ff3-fad7fee8b516

Also verify that mod_cluster in Apache Web Server has detected the two JBoss servers.

If mod_cluster have not detected two server or they have not Status: OK, then stop here and check the Apache Web Server error log file (/etc/httpd/logs/error_log) and JBoss server log file (./jb1/standalone/log/server.log).

In my case had SELinux problem that stopped the second JBoss instance to be properly detected by mod_cluster in Apache Web Server. I received the following error message in /etc/httpd/logs/error_log.

(13)Permission denied: proxy: ajp: attempt to connect to 127.0.0.1:8259 (127.0.0.1) failed

To temporarily disable that, run the below on RHEL 6.3. For a lengthier description see http://sysadminsjourney.com/content/2010/02/01/apache-modproxy-error-13permission-denied-error-rhel/.

$ /usr/sbin/setsebool httpd_can_network_connect 1

Since the new JBoss load modules lazily, you will not see much in the log file, without a cluster application. You can write you own clustered application, but that is out of scope for this blog, so I copied a simple application from https://github.com/akquinet/jbosscc-as7-examples/tree/master/cluster-example.

Now deploy the clusterd application to each JBoss deploy folder $JBOSS_HOME/standalone/deployments/. And you see in each JBoss log file, that they have started Infinispan, and clustering have detected each other.

jb1
--------
12:56:42,923 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 26) ISPN000078: Starting JGroups Channel
12:56:42,932 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 26) ISPN000094: Received new cluster view: [jb1/web|0] [jb1/web]
12:56:42,935 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 26) ISPN000079: Cache local address is jb1/web, physical addresses are [127.0.0.1:55200]
12:56:42,941 INFO  [org.infinispan.factories.GlobalComponentRegistry] (ServerService Thread Pool -- 26) ISPN000128: Infinispan version: Infinispan 'Brahma' 5.1.8.Final
12:56:42,942 INFO  [org.infinispan.config.ConfigurationValidatingVisitor] (ServerService Thread Pool -- 26) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
12:56:43,054 INFO  [org.infinispan.config.ConfigurationValidatingVisitor] (ServerService Thread Pool -- 23) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
12:56:43,104 INFO  [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 23) ISPN000031: MBeans were successfully registered to the platform mbean server.
12:56:43,104 INFO  [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 26) ISPN000031: MBeans were successfully registered to the platform mbean server.
12:56:43,192 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 26) JBAS010281: Started repl cache from web container
12:56:43,193 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 23) JBAS010281: Started default-host/mod_cluster-demo-server-1.2.0.Final cache from web container
12:56:43,211 INFO  [org.jboss.as.clustering] (MSC service thread 1-2) JBAS010238: Number of cluster members: 1
12:56:43,251 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 passivated.
12:56:43,262 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 passivated.
12:56:43,269 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 passivated.
12:56:43,376 INFO  [org.jboss.web] (MSC service thread 1-1) JBAS018210: Registering web context: /mod_cluster-demo-server-1.2.0.Final
12:56:43,547 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 1) JBAS018559: Deployed "mod_cluster-demo-server-1.2.0.Final.war"
12:56:46,269 INFO  [org.jboss.as.clustering] (Incoming-1,null) JBAS010225: New cluster view for partition web (id: 1, delta: 1, merge: false) : [jb1/web, jb2/web]
12:56:46,271 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (Incoming-1,null) ISPN000094: Received new cluster view: [jb1/web|1] [jb1/web, jb2/web]
jb2
--------
12:56:46,602 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 55) ISPN000078: Starting JGroups Channel
12:56:46,612 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 55) ISPN000094: Received new cluster view: [jb1/web|1] [jb1/web, jb2/web]
12:56:46,613 INFO  [org.infinispan.remoting.transport.jgroups.JGroupsTransport] (ServerService Thread Pool -- 55) ISPN000079: Cache local address is jb2/web, physical addresses are [127.0.0.1:55300]
12:56:46,618 INFO  [org.infinispan.factories.GlobalComponentRegistry] (ServerService Thread Pool -- 55) ISPN000128: Infinispan version: Infinispan 'Brahma' 5.1.8.Final
12:56:46,619 INFO  [org.infinispan.config.ConfigurationValidatingVisitor] (ServerService Thread Pool -- 55) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
12:56:46,723 INFO  [org.infinispan.config.ConfigurationValidatingVisitor] (ServerService Thread Pool -- 57) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
12:56:46,765 INFO  [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 57) ISPN000031: MBeans were successfully registered to the platform mbean server.
12:56:46,765 INFO  [org.infinispan.jmx.CacheJmxRegistration] (ServerService Thread Pool -- 55) ISPN000031: MBeans were successfully registered to the platform mbean server.
12:56:46,920 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 57) JBAS010281: Started default-host/mod_cluster-demo-server-1.2.0.Final cache from web container
12:56:46,962 INFO  [org.jboss.as.clustering.infinispan] (ServerService Thread Pool -- 55) JBAS010281: Started repl cache from web container
12:56:46,973 INFO  [org.jboss.as.clustering] (MSC service thread 1-1) JBAS010238: Number of cluster members: 2
12:56:47,044 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (MSC service thread 1-2) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
12:56:47,062 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (MSC service thread 1-2) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
12:56:47,063 INFO  [org.infinispan.configuration.cache.EvictionConfigurationBuilder] (MSC service thread 1-2) ISPN000152: Passivation configured without an eviction policy being selected. Only manually evicted entities will be passivated.
12:56:47,189 INFO  [org.jboss.web] (MSC service thread 1-2) JBAS018210: Registering web context: /mod_cluster-demo-server-1.2.0.Final
12:56:47,393 INFO  [org.jboss.as.server] (DeploymentScanner-threads - 2) JBAS018559: Deployed "mod_cluster-demo-server-1.2.0.Final.war"

After successful deployment, now lets try the web app, http://127.0.0.1/cluster/index.jsf.

Now to test the failover capability kill the server you was served for. And then hit http://127.0.0.1/cluster/index.jsf again.

No comments: