Friday, 6 September 2013

Apache Tomcat Clustering 2

                                                     Apache  Tomcat  Clustering

Apache 2 Configuration

Download mod_jk.so file for Apache 2 and put the file in the modules(\Program Files (x86)\Apache    
 Software  Foundation\Apache2.2\modules) 

           folder of Apache 2.
Edit httpd.conf file (Apache/conf) and at the very end of  the file include mod-jk.conf which


 is located.

Include conf/mod-jk.conf

Add mod-jk.conf and workers.properties file conf folder of Apache 2.

mod-jk.conf

######## JkModule ########
LoadModule jk_module modules/mod_jk.so
  
######## Set JKWorker File ########
JkWorkersFile "C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\workers.properties"

# Where to put jk logs
JkShmFile logs/mod_jk.shm   
  # Shared Memory File
JkLogFile logs/mod_jk.log                             

# Set the jk log level [debug/error/info]
JkLogLevel info  
JkLogStampFormat  "[%a %b %d %H:%M:%S %Y]"

# Mount point from context to a  Tomcat worker 
 JkMount  /jsp-examples loadbalancer

 JkMount /jsp-examples/* loadbalancer

Add workers.properties file in conf folder of Apache 2.

workers.perporties

# workers.properties.minimal -
#
# This file provides minimal jk configuration properties needed to
# connect to Tomcat.
#
# The workers that jk should create and work with
worker. list=loadbalancer 
# loadbalancer
#####################  
# apache-tomcat-6.1.28 for session replication
worker. Tomcat1.port=8109
worker. Tomcat1.host=10.254.0.117
worker. Tomcat1.type=ajp13
worker. Tomcat1.lbfactor=100

# apache-tomcat-6.2.28 for session replication 
worker. Tomcat2.port=8209
worker. Tomcat2.host=10.254.0.117
worker. Tomcat2.type=ajp13
worker. Tomcat2.lbfactor=1 
   
# Loadbalancing behaviour
worker.loadbalancer.type=lb

#LB for session replication
worker.loadbalancer.balanced_workers=one,two

#Sticky Bit  

worker.loadbalancer.sticky_session=1

Port number for each tomcat worker should match with respective AJP port number in

    server.xml file for each tomcat instance. 
Add index.jsp page in  jsp-examples folder  of  WEB-APP/ROOT in   

    both the Tomcats (Tomcat1 & Tomcat2).

Tomcat 1 : index.jsp

<%@ page session="true" %>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head><title>Test Jsp</title></head>
<body>
<table  width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr bgcolor="red"><td align="left" width="13%">Tomcat 1 Machine</td>
      <td width="87%">&nbsp;</td></tr>
<tr><td>Session ID : </td>
 <td><%=session.getId()%></td>
           </tr>
</table>
</body>

<html>

Tomcat 2 : index.jsp

<%@ page session="true" %>

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head><title>Test JSP</title></head>
<body>
<table  width="100%" border="0" cellspacing="0" cellpadding="0">
    <tr bgcolor="green"><td width="13%">Tomcat 2 Machine</td>
      <td  width="87%">&nbsb;</td>
      <tr><td> Session Id : </td><td><%=session.getId()%></td></tr>
</table>
</body>

</html>  

Start the Apache 2 server and Tomcat 1 and verify the clustering  example on port 81.

http://localhost:81/jsp-examples/index.jsp


Stop Tomcat 1 and start Tomcat 2 with Apache 2 server.

http://localhost:81/jsp-example/index.jsp







No comments:

Post a Comment

Spring 3 Rest Web Service Batch Update with JQuery & Ajax Integration

                      Spring 3  Rest Web Service Batch Update with JQuery & Ajax Integration Hi     In this blog I will describe the...