Download Apache 2 (I used 2.2.22 without crypto for windows) from http://httpd.apache.org/download.cgi
Install Apache 2 (I used localhost as the domain)
Add the following entry to httpd.conf located under C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf
LoadModule jk_module modules/mod_jk.so
<IfModule jk_module>
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info
JkMountFile conf/uriworkermap.properties
JkMount /jkmanager/* jkstatus
</IfModule>
#Enable the JK manager access from localhost only
<Location /jkmanager/>
JkMount jkstatus
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Location>
Place the file workers.properties in the same location with the follwoing contents:
#
# This file provides minimal jk configuration properties needed to
# connect to Tomcat.
#
# The workers that jk should create and work with
#
worker.list=loadbalancer,jkstatus
#
# Define the servers in our cluster
#
worker.tomcat1.type=ajp13
worker.tomcat1.host=localhost
worker.tomcat1.port=8009
worker.tomcat1.lbfactor=1
worker.tomcat2.type=ajp13
worker.tomcat2.host=localhost
worker.tomcat2.port=8010
worker.tomcat2.lbfactor=1
#
# Defining a load balancer
#
worker.loadbalancer.type=lb
#worker.loadbalancer.balance_workers=tomcat1
worker.loadbalancer.balance_workers=tomcat1,tomcat2
worker.loadbalancer.sticky_session=false
#
# Define status worker
#
worker.jkstatus.type=status
Now create the file uriworkermap.properties in the same directory and add the follwoing contents:
# This file provides sample mappings for example wlb
# worker defined in workermap.properties.minimal
# The general syntax for this file is:
# [URL]=[Worker name]
/*.*=loadbalancer
Now go to the Tomcat and change the configuration in server.xml (e.g. under C:\Tools\apache-tomcat-6.0.35worker1\conf):
The AJP connector should add a redirect port to the HTTP Connector that is already configured in the server.xml:
<Connector port="8009" protocol="AJP/1.3" redirectPort="8080" />
The HTTP connector should like similar to this:
<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />
Also specify the jvmRoute for the Engine:
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
For the second tomcat (worker2) when also running on localhost, you should increase the following port numbers by 1:
- AJP Connector (from 8009 to 8010 and redirectPort from 8080 to 8081)
- HTTPConnector (from 8080 to 8081)
- Server Port from (8005 to 8006)
and of course you should specify tomcat2 as jvmRoute in the engine.
On the second worker node (i.e. on the second tomcat) delete tomcat.gif under webapps/ROOT and rename tomcat-power.gif to tomcat.gif.
Now start both Tomcats and the Apache 2 server. Then start your browser and point it to localhost/tomcat.gif.
On each refresh you should see the two different tomcat pictures, alternating.
Under http://localhost/jkmanager/ you can find a management console for the tomcat workers. Here you can for example stop a tomcat from receiving requests from the loadbalancer and then start it again.