Keepalived with Threaded-Health-Check support
This is the page for the thc patch to be used with keepalived,
an excellent program written by Alexandre Cassen to handle Linux Virtual Servers and
other redundant applications.
The main advandages for using keepalived-THC:
- Write your own pluggable monitor modules for keepalived which then are loadable as dynamic shared objects. Writing such modules now is very easy.
- Use external libraries for writing such modules, even without support for asynchronous calls.
- Avoid I/O blocking in certain situations, were the scheduler of the keepalived-checker did block in certain system calls, namely
read().
- Separate the real-server-checking from the virtual-server-switching. This allows you to use one real-server-query to switch more than one virtual-server. If, for instance your httpd-server runs on more than one port, then its needless to query for each of them. By doing a query onto one port, the virtual-server switching can be done once for all of them.
- Allow more than one real-server-checking per virtual-server-switching. This allows you do virtual-server-switching by doing, for instance one query onto the httpd, and one query onto the mysqld. Only if both report success the real-server is added to the list.
The latest version of keepalived with THC support can be downloaded here:
source-rpm: http://homes.tiscover.com/jrief/keepalived/keepalived-1.1.11-8thc.src.rpm
Patch only: http://homes.tiscover.com/jrief/keepalived/keepalived-1.1.11-8thc.patch
Setting up a Sorry-server
keepalived allows you to redirect all web-traffic into one webserver in case all real-server went down. This is much
more polite to your customers rather than just beeing not available. To set up such a webserver you normally would
serve only some static content telling your customers that you are sorry, but your web-services currently are not
available. However the requests your customers send, are regular URLs which are not resolvable by your sorry-server,
and therefore would be answered with an error-code 404 - Not found. This error-code can be very annoying, if at
the moment of an outage a robot (such as googlebot) is indexing your webpages. In such a case many of your webpages will
certainly fall out of the Google-index.
To avoid this, your sorry-server should send a 502 - Server overload message instead of a 404 - Not found
message. A Server oveload message also is describing more accurately your real problem.
To set up a sorry-server, you should consider to use a very small and simple webserver, which is able to serve only static
content. Otherwise you would risk to overload your sorry-server as well.
Setting up Sorry-server with publicfile
publicfile is a tiny and safe webserver written by Dan Bernstein.
Compared to other webservers such as Apache, it lacks of many features and is very limited in its configuration. This lack
of features can be advatagous were the webserver shall do only one specific task, for instance showing a sorry page.
You could use publicfile out of the box to setup a sorry-server, the problem however is, that in case all
loadbalanced servers go down, visitors are referring to URLs not handable by the sorry-server. This would result into
404 (not found) error-messages, which is a hardcoded message in publicfile. In order to customize this sorry-message
I patched publicfile. It now sends an error-code 502 (server overloaded)
instead of 404 (not found) and sends an individual default page for unresolvable URLs, rather than a static error string.
Setting up Sorry-server with TUX
Since publicfile is running in userspace, this could become another bottleneck. By using TUX as a Sorry-server you can
be assured, that your loadbalancer can hanlde at least as much sorry-web-traffic as it would able to under normal
conditions. Therefore using TUX might even be a better
idea than using publicfile. Since the intention of this webserver is to serve a sorry page, an error code of 404
would be inappropriate. Apply this patch onto a 2.4 or 2.6 kernel and TUX will send an error-code of 502 (server overloaded)
instead of 404 (not found) for all URL's which can't be resoved.
kernel-2.4.x
diff -u kernel-2.4.21/linux-2.4.21/net/tux/proto_http.c linux-2.4.21-tux502/net/tux/proto_http.c
--- linux-2.4.21/net/tux/proto_http.c 2005-03-07 15:09:45.000000000 +0100
+++ linux-2.4.21-tux502/net/tux/proto_http.c 2005-03-07 15:08:13.000000000 +0100
@@ -1172,7 +1172,7 @@
" Forbidden ";
static const char not_found[] =
- "HTTP/1.1 404 Not Found\r\n"
+ "HTTP/1.1 502 Service temporarily down\r\n"
"Connection: Keep-Alive\r\n" \
"Content-Length: 29\r\n\r\n"
" Page Not Found ";
@@ -1838,7 +1838,7 @@
"HTTP/1.1 206 Partial Content"
#define HEADER_PART1C \
- "HTTP/1.1 404 Page Not Found\r\n" \
+ "HTTP/1.1 502 Service temporarily down\r\n" \
"Content-Type: "
#define HEADER_PART1D \
kernel-2.6.x:
diff -ur linux-2.6.9/net/tux/proto_http.c linux-2.6.9-tux502/net/tux/proto_http.c
--- linux-2.6.9/net/tux/proto_http.c 2005-03-15 12:08:56.660827776 +0100
+++ linux-2.6.9-tux502/net/tux/proto_http.c 2005-03-15 13:13:49.437035840 +0100
@@ -1174,7 +1174,7 @@
" Forbidden ";
static const char not_found[] =
- "HTTP/1.1 404 Not Found\r\n"
+ "HTTP/1.1 502 Service temporarily down\r\n"
"Connection: Keep-Alive\r\n" \
"Content-Length: 29\r\n\r\n"
" Page Not Found ";
@@ -1840,7 +1840,7 @@
"HTTP/1.1 206 Partial Content"
#define HEADER_PART1C \
- "HTTP/1.1 404 Page Not Found\r\n" \
+ "HTTP/1.1 502 Service temporarily down\r\n" \
"Content-Type: "
#define HEADER_PART1D \
In case you have questions, please start your subject line with something containing keepalived, otherwise
I might ignore it.
E-Mail me at echo "jaNcoOb.rSiePf@tiAscovMer.com" | sed -e 's/[NOSPAM]//g'.