Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I set up a load balancer with Apache 2.2 via mod_proxy and mod_proxy_balancer. The load balancing works just fine, but there is one case I cannot find any configuration options for, namely, while using persistent connections to the backend servers, when one of them dies (shuts down, crashes, etc ), the existing connections to it still try to access it.

Is there a way to configure the apache Load Balancer so that it quits or recreates connections to dead backend servers? In the LVS world the Ldirector has an option under Proc FS that governs just that:

/proc/sys/net/ipv4/vs/expire_quiescent_template

When this is set persistent sessions / connections or a dead backend server will be flushed so that on the next client request they can be recreated.

Is there something similar to it in the Apache world?

P.S. In what manner does Apache check the status of the backend servers? Does it try to connect to some port or something like that? It would be great if someone could shed some light on that too!

Here is my virtual host configuration file:

ServerAdmin admin@mysite.com ServerName myapp.mysite.com

DocumentRoot /srv/www/vhosts/myapp.mysite.com

ErrorLog /var/log/apache2/myapp.mysite.com-error_log
CustomLog /var/log/apache2/myapp.mysite.com-access_log combined

HostnameLookups Off
UseCanonicalName Off
ServerSignature On
ScriptAlias /cgi-bin/ "/srv/www/vhosts/myapp.mysite.com/cgi-bin/"

<Location /balancer-manager>
    SetHandler balancer-manager
    Order Deny,Allow
    Deny from all
    Allow from all
</Location>

<Location /server-status>
    SetHandler server-status
    Order deny,allow
    Deny from all
    Allow from bmf.intern.netz
</Location>

Header add Set-Cookie "ROUTEID=.%{BALANCER_WORKER_ROUTE}e; path=/" env=BALANCER_ROUTE_CHANGED
<Proxy balancer://myapp>
    BalancerMember http://172.22.1.133:777/ loadfactor=10 route=1 connectiontimeout=200ms
    BalancerMember http://172.22.1.134:777/ loadfactor=10 route=2 connectiontimeout=200ms
    ProxySet stickysession=ROUTEID
    ProxySet lbmethod=byrequests
</Proxy>

ProxyPass /balancer-manager !
ProxyPass /server-status !
ProxyPass / balancer://myapp/ lbmethod=byrequests
ProxyPassReverse / balancer://myapp/

<Directory "/srv/www/vhosts/myapp.mysite.com/cgi-bin">
    AllowOverride None
    Options +ExecCGI -Includes
    Order allow,deny
    Allow from all
</Directory>

<IfModule mod_userdir.c>
    UserDir public_html
    Include /etc/apache2/mod_userdir.conf
</IfModule>


#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/srv/www/vhosts/myapp.mysite.com">

    Options Indexes FollowSymLinks
    AllowOverride None

    Order allow,deny
    Allow from all

</Directory>

share|improve this question
    
If you are not forced to use apache, maybe you can give a try to haproxy haproxy.1wt.eu. Otherwise with mod_proxy you may also try to play with ttl, retry and timeout values. Check documentation here : httpd.apache.org/docs/2.2/mod/mod_proxy.html. As far as I know the "alive" check is done at request time. –  Tony May 16 '13 at 17:36
    
First of all thanks for the reply :) TTL values will make the users re-authorize every while and then, which is not desired at all. Connectiontimeout presents the same problem. All in all I don't want to kill or restrict the users' connections when the real servers are online, I want to redirect them when the server to which they have been connected dies / becomes unavailable. Does HAproxy has this stickyness removal option, like the expire quiescent templates? –  Konstantin Boyanov May 17 '13 at 8:20
add comment

1 Answer 1

If you switch mod_proxy to use ajp13 connection which require (I think) a Java backend, you might be able to achieve session stickyness

I think that the "expire" option you are looking for is present in HAProxy

option redispatch no option redispatch Enable or disable session redistribution in case of connection failure May be used in sections: defaults | frontend | listen | backend yes | no | yes | yes Arguments : none

In HTTP mode, if a server designated by a cookie is down, clients may definitely stick to it because they cannot flush the cookie, so they will not be able to access the service anymore.

Specifying "option redispatch" will allow the proxy to break their
persistence and redistribute them to a working server.

It also allows to retry last connection to another server in case of multiple connection failures. Of course, it requires having "retries" set to a nonzero value.

This form is the preferred form, which replaces both the "redispatch" and "redisp" keywords.

If this option has been enabled in a "defaults" section, it can be disabled in a specific instance by prepending the "no" keyword before it.

See also : "redispatch", "retries", "force-persist"

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.