1. Apache Load Balancing :
Basic SW Requirements :
1. java
2. Tomcat
3. Apache web server
4. mod_jk
Pre-Check :
1. Java home/path settings in environment
2. Test and ensure tomcat instance / httpd [Apache web server] is running .
Basic Configuration:
1. enable mod_jk in apache configuration file . Ensure in below paths and files :
1. /etc/httpd/modules (or) /usr/lib64/httpd/modules/
2./usr/libexec/
2. need to create the following files to integrate tomcat app's with apache httpd
server under /etc/httpd/conf.d/.
1. worker.properties
2.uriworkermap.properties
3. mod_jk.conf
worker.properties file format :
worker.list=lb,status
worker.tomcat1.port=8009
worker.tomcat1.host=localhost
worker.tomcat1.type=ajp13
worker.tomcat1.lbfactor=1
worker.tomcat1.redirect=tomcat2
worker.tomcat2.port=8079
worker.tomcat2.host=localhost
worker.tomcat2.type=ajp13
worker.tomcat2.lbfactor=1
worker.tomcat2.redirect=tomcat1
worker.lb.type=lb
worker.lb.balance_workers=tomcat1,tomcat2
worker.lb.sticky_session=True
worker.lb.sticky_session_force=True
worker.status.type=status
worker.localhost.host=localhost
Note :
1. while enabling LB we need to declare lb worker in worker.list [It is not workers.list]
2. Change the native AJP port as per the infrastructure security policy in tomcat server.xml
files . And ensure the tomcat is running on that port while running .
[netstat -nap |grep java]
3. update the details for each instances as per the above format .
4. Finally declare loadbalancer with the above attributes [balance_workers[it is not
balance_worker],sticky_session.sticky_session_force ]
5. declaring the status worker to check the status of Load Balancing
2. mod_jk.conf configuration:
LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf.d/worker.properties
JkMountFile conf.d/uriworkermap.properties
JkLogFile /var/log/mod_jk.log
JkLogLevel info
JkLogStampFormat "[%a %b %d %H:%M:%S %Y] "
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"
JkShmFile logs/jk.shm
Note :
1. 1st line including the mod_jk.so with httpd
2. JkWorkersFile Including the worker.properties file
3. JkMountFile we are declaring the worker and mounting point details .
4. 4th line saying the log file location
5. Other attributes saying the log formates and final line is about memory details .
uriworkermap.properties file :
#/admin/*=lb
#/manager/*=lb
#/jsp-examples/*=lb
#/servlets-examples/*=lb
#/examples/*=lb
#/jk-manager=status
/* =lb
/status =status
Note :
Declaring the mount points with the specific worker details
We are using with load balancing so we can declare with loadbalancer worker [lb] .
Loadbalancer worker will take care the distribution of the load and session status
Tomcat configuration[server.xml]:
1. we need to change the native ports in tomcat server.xml file as per the
requirements
[We have used here 8009 & 8079]
ex :
<Connector port="8009" protocol="AJP/1.3" redirectPort="8473" />
in tomcat1
<Connector port="8079" protocol="AJP/1.3" redirectPort="8473" />
in tomcat2
2. change the jvmRoute name as per the workers declaration.
Ex:
in tomcat1
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
in tomcat1
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
3. Final steps :
1. Once done all the configuration as per the above details start the tomcat instances
and apache server . Check the service status and log details for the information .
2. To verify the session status in load balancing Please create index.jsp with
identification [page color/ content different ] in $TOMCAT_HOME/webapps/ROOT/
3. access the server in two different session and confirm the load balance status. It
need to handle the sessions separately.
K.KarthiKeyan