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 

2 comments:

  1. thx dear. really help full

    ReplyDelete
  2. Thanks for the documentation. I could able to setup the clustered envt and able to replicate the session with simple JSP's. But when I implement the session in Struts2, session is not replicating. Could you please help me on this.

    Thanks in advance!!!

    ReplyDelete