Featured Post

APAHE TOMAT LUSTERING

Hi Guys ,

Today I am going to discuss about Tomcat Clustering . Before understanding
this you should have good understanding of Tomcat and Apache Server and
its installation and also some concepts of J2EE servers instances and
clusters . If you want more information you can just my blog previous post
which says about the Tomcat Apache integration visit that info at :

http://sitarampv.blogspot.com



Installation of Jdk


Java can be downloaded from sun and installed.


Sun provides different executable file for Windows and Linux operating
system version. Sun provide JDK for Linux in .bin or tar.gz format, and
for Windows .exe format.


After downloading file from sun, install JDK simple double click or
through command prompt











Installation of apache web server for load balancing and load sharing


Download apache and install on same system for vertical tomcat clustering.





After installation of apache, we need to do some configuration


Installation of tomcat


Download tomcat 6 Make three copy of tomcat If want to make three tomcat
clustering system then need three copies of tomcat
Cluster 1 tomcatA
Cluster 2 tomcatB
Cluster 3 tomcatC


Horizontal Clustering
horizontal clustering fundamental


Vertical Clustering
vertical clustering fundamental
If need three cluster then need to make three instance of tomcat
tomcat installation steps

Installation is simple as we install tomcat normally. In this tomcat
clustering we are going for vertical tomcat clustering. So all tomcat
instance is in single server. If you want (real world clustering) that is
also much simpler. Then work with ip instead of localhost, I am also
including examples for download


Tomcat server.xml configuration
1. Vertical tomcat clustering( on single machine)
2. Horizontal tomcat clustering( on multiple machine)


Vertical tomcat clustering example


open Tomcat -> Conf -> server.xml


Edit highlighted and can give port which we can required


1 First tomcatA









































































2 Second tomcatB









































































3 Third tomcatC









































































Horizontal tomcat clustering or tomcat clustering on different machine
system


If you want to do horizontal tomcat clustering then you don't need to
change in ports


Just left ports unchanged e.g
1.
2.


3.


4. Add jvmRoute





5. Uncommented clustering tag





Add distributed tag in web.xml


Next step to do add distributed tag in web.xml to switching session among
the tomcat clustering instance


Make any application, e.g we are making cluster as application folder in
webapps


1. TomcatA - > webapps - > cluster -> WEB-INF -> web.xml
2. TomcatB - > webapps - > cluster -> WEB-INF -> web.xml
3. TomcatC - > webapps - > cluster -> WEB-INF -> web.xml


Add in all three web.xml file













Install mod_jk in module


Mod_jk is connector that communicates with apache web server and tomcat. We
need to download and copy that connector in module folder of apache
http://tomcat.apache.org/connectors-doc/ we are using latest connector of
mod_jk


Make mod_jk.log file in logs folder otherwise apache will throw error





Edit in httpd.conf


Open apache -> httpd.conf


Open in any text editor and add


LoadModule jk_module modules/mod_jk-apache-2.2.4.so
JkWorkersFile "C:\cluster\Apache\conf\workers.properties"
JkLogFile "logs/mod_jk.log"
JkLogLevel error
JkMount /cluster loadbalancer
JkMount /cluster/* loadbalancer


Worker.properties file


Make a file with name of workers.properties in conf folder. This file tells
properties of all tomcat instances. We have to specify all tomcat
properties here. Apache will forword request to tomcat through this file


Vertical tomcat clustering this file like


workers.tomcat_home=/tomcatA
workers.java_home=$JAVA_HOME
ps=/
worker.list=tomcatA,tomcatB,tomcatC,loadbalancer





worker.tomcatA.port=8109
worker.tomcatA.host=localhost
worker.tomcatA.type=ajp13
worker.tomcatA.lbfactor=1





worker.tomcatB.port=8209
worker.tomcatB.host=localhost
worker.tomcatB.type=ajp13
worker.tomcatB.lbfactor=1


worker.tomcatC.port=8309
worker.tomcatC.host=localhost
worker.tomcatC.type=ajp13
worker.tomcatC.lbfactor=1


worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcatA,tomcatB,tomcatC
worker.loadbalancer.sticky_session=1


for horizontal tomcat clustering


workers.tomcat_home=/tomcatA
workers.java_home=$JAVA_HOME
ps=/
worker.list=tomcatA,tomcatB,tomcatC,loadbalancer





worker.tomcatA.port=8009
worker.tomcatA.host=192.168.1.1
worker.tomcatA.type=ajp13
worker.tomcatA.lbfactor=1





worker.tomcatB.port=8009
worker.tomcatB.host=192.168.1.2
worker.tomcatB.type=ajp13
worker.tomcatB.lbfactor=1


worker.tomcatC.port=8009
worker.tomcatC.host=192.168.1.3
worker.tomcatC.type=ajp13
worker.tomcatC.lbfactor=1


worker.loadbalancer.type=lb
worker.loadbalancer.balanced_workers=tomcatA,tomcatB,tomcatC
worker.loadbalancer.sticky_session=1





lbfactor properties define for load balancing factor, restrict number of
request to send particular tomcat instance
e.g
worker.tomcatC.lbfactor=100
increase and decrease request to this tomcatC instance


Restart apache, tomcatA, tomcatB, tomcatC


Check clustering if apache start properly, It is fine without any errors
otherwise check problems,basically mod_jk problems come. So download
different mod_jk for your machine. Start all tomcats, tomcatA, tomcatB, and
tomcatC. If all tomcats is started this means tomcat is working fine.


Open test.jsp on browser and check session id. Check which tomcat on
test.jsp is running tomcatB or tomcatC. Close that tomcat, reload test.jsp.
Check session id,if session id is same. Then tomcat clustering is working
fine.





Test jsp file


Make test.jsp in cluster folder of webapps


tomcatA


<% session.setAttribute("a","a"); %>



tomcatB <% session.setAttribute("a","a"); %>
TomcatA Machine  
Session ID : <%=session.getId()%>
TomcatB Machine  
Session ID : <%=session.getId()%>
TomcatC <% session.setAttribute("a","a"); %>
TomcatC Machine  
Session ID : <%=session.getId()%>

Enter you DOB ,Time and Place

SEO Schemes

Comments

Popular posts from this blog

[Inside AdSense] Understanding your eCPM (effective cost per thousand impress...