Tomcat cluster configuration notes (by quqi99)
Author: Zhang Hua published in: 2011-04-06
Copyright NOTICE: You can reprint, reprint, please be sure to hyperlink form to indicate the original source of the article and author information and this copyright notice (http://blog.csdn.net/quqi99)
h1 {margin-top:0.6cm; margin-bottom:0.58cm; line-height:200%; page-break-inside:avoid;} H1.western {font-family: "Times New Roman", serif; font-size:22pt;} H1.CJK {font-family: "Arial Unicode MS"; font-size:22pt; font-style:normal; font-weight:bold;} h1.ctl {font-size:22pt; font-weight:bold;} H1. Style-title-A +-fourth-western {font-family: "Times New Roman", serif; font-size:14pt; line-height:150%;} H1. Style-title +-fourth-CJK {font-family: Arial Unicode MS; font-style:normal; font-weight:bold; line-height:150%;} H1. Style-title-+-fourth-ctl {font-size:22pt; font-weight:bold; line-height:150%;} p {margin-bottom:0.21cm;} a:link {color:rgb (0, 0, 255);} I. Environmental description
1. server 3, one installation Apache service, two installs Tomcat
2. The use of various components and download the address:
Apache_2.2.11-win32-x86-no_ssl.msi
http://httpd.apache.org/download.cgi
Tomcat 6 Compact version
http://tomcat.apache.org/download-60.cgi
Apache's JK Connector (Windows version), as a module of Apache, the site also provides a way to use the configuration file
Mod_jk-1.2.28-httpd-2.2.3.so
http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/
3.IP Configuration
One installed Apache IP for 192.168.1.50, two installed tomcat IP for 192.168.1.24 and 192.168.1.52 (according to their respective circumstances assigned) two. Installation process
1. Install jdk6 (at least jdk5) on two machines with Tomcat installed
2. Configure the JDK installation path, add the JDK bin path to the environment variable path, and create a new environment variable java_home the installation path to the JDK
3. Install Tomcat and test that Tomcat is booting properly
http://192.168.1.24:8080
http://192.168.1.50:8080 Three. Load Balancing configuration Process
1. Install the Apache service on the 192.168.1.50 machine, my installation path defaults to: D:/program files/apache Software foundation/apache2.2
2. After the installation completes the test can start normally, http://192.168.1.50, as shown in the figure:
3. Copy the mod_jk-1.2.28-httpd-2.2.3.so to the Apache modules directory
2. Modify the Apache configuration file Httpd.cof, and at the end add the following passage:
LoadModule jk_module modules/mod_jk-1.2.28-httpd-2.2.3.so # load JK Connector
Jkworkersfile Conf/workers.properties # Set up a load-balanced configuration file that defines the balancing rule
Jklogfile Logs/mod_jk.log # Specify log file
Jkloglevel Debug # Specify Log Level
# configure Apache to distribute which requests to JK for equalization
Jkmount/*.jsp LoadBalancer
jkmount/test/* LoadBalancer
3. Modify two Tomcat profile Conf/server.xml files separately
Before modification:
<!--an Engine represents "entry point" (within Catalina) that processes
Every request. The Engine implementation for Tomcat stand alone
Analyzes the HTTP headers included with the request, and passes them
On to the appropriate host (virtual Host).
Documentation At/docs/config/engine.html-->
<!--should set Jvmroute to support load-balancing via AJP ie:
<engine name= "Catalina" defaulthost= "localhost" jvmroute= "jvm1" >
-->
<engine name= "Catalina" defaulthost= "localhost" >
After modification:
<!--an Engine represents "entry point" (within Catalina) that processes
Every request. The Engine implementation for Tomcat stand alone
Analyzes the HTTP headers included with the request, and passes them
On to the appropriate host (virtual Host).
Documentation At/docs/config/engine.html-->
<!--should set Jvmroute to support load-balancing via AJP ie:-->
<engine name= "Catalina" defaulthost= "localhost" jvmroute= "Node1" >
<engine name= "Catalina" defaulthost= "localhost" >
Modify the Jvmroute= "JVM1" to Jvmroute= "Node1" and jvmroute= "Node2" respectively.
4. Create the Workers.property file under the Apache Conf directory, and enter the following:
# Fine The communication channel
# All host names that define load balancing should correspond to the Jvmroute properties of the preceding Tomcat configuration file
# One of the LoadBalancer is a virtual host, responsible for load balancing, just as Apache itself
Worker.list=node1,node2,loadbalancer
# Node1 uses AJP to communicate with JK
worker.node1.port=8009 # Work port, no modification if not occupied
WORKER.NODE1.HOST=192.168.1.24 # Node1 address is localhost, if Tomcat enters the address of the server at another server
WORKER.NODE1.TYPE=AJP13 # Type
WORKER.NODE1.LBFACTOR=100 # Load Balancing factor
worker.node2.port=9009 # Work port, no modification if not occupied
worker.node2.host=192.168.1.52 #node2 The address of the server
WORKER.NODE2.TYPE=AJP13 # Type
WORKER.NODE2.LBFACTOR=100 # Load factor, the greater the value the more load JK distributes to this Tomcat
# define LoadBalancer type as load balancer (LB)
Worker.loadbalancer.type=lb
# defines the LoadBalancer for load balancing objects
Worker.loadbalancer.balanced_workers=node1,node2
Worker.loadbalancer.sticky_session=false
Worker.loadbalancer.sticky_session_force=false
5. In the two Tomcat installation directory of WebApps to establish the same application, my application named Test, in two application directory to establish the same Web-inf directory and page test.jsp page content is as follows
<%@ page language = "java" contentType = "text/html; Charset=iso-8859-1 "
pageencoding = "GBK"%>
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
< HTML >
< head >
< meta HTTP-EQUIV = "Content-type" Content = "text/html"; Charset=iso-8859-1 ">
< title > HelloApp </title >
< BODY >
<%
System.out.println ("Call test.jsp"); Print some trace data on the Tomcat console
%>
SessionID: <%= session.getid ()%>
</Body >
</HTML >
6. Restart the Apache server and two Tomcat servers, to this load balance has been configured to complete the test load balance: http://192.168.1.50/test/test.jsp, the normal operation has been established load balance four. Cluster configuration
1. Configure tomcat cluster under load balancing conditions
2. Modify the two tomcat configuration file Conf/server.xml separately, and modify the contents as follows
Before modification:
<!--
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
-->
After modification:
< Cluster ClassName = "Org.apache.catalina.ha.tcp.SimpleTcpCluster"
Channelsendoptions = "8" >
< Manager ClassName = "Org.apache.catalina.ha.session.DeltaManager"
Expiresessionsonshutdown = "false" Notifylistenersonreplication = "true"/>
< Channel ClassName = "Org.apache.catalina.tribes.group.GroupChannel" >
< membership
ClassName = "Org.apache.catalina.tribes.membership.McastService"
bind = "192.168.1.100" address = "228.0.0.4" port = "45564" frequency = "500"
Droptime = "3000"/>
< Receiver
ClassName = "Org.apache.catalina.tribes.transport.nio.NioReceiver"
Address = "Auto" port = "4000" Autobind = "selectortimeout" = "5000"
MaxThreads = "6"/>
< Sender
ClassName = "Org.apache.catalina.tribes.transport.ReplicationTransmitter" >
< transport
ClassName = "Org.apache.catalina.tribes.transport.nio.PooledParallelSender"/>
</Sender >
< Interceptor
ClassName = "Org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/>
< Interceptor
ClassName = "Org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor"/>
</Channel >
< Valve ClassName = "Org.apache.catalina.ha.tcp.ReplicationValve" filter = ""/>
< Valve ClassName = "Org.apache.catalina.ha.session.JvmRouteBinderValve"/>
<