Website Scripts And Cloud Tutorials

mod_proxy_balancer apache load balancing

Byadmin

Sep 19, 2010
Click to rate this tutorial!
[Total: 3 Average: 4.7]

Well, that is exactly what mod_proxy_balancer in Apache 2.2 allows you to do. It goes beyond that and can provide weighted load balancing of internal services, but it also allows you to define “hot spares” which are only used if the normal service(s) are unavailable. This is what I’m using, with a config like:

# Reverse Proxy /myapp to an internal web service, with fail-over to a hot standby
<proxy balancer://appcluster>
    BalancerMember http://127.0.0.1:9080
    # the hot standby on server2
    BalancerMember http://102.1.2.2:9080 status=+H
</proxy>
<location /myapp>
    ProxyPass           balancer://appcluster
    ProxyPassReverse    http://127.0.0.1:9080
    ProxyPassReverse    http://102.1.2.2:9080
</location>

This config tells Apache to proxy requests for /myapp to a web service on localhost at http://127.0.0.1:9080

If that service becomes unavailable (ie: you take it down for maintenance) then it will automatically send requests to http://102.1.2.2:9080 instead. The “status=+H” defines that member as a Hot Standby. When the default service is back on-line mod_proxy_balancer will pick that up within about 60 seconds or so and revert back to forwarding all requests to it.

The ProxyPassReverse directives are unrelated to the proxy balancing smarts, but are usually required if you want to handle redirects/etc properly.
Before configuring the above handlers you need to load the modules required

LoadModule status_module "/apache2.2/modules/standard/mod_status.so"
LoadModule proxy_balancer_module "/apache2.2/modules/standard/mod_proxy_balancer.so"

WEIGHTED LOAD BALANCING USING mod_proxy_balancer COMING SOON

Click to rate this tutorial!
[Total: 3 Average: 4.7]

Leave a Reply

Your email address will not be published.