In Win7, use Apache to load-balance tomcat, with the following components and versions:
Two Tomcat v 7.0.57
An Apache v 2.2.14
One MOD_JK v 1.2.33 (for Windows i386 httpd 2.2.x): http://archive.apache.org/dist/tomcat/tomcat-connectors/jk/binaries /windows/tomcat-connectors-1.2.33-windows-i386-httpd-2.2.x.zip
Configuration method:
1. Install Apache (slightly)
In the installation directory (conf directory) add another folder: CONF.D, under this folder, edit the following file:
Mod_jk.conf
# Load mod_jk moduleloadmodule jk_module modules/mod_jk.so# Where to find Workers.propertiesjkworkersfile conf.d/workers . properties# Where to put JK Logsjklogfile logs/mod_jk.log# Set The JK log level [Debug/error/info]jkloglevel info# Select The log Formatjklogstampformat "[%a%b%d%h:%m:%s%Y]" # jkoptions indicate to send SSL KEY size,jkoptions +forwardkeysi Ze +forwarduricompat-forwarddirectories# Jkrequestlogformat Set the request Formatjkrequestlogformat "%w%V%T" # Send Ser Vlet for Context/examples to worker named ajp13#jkmount/servlet/* controller# Send JSPs for Context/examples to worker Named Ajp13jkmount/* Controller
This configuration Jkmoun/* Controller indicates that all Apache requests are turned to Tomcat. Then edit a file as follows:
Workers.properties
# # workers.properties# # list the workers by nameworker.list=controllerworker.controller.type= Lbworker.controller.sticky_session=1worker.controller.error_escalation_time=0worker.controller.max_reply_ timeouts=10 # localhost Server #------------------------worker.jvm1.reference=worker.templateworker.jvm1.port= 8019 #对应tomcat AJP Port worker.jvm1.host=localhostworker.jvm1.lbfactor = 1 #权重worker. Jvm1.activation=a # Localhos T Server------------------------worker.jvm2.reference=worker.templateworker.jvm2.port=8029worker.jvm2.host= Localhostworker.jvm2.lbfactor = 1worker.jvm2.activation=a worker.template.type=ajp13 worker.template.so Cket_connect_timeout=5000worker.template.socket_keepalive=trueworker.template.ping_mode=aworker.template.ping_ timeout=10000worker.template.connection_pool_minsize=0worker.template.connection_pool_timeout= 600worker.template.reply_timeout=300000worker.template.recovery_options=3 worker.controller.balance_workers= JVM1, jvm2# corresponds to two tomcatJvmroute
Then, edit conf/httpd.conf, adding the following line at the end:
Include conf.d/mod_jk.conf
Copy the mod_jk.so downloaded above to the Apache installation directory modules below.
2. Configure Tomcat
Modify the Server.xml of the first Tomcat as follows:
...<ServerPort= "8015"shutdown= "SHUTDOWN">...<ConnectorPort= "8091"Protocol= "http/1.1"ConnectionTimeout= "20000"Redirectport= "8443" />....<ConnectorPort= "8019"Protocol= "ajp/1.3"Redirectport= "8443" />...<Enginename= "Catalina"Defaulthost= "localhost"Jvmroute= "JVM1">...<!----> <ClusterClassName= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>...
Similarly, modify the configuration of the second tomcat:
...<ServerPort= "8025"shutdown= "SHUTDOWN">...<ConnectorPort= "8092"Protocol= "http/1.1"ConnectionTimeout= "20000"Redirectport= "8443" />....<ConnectorPort= "8029"Protocol= "ajp/1.3"Redirectport= "8443" />...<Enginename= "Catalina"Defaulthost= "localhost"Jvmroute= "JVM2">...<!----> <ClusterClassName= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>...
The last two Tomcat Web. XML, add a line <distributable/> to the following location:
... < distributable /> </ Web-app >
Launch Apache, and two Tomcat, can be accessed by Apache listening port, Tomcat's listening port is ignored, such as:
http://localhost or http://127.0.0.1
Tomcat 7 load Balancing with MOD_JK