0

I have 2 backend servers on the same network and 2 Tomcats on both machines with the same application. Additionally, I have a main machine where I load my app and which choses to which worker requests should go. The problem is that the Load Balancer machine always choses the second worker no matter what and when I manipulate with the application to make it not work on the second machine, I load the app on main machine and the app won't load even for the fact that worker1 is working, but when I close the Tomcat on the second machine it redirects the requests to the first worker and it works. How to make it work? Why it always choses the the second worker?

workers.properties:

worker.list=jkstatus,router
worker.jkstatus.type=status
worker.router.type=lb
worker.router.balance_workers=worker1,worker2
worker.router.method=B
worker.router.sticky_session=true
worker.template.type=ajp13
worker.template.lbfactor=1
worker.template.recovery_options=3
worker.template.socket_keepalive=true
worker.template.connection_pool_timeout=180
worker.worker1.reference=worker.template
worker.worker1.host=firstmachine.abc.com
worker.worker1.port=8009
worker.worker1.redirect=worker2
worker.worker2.reference=worker.template
worker.worker2.host=secondmachine.abc.com
worker.worker2.port=8009
worker.worker2.redirect=worker1
K. Martin
  • 1
  • 1

1 Answers1

0

If you application does not require it, try changing worker.router.sticky_sessions to false. Here's an explanation from documentation:

sticky_session specifies whether requests with SESSION ID's should be routed back to the same Tomcat instance that created the session. You can set sticky_session to false when Tomcat is using a session manager which can share session data across multiple instances of Tomcat - or if your application is stateless. By default sticky_session is set to true. https://tomcat.apache.org/connectors-doc/common_howto/loadbalancers.html

SamErde
  • 3,409
  • 3
  • 24
  • 44
  • A certain situation forced me to switch from workers.properties to httpd.conf and use Proxy and Balancers (also updated Apache and mod_jk) and everything works great. – K. Martin Jul 25 '18 at 11:54