Configure load balancing based on MOD_JK
MOD_JK Articles
1, in order to avoid users directly access to the back-end Tomcat instance, affect the effect of load balancing, it is recommended to disable the http/1.1 connector on each instance of Tomcat 7.
2. Add the Jvmroute parameter to the engine for each Tomcat 7 instance and set the global unique identifier for the current engine. as shown below. It should be noted that the Jvmroute value of each instance cannot be the same.
<engine name= "Standalone" defaulthost= "localhost" jvmroute= "Tomcata" >
Then go to configure Apache, modify/etc/httpd/extra/httpd-jk.conf for the following content:
LoadModule Jk_module modules/mod_jk.so
Jkworkersfile/etc/httpd/extra/workers.properties
Jklogfile Logs/mod_jk.log
Jkloglevel Debug
Jkmount/* Lbcluster1
Jkmount/jkstatus/stat1
Edit/etc/httpd/extra/workers.properties and add the following:
Worker.list = LBCLUSTER1,STAT1
Worker. Tomcata.type = ajp13
Worker. Tomcata.host = 172.16.100.1
Worker. Tomcata.port = 8009
Worker. Tomcata.lbfactor = 5
Worker. Tomcatb.type = ajp13
Worker. Tomcatb.host = 172.16.100.2
Worker. Tomcatb.port = 8009
Worker. Tomcatb.lbfactor = 5
Worker.lbcluster1.type = lb
Worker.lbcluster1.sticky_session = 1
Worker.lbcluster1.balance_workers = Tomcata, TOMCATB
Worker.stat1.type = Status
Example:
10.0.0.53/54 is a tomcat machine, 10.0.0.91 is a httpd load.
Installing JDK
[Root@nfs-web2 local]# RPM-IVH jdk-7u9-linux-x64.rpm
Preparing ... ########################################### [100%]
1:JDK ########################################### [100%]
Install Apa-tomat
[Root@nfs-web2 local]# tar XF apache-tomcat-7.0.67.tar.gz-c/usr/local/
[Root@nfs-web2 local]# LN-SV apache-tomcat-7.0.67 Tomcat
' Tomcat '-> ' apache-tomcat-7.0.67 '
[Root@nfs-web2 bin]# cat/etc/profile.d/tomcat.sh
Export Catalina_home=/usr/local/tomcat
Export path= $CATALINA _home/bin: $PATH
[Root@nfs-web2 bin]# cat/etc/profile.d/java.sh
Export Java_home=/usr/java/latest
Export path= $JAVA _home/bin: $PATH
Tomcat's INIT.D startup script
[Root@nfs-web2 bin]# Cat/etc/init.d/tomcat
#!/bin/sh
# Tomcat init script for Linux.
#
# chkconfig:2345 96 14
# description:the Apache Tomcat servlet/jsp container.
Java_home=/usr/java/latest
Catalina_home=/usr/local/tomcat
Export Java_home Catalina_home
Case is in
Start
exec $CATALINA _home/bin/catalina.sh start;;
Stop
exec $CATALINA _home/bin/catalina.sh stop;;
Restart)
$CATALINA _home/bin/catalina.sh Stop
Sleep 2
exec $CATALINA _home/bin/catalina.sh start;;
*)
echo "Usage: ' basename $ ' {Start|stop|restart} '
Exit 1
;;
Esac
[Root@nfs-web2 bin]#
[Root@nfs-web2 local]# chmod +x/etc/init.d/tomcat
[Root@nfs-web2 local]# chkconfig--add Tomcat
Two different test pages are available on two nodes:
10.0.0.53
[Root@nfs-web2 webapps]# Cd/usr/local/tomcat/webapps
[Root@nfs-web2 webapps]# mkdir TestApp
[Root@nfs-web2 webapps]# CD testapp/
[Root@nfs-web2 testapp]# mkdir-p Web-inf/{classes,lib}
[Root@nfs-web2 webapps]# Vim index.jsp
Demo effect, in a context (such as/test) on Tomcata, provide the following page
<%@ page language= "java"%>
<body>
<table align= "centre" border= "1" >
<tr>
<td>session id</td>
<% Session.setattribute ("abc", "abc"); %>
<td><%= Session.getid ()%></td>
</tr>
<tr>
<td>created on</td>
<td><%= session.getcreationtime ()%></td>
</tr>
</table>
</body>
10.0.0.54
[Root@nfs-web1 webapps]# Cd/usr/local/tomcat/webapps
[Root@nfs-web1 webapps]# mkdir TestApp
[Root@nfs-web1 webapps]# CD testapp/
[Root@nfs-web1 testapp]# mkdir-p Web-inf/{classes,lib}
[Root@nfs-web1 webapps]# Vim index.jsp
Demo effect, in a context (such as/test) on TOMCATB, provide the following page
<%@ page language= "java"%>
<body>
<table align= "centre" border= "1" >
<tr>
<td>session id</td>
<% Session.setattribute ("abc", "abc"); %>
<td><%= Session.getid ()%></td>
</tr>
<tr>
<td>created on</td>
<td><%= session.getcreationtime ()%></td>
</tr>
</table>
</body>
MOD_JK 10.0.0.91
[Root@nginx-proxy2 modules]# cat/etc/httpd/conf.d/mod_jk.conf
LoadModule Jk_module modules/mod_jk.so
Jkworkersfile/etc/httpd/conf.d/workers.properties
Jklogfile Logs/mod_jk.log
Jkloglevel Notice
Jkmount/* LBCA
Jkmount/jkstatus/stata
[Root@nginx-proxy2 modules]# Cat/etc/httpd/conf.d/workers.properties
Worker.list=lbca,stata
Worker. tomcata.port=8009
Worker. tomcata.host=10.0.0.53
Worker. Tomcata.type=ajp13
Worker. Tomcata.lbfactor=1
Worker. tomcatb.port=8009
Worker. tomcatb.host=10.0.0.54
Worker. Tomcatb.type=ajp13
Worker. Tomcatb.lbfactor=1
Worker.lbca.type=lb
Worker.lbca.sticky_session=0, don't keep it.
Worker.lbcA.balance_workers = TOMCATA,TOMCATB
Worker.statA.type = Status
[Root@nginx-proxy2 modules]#