简体   繁体   中英

Apache mod_jk load balancing issue

I've two applications ( app1 and app2 ) was deployed on two tomcats ( tomcat1 and tomcat2 ), other application ( sso ) was deployed on other tomcat ( tomcat3 ) and I've installed apache web server with mod_jk with the following configurations but getting 404 error for sso when redirecting from app1 to sso . For two applications ( app1 and app2 ) there is no issue but for sso getting 404 error.

workers.properties

worker.list=balancer

#Define Node1
worker.tomcat1.type=ajp13
worker.tomcat1.port=8008
worker.tomcat1.host=abc.com

#Define Node2
worker.tomcat2.type=ajp13
worker.tomcat2.port=9009
worker.tomcat2.host=abc.com

#Define Node3
worker.tomcat3.type=ajp13
worker.tomcat3.port=8009
worker.tomcat3.host=abc.com

#Load-balancing behaviour
worker.balancer.type=lb
worker.balancer.balance_workers=tomcat1,tomcat2,tomcat3

httpd.cnf:

JkMount /app* balancer
JkMount /sso* balancer

And in each tomcat server.xml contains below tag with different ports

<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

Apache: 2.4.41 Tomcat: 8.0 mod_jk: 1.2.46 JDK 1.8

It's my local setup. Am I missing any thing. I'm new to tomcat clustering any one please help me out.

The three Tomcat servers cannot act as a cluster apiece, as there are two apps (app1 & app2) running in two tomcat (tomcat1 & tomcat2) and ther third one sso running in tomcat3.

What is happening here using your workers.properties when redirecting from app1 to even app2 or sso is that mod_jk is redirecting the request to the tomcat where you had been redirected before, due to session stickyness. So that it works like a charm when been redirecting from app1 to app2, as both apps are deployed to tomcat1 and tomcat2, but you receive a HTTP 404 when being redirected to sso, as your jsessionid cookie is bind to tomcat1 or tomcat2 making it redirect the sso request to the same tomcat, and receiving a 404 just because sso is not deployed there.

With that deployment plan, you should configure a balancer just for tomcat1 and tomcat2 and leave tomcat3 out of the balancer, acting as a standalone tomcat. This could be done this way:

worker.list=balancer,tomcat3

#Define Node1
worker.tomcat1.type=ajp13
worker.tomcat1.port=8008
worker.tomcat1.host=abc.com

#Define Node2
worker.tomcat2.type=ajp13
worker.tomcat2.port=9009
worker.tomcat2.host=abc.com

#Define Node3
worker.tomcat3.type=ajp13
worker.tomcat3.port=8009
worker.tomcat3.host=abc.com

#Load-balancing behaviour
worker.balancer.type=lb
worker.balancer.balance_workers=tomcat1,tomcat2

This way all should work, getting rid of HTTP 404 errors

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM