3

Anyone knows how to configure the hot standby (+H) mod_proxy feature so that the takeover occurs immediately (without even one user receiving a 502) error during a shutdown?

We aren't looking for real load-balancing, we just want a secondary server to take over while we shutdown the primary.

The problem is that whenever the primary goes down, I'm able to slip one invalid request resulting in a 502 HTTP error reaching the end user,before the secondary actually takes over.

Listen 80
<VirtualHost 127.0.0.1:80>
    ServerName domain.com
    ProxyPass / balancer://balance/

    <Proxy balancer://balance/>
        BalancerMember http://primary_ip:80
        BalancerMember http://secondary_ip:80 status=+H
    </Proxy>
</VirtualHost>
6million
  • 31
  • 2
  • Is there any way we could respond with something like a redirect to the original page when we occur a 502, acting as a retry-mechanism? – 6million Oct 22 '10 at 12:56

4 Answers4

1

If you explicitly disable the primary balancer member first (before bringing down the primary server), Apache will happily route request to the secondary balancer member. Takeover happens immediately.

To do that, enable the balancer manager first with config:

<Location /lb>
    SetHandler balancer-manager
</Location>

Then, you can interactively or programmatically enable / disable balancer member by accessing /lb.

Contrary to karmawhore's comment, a hot-standby setup like this has nothing to do with health-check.

sayap
  • 164
  • 6
0

You have to set timeout at the BalanceMember level in combination with setting failontimeout on the balancer level.

See https://stackoverflow.com/questions/169453/bad-gateway-502-error-with-apache-mod-proxy-and-tomcat/64805009#64805009.

dr0i
  • 231
  • 2
  • 11
0

Apache doesn't support health-checks which would be necessary to do that. Even with health-checks, there's a window between checks where requests could be invalid.

You could write something that repeatedly tested a small static file to force the proxy to recognize that the balancer has failed.

I remembered an old mod_perl solution:

http://search.cpan.org/~mgregoro/Apache-HealthCheck-0.01/lib/Apache/HealthCheck.pm

karmawhore
  • 3,865
  • 18
  • 9
  • I don't like the custom polling, because it's still not 100% sure, although it would make it less likely that someone gets responded with an error – 6million Oct 22 '10 at 12:55
0

I think that you can use the ErrorDocument directive. If you specify the error code you are looking for and instead of a static page (like /missing.html) you can specify a PHP page which can handle the redirect for you. Something like:

ErrorDocument 502 /redir.php

Then in the redir.php have something like:

<?php
header("Location: ...page that was asked for...");
?>
David Newcomb
  • 275
  • 1
  • 5
  • 14