Managing multiple Apache proxies simultaneously (mod_proxy_balancer)

apache-2.2load balancing

The frontend of my web application is formed by currently two Apache reverse proxies, using mod_proxy_balancer to distribute traffic over a number of backend application servers. Both frontend reverse proxies, running on separate hosts, are accessible from the internet. DNS round robin distributes traffic over both. In the future, the number of reverse proxies is likely to grow, since the webapplication is very bandwidth-heavy.

My question is: how do I keep the state of both reverse balancers / proxies in sync?

For example, for maintenance purposes, I might want to reduce the load on one of the backend appservers. Currently I can do that by accessing the Balancer-Manager web form on each proxy, and change the distribution rules. But I have to do that on each proxy manually and make sure I enter the same stuff.

Is it possible to "link" multiple instances of mod_proxy_balancer? Or is there a tool out there that connects to a number of instances, and updates all with the same information?

Update: The tool should retrieve the runtime status and make runtime changes, just like the existing Balancer-Manager, only for a number of proxies – not just for one. Modification of configuration files is not what I'm interested in (as there are plenty tools for that).

Best Answer

There is a ruby module name Amphibian which eases programatic access to the balancer-manager web interface. It may not have all the features you need, but you could add them or use it as an example to write a similar library in another language. Here is an example script that uses it to enable or disable user-specified backend appservers on two proxy balancers.

# amphibian_example.rb
require 'amphibian'

balancer_hosts = ["b1.example.com", "b2.example.com"]

command = ARGV.shift
backend_hosts = ARGV

balancer_hosts.each do |balancer_host|
    balancer_url = "http://#{balancer_host}/balancer-manager"
    balancer = Amphibian::BalancerManager.new(balancer_url)
    backend_hosts.each do |backend_host|
        backend_url = "http://#{backend_host}"
        if command == "enable"
            balancer.enable_host(backend_url)
            puts "Enabled #{backend_host} on #{balancer_host}"
        end
        if command == "disable"
            balancer.disable_host(backend_url)
            puts "Disabled #{backend_host} on #{balancer_host}"
        end
    end
end

This could be run like

$ amphibian_example.rb disable a1.example.com a5.example.com
Disabled a1.example.com on b1.example.com
Disabled a5.example.com on b1.example.com
Disabled a1.example.com on b2.example.com
Disabled a5.example.com on b2.example.com
Related Topic