Search code examples
apacheload-balancingfailovermod-jk

Apache mod_jk load balancing not working but failover works


I am trying to configure an Apache load balancing solution with mod_jk. The clustering works but not load balancing.

I have Apache httpd 2.2 server running on my laptop. I have two VMWare Virtual Machine Guest Operating systems. All three are windows. The VMware machines hosts Apache Tomcat Server serving the web application. I have configured httpd.conf file with mod_jk and a workers properties file with the worker information. I am able to access my web application using the URL : http://localhost/Web-application . If I stop one server then the application is served from the other. However not both at the same time. Some extracts are below:

httpd.conf file:

LoadModule jk_module modules/mod_jk.so 
JkWorkersFile conf/workers.properties
JkLogFile "logs/mod_jk.log" 
JkLogLevel info
JkMount /MovieBooking loadbalancer
JkMount /MovieBooking/* loadbalancer

workers.properties File

workers.tomcat_home=/worker1
workers.java_home=$JAVA_HOME
worker.list=loadbalancer,jkstatus,worker1,worker2

 #Declare Tomcat server workers 1 through n

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=worker1,worker2
worker.loadbalancer.sticky_session=1

worker.worker1.type=ajp13
worker.worker1.host=192.168.200.244
worker.worker1.port=8109
worker.worker1.lbfactor=1

worker.worker2.type=ajp13
worker.worker2.port=8109
worker.worker2.host=192.168.200.243
worker.worker2.lbfactor=1

worker.jkstatus.type=status

I have also set jvmroute in the server.xml files on these servers:

Server.xml

<Engine name="Catalina" defaultHost="localhost" jvmRoute="worker1">         
     <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

if any more extracts are required I can upload them


Solution

  • The way you configured load balancing (looking ok to me) with sticky sessions means that once a session is created, subsequent requests will be directed to the same Tomcat instance. You can recognize this by looking at the session cookie values which should be appended with .worker1 or .worker2. This postfix is used by the Apache HTTPD to decide which Tomcat instance to send an incoming request to.

    If there is no session cookie, requests should be distributed among the available Tomcats in a round-robin fashion. So in order to test load-balacing, you will typically need several browser instances holding different session cookies. Or try setting sticky_session=false to see all requests forwarded round-robin style.