Monday 13 May 2013

Session Replication with Mod_cluster in jboss as 7.1


Using mod_cluster with JBoss AS 7.1 cluster

In this blog we will see how to use mod_cluster with jboss as 7.1.
The mod_cluster integration is done via the modcluster subsystem which is present in standalone configuration file. 
For working with mod_cluster we need to configure it in both Apache Web Server and jboss as 7.
This will help in session replication in case of jboss as 7



Apache side configuration

  1. Download the required binaries of mod_cluster for your OS from below link,http://www.jboss.org/mod_cluster/downloads/1-1-0.html
  2. Copy following .so files to your “<Apache_Home>/modules” folder.
mod_proxy.so
mod_proxy_ajp.so
mod_slotmem.so
mod_manager.so
mod_proxy_cluster.so
mod_advertise.so
3.  Edit your httpd.conf (i.e. /conf/http.conf) and add following lines
   to it.However these setting is a sample, you might have to make 
   changes as per your own environment.
############### mod_cluster Setting###############
LoadModule slotmem_module modules/mod_slotmem.so
LoadModule manager_module modules/mod_manager.so
LoadModule proxy_cluster_module modules/mod_proxy_cluster.so
LoadModule advertise_module modules/mod_advertise.so
<VirtualHost 10.10.10.10:80>
  <Directory />
         Order deny,allow
         Allow from all
  </Directory>
  <Location /mod_cluster_manager>
         SetHandler mod_cluster-manager
         Order deny,allow
         Allow from all
  </Location>
  KeepAliveTimeout 60
  MaxKeepAliveRequests 0
  ManagerBalancerName testcluster
  AdvertiseFrequency 5
</VirtualHost>
############### mod_cluster Setting###############

  where 10.10.10.10:80 is IP:Port on which apache is running

NOTE:
We need to Comment Out the following module mod_proxy_balancer.so  in “httpd.conf” file, this is been done because we are now using mod_proxy_cluster.so instead of mod_proxy_balancer.so

#LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
  1. Restart Apache.



JBoss side configuration

Now we will see changes we need to make to jboss side

Standalone

  1. First we need to create a jboss cluster as explained in :http://jboss-as-7-abhishekmathur.blogspot.in/2013/05/jboss-as-71-clustering.html
  2. Give a unique name in the server element,(present in standalone.conf file) as shown below .
standalone-node1
      <server name="standalone-node1" xmlns="urn:jboss:domain:1.2">
standalone-node2
      <server name="standalone-node2" xmlns="urn:jboss:domain:1.2">
3.        Now we need to add the instance-id attribute in web subsystem as shown below in both the standalone nodes.
<subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host" instance-id="${jboss.node.name}" native="false">
    <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>
    <connector name="ajp" protocol="AJP/1.3" scheme="http" socket-binding="ajp"/>
    .
    .
    .
</subsystem>
 
4.  Last you just have to add the proxy-list in the attribute in  
mod-cluster-config of modcluster subsystem, which would be having 
IP Address and Port on which your Apache server is running so that 
JBoss server can communicate with it, as shown below in both the
standalone nodes.
 
<subsystem xmlns="urn:jboss:domain:modcluster:1.0">
    <mod-cluster-config advertise-socket="modcluster" proxy-list="10.10.10.10:80">
    .
    .
    .
    </mod-cluster-config>
</subsystem>
 
where 10.10.10.10:80 is the Ip:Port of the Apache web server.
 Now start the Apache web and jboss as server and deploy application in both,
to see the desired result 

Jboss as 7.1 : Clustering



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.

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
/home/user/jboss-as-7.1.1.Final/standalone-node1
/home/user/jboss-as-7.1.1.Final/standalone-node2

2.      Now you would have to run the below command to start both the JBoss node in a cluster
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
 
Where 10.10.10.10 is the IP of machine.
 
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 
·         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

3.      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 .
Eg. < distributable />
4.       Now keep the War in both the standalone / deployment  folder and start the server.

Cluster on different boxes

1.       After unzipping JBoss AS 7 in both the boxes then you can create just a single copies of standalone folder in respective boxes
Box-1 : /home/user/jboss-as-7.1.1.Final/standalone-node1

Box-2 : /home/user/jboss-as-7.1.1.Final/standalone-node2
 
2.      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 
  1. Both the nodes should have same multicast address
  2. Both the nodes should have different node names
  3. Both the nodes should be running on the IP_ADDRESS or HOST_NAME of the box
Node1 on Box-1
./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

Where 10.10.10.10 is the IP of machine
Node2 on Box-2
./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

Where 20.20.20.20 is the IP of machine
Now make the changes in the Application as mention above and start the server.