apache mod_proxy load balancing - saviovettoor/DevOps-wiki GitHub Wiki
You can cluster at the request or session level. Request level means that each request may go to a different node – this is the ideal since the traffic would be balanced across all nodes, and if a node goes down, the user has no idea. Unfortunately, this requires session replication between all nodes, not just of HttpSession, but ANY session state. Session level clustering means if your application is one that requires a login or other forms of session-state, and one or more your Tomcat nodes goes down, on their next request, the user will be asked to log in again, since they will hit a different node which does not have any stored session data for the user.
Enable following modules in apache
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule proxy_balancer_module modules/mod_proxy_balancer.so
And the Apache Cluster Virtual Host Configuration as follows:
<VirtualHost example.com:80>
ServerName example.com
ServerAlias www.example.com
ErrorLog /srv/www/example.com/logs/error.log
CustomLog /srv/www/example.com/logs/access.log combined
<Proxy balancer://cluster stickysession=JSESSIONID>
#stickysession to maintain session ID
BalancerMember http://app1.example.com connectiontimeout=10 retry=600
BalancerMember http://app2.example.com connectiontimeout=10 retry=600
BalancerMember http://app3.example.com connectiontimeout=10 retry=600
</Proxy>
ProxyPass / balancer://cluster/
# ProxyPass / balancer://cluster/ lbmethod=byrequests
# ProxyPass / balancer://cluster/ lbmethod=bytraffic
# ProxyPass / balancer://cluster/ lbmethod=bybusyness
</VirtualHost>