You will need to configure both Apache and Tomcat for this purpose. Let us assume you want to load balance two Tomcat Servers against an Apache instance. Apache, first tomcat, second tomcat, all can be on the same machine(hardware) OR they can be in three different machines (each on its own); this configuration will work.
The below mentioned configuration shows all three running on the same host(myhost.mycompany.com). (You must install tomcat twice ofcourse in different directories, so that you have two tomcats, ofcourse since they are on the same host both tomcats must run on different http ports, say first one on 8080, and second one on 9090. This config is present in <Tomcat_Home>/conf/server.xml file).
info=Scoreboard. Requried for reconfiguration and status with multiprocess servers.
# Defines a load balancer named lb. Use even if you only have one machine.
noWorkersMsg=Server Busy please retry after some time.
# Example socket channel, override port and host.
# Map the Tomcat webapp to the Web server uri space
info=Status worker, displays runtime information
info=The Tomcat /jkstatus handler
———end of file——————-
The only file you will have to modify here is:<Tomcat_Home>/conf/server.xml, yes on both the tomcat servers you are trying to load balance. You have to set up connector port (8009 on first tomcat, 9009 on second tomcat), and jvmRoute (server1 on first tomcat, server2 on second tomcat). You will notice that these values you had defined earlier in workers2.properties file.
So, here is how you would update on first tomcat, the file:<Tomcat_Home>/conf/server.xml
So, AJP 1.3 Connector to be defined as follows(if it is commented out, uncomment it). The relevant line should look like this:
<Connector port=”8009″ protocol=”AJP/1.3″ protocolHandlerClassName=”org.apache.jk.server.JkCoyoteHandler” redirectPort=”8443″ />
jvmRoute is set up as follows:
<Engine name=”Catalina” defaultHost=”localhost” jvmRoute=”server1″>
Similar changes you must make to the second tomcat.
You are all set.
Tested on: Apache 2.2.6, Tomcat 6, Linux