简体   繁体   中英

Tomcat Load Balancing

I have created a load balancing scenario in my machine and the same works fine. However, I am stuck at one simple issue and request help on the same.

I have two tomcat workers - worker1 and worker2. I also have a loadbalancer called balancer. workers.properties file has been created as follows -

  • workers.tomcat_home="MyTomcatDirectory"
  • workers.java_home="MyJDKDirectory"
  • worker.list=tomcat1,tomcat2
  • worker.list=balancer
  • 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=8019
  • worker.tomcat2.lbfactor=1
  • worker.balancer.type=lb
  • worker.balancer.balance_workers=tomcat1,tomcat2
  • worker.balancer.method=B`

Now, I have a webapp say webapp1 which is used by endusers extensively. I hence want that all the user requests for webapp1 should be handled by worker1. For this I have added the below lines in httpd.conf file in my apache's conf dir -

  • JkMount / balancer
  • JkMount /* balancer
  • JkMount /webapp1 worker1
  • JkMount /webapp1/* worker1

This works fine as well. The only problem here is that if tomcat1 (worker1) is down, the balancer doesn't direct the request for webapp1 to tomcat2 (worker2). How do I resolve this issue?

If you want requests to go to worker 1 by default and then to worker 2 if and only if worker 1 fails you'll need to set up a second lb worker (call it lb2) with two workers (tomcat1b and tomcat2b) and use the distance parameter to give tomcat2b a larger distance than tomact1b. That will cause tomcat1b to be used in preference to tomcat2b unless tomcat1b fails.

See the workers.properties docs for more info: http://tomcat.apache.org/connectors-doc/reference/workers.html

BTW you have tomcat1 in your workers.properties but worker1 in your JKMount. That won't work.

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