load balancing with mod_proxy_balancer

1.

$ a2enmod proxy

$ a2enmod proxy_balancer # provides three algorithms for scheduling requests [ default = “byrequest” algorithm ]

$ a2enmod proxy_http # for HTTP-aware proxying of requests.
$ a2enmod status # for getting the status of the backend servers.

$ a2enmod rewrite # require by mod_proxy to do reverse proxying ( Client thinks the proxy server is serving its request, but in fact the proxy is forwarding the request to a different backend server )

2. config loadbalancing

$ cp /etc/apache2/sites-available/default /etc/apache2/sites-available/default_orig

edit /etc/apache2/sites-available/default

NameVirtualHost *
<VirtualHost *>
ServerName localhost
ServerAlias localhost
DocumentRoot /var/www/
ProxyRequests Off
# This is sets up access for proxy forwading.
# This configuration allows all request to be forwarded.
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
# If the url includes /balancer-manager,
# The server will not proxy the request
ProxyPass /balancer-manager !
# This maintains session across the different backend servers
ProxyPass / balancer://mycluster/ stickysession=BALANCEID nofailover=On
# The following allows every request to be forwared to the given servers
ProxyPassReverse / http://192.41.170.42/
ProxyPassReverse / http://192.41.170.41/
# Next the backend web servers and the scheduling algorithm are defined
<Proxy balancer://mycluster>
BalancerMember http://192.41.170.42 route=http1
BalancerMember http://192.41.170.41 route=http2
ProxySet lbmethod=byrequests
</Proxy>
# Balancer-manager Web app allows configuration of routes
<Location /balancer-manager>
SetHandler balancer-manager
Order deny,allow
Allow from all
</Location>
</VirtualHost>

ref : http://www.howtoforge.com/load_balancing_apache_mod_proxy_balancer


http://httpd.apache.org/docs/2.2/mod/mod_proxy.html for more on reverse proxying and the necessary URL rewriting

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s