Search code examples
apachetomcatcluster-computingload-balancingmod-jk

Apache HTTP / mod_jk only working when one worker is active


I added the following mod-jk.conf file and include it in httpd.conf:

LoadModule jk_module modules/mod_jk.so
JkWorkersFile conf/workers.properties
JkLogFile logs/mod_jk.log
JkLogLevel info 
JkLogStampFormat  "[%a %b %d %H:%M:%S %Y]"
JkOptions +ForwardKeySize +ForwardURICompat -ForwardDirectories
JkRequestLogFormat "%w %V %T"

JkMount /MyApp/* loadbalancer
JkShmFile logs/jk.shm 

JkMount /status status

I also added the following workers.properties file:

worker.list=loadbalancer,status

worker.node1.port=8009
worker.node1.host=10.1.4.49
worker.node1.type=ajp13
worker.node1.lbfactor=1 

worker.node2.port=8009
worker.node2.host=10.1.4.51
worker.node2.type=ajp13
worker.node2.lbfactor=1

worker.loadbalancer.type=lb
worker.loadbalancer.balance_workers=node1,node2

worker.status.type=status

When I have two workers running the http server connects to the tocat server/app but it says the connection to the server is closed. However, if I take out one of the workers (doesn't matter which one) I can connect to the tomcat server/app just fine.

For whatever reason my load balancer is only working when there is 1 active worker.


Solution

  • When using a load balancer with sticky sessions, you need to setup each tomcat with the correct jvmRoute that matches what you have defined in the workers.properties file. In my case I have workers named node1 and node2 so I should expect to find

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="node1">
    

    on the tomcat at address 10.1.4.49 and

    <Engine name="Catalina" defaultHost="localhost" jvmRoute="node2">
    

    on the tomcat at address 10.1.4.51