diff --git a/docs/manual/rewrite/advanced.html.en b/docs/manual/rewrite/advanced.html.en index df5dc7c193..07a6ad4952 100644 --- a/docs/manual/rewrite/advanced.html.en +++ b/docs/manual/rewrite/advanced.html.en @@ -34,6 +34,7 @@ configuration.
We wish to randomly distribute load across several servers + using mod_rewrite.
+We'll use RewriteMap
and a list of servers
+ to accomplish this.
+RewriteEngine on +RewriteMap lb rnd:/path/to/serverlist.txt + +RewriteRule ^/(.*) http://${lb:servers}/$1 [P,L] +
serverlist.txt
will contain a list of the servers:
+## serverlist.txt + +servers one.example.com|two.example.com|three.example.com +
If you want one particular server to get more of the load than the +others, add it more times to the list.
+ +Apache comes with a load-balancing module -
+mod_proxy_balancer
- which is far more flexible and
+featureful than anything you can cobble together using mod_rewrite.
Available Languages: en
diff --git a/docs/manual/rewrite/advanced.xml b/docs/manual/rewrite/advanced.xml index 2cb1aeac56..fb2cae603c 100644 --- a/docs/manual/rewrite/advanced.xml +++ b/docs/manual/rewrite/advanced.xml @@ -142,4 +142,55 @@ RewriteRule ^page\.html$ page.cgi [ +We wish to randomly distribute load across several servers + using mod_rewrite.
+We'll use
+RewriteEngine on +RewriteMap lb rnd:/path/to/serverlist.txt + +RewriteRule ^/(.*) http://${lb:servers}/$1 [P,L] +
serverlist.txt
will contain a list of the servers:
+## serverlist.txt + +servers one.example.com|two.example.com|three.example.com +
If you want one particular server to get more of the load than the +others, add it more times to the list.
+ +Apache comes with a load-balancing module -
+
Suppose we want to load balance the traffic to
- www.example.com
over www[0-5].example.com
- (a total of 6 servers). How can this be done?
There are many possible solutions for this problem.
- We will first discuss a common DNS-based method,
- and then one based on mod_rewrite
:
The simplest method for load-balancing is to use
- DNS round-robin.
- Here you just configure www[0-9].example.com
- as usual in your DNS with A (address) records, e.g.,
-www0 IN A 1.2.3.1 -www1 IN A 1.2.3.2 -www2 IN A 1.2.3.3 -www3 IN A 1.2.3.4 -www4 IN A 1.2.3.5 -www5 IN A 1.2.3.6 -
Then you additionally add the following entries:
- --www IN A 1.2.3.1 -www IN A 1.2.3.2 -www IN A 1.2.3.3 -www IN A 1.2.3.4 -www IN A 1.2.3.5 -
Now when www.example.com
gets
- resolved, BIND
gives out www0-www5
- - but in a permutated (rotated) order every time.
- This way the clients are spread over the various
- servers. But notice that this is not a perfect load
- balancing scheme, because DNS resolutions are
- cached by clients and other nameservers, so
- once a client has resolved www.example.com
- to a particular wwwN.example.com
, all its
- subsequent requests will continue to go to the same
- IP (and thus a single server), rather than being
- distributed across the other available servers. But the
- overall result is
- okay because the requests are collectively
- spread over the various web servers.
A sophisticated DNS-based method for
- load-balancing is to use the program
- lbnamed
which can be found at
- http://www.stanford.edu/~riepel/lbnamed/.
- It is a Perl 5 program which, in conjunction with auxiliary
- tools, provides real load-balancing via
- DNS.
In this variant we use mod_rewrite
- and its proxy throughput feature. First we dedicate
- www0.example.com
to be actually
- www.example.com
by using a single
-www IN CNAME www0.example.com. -
entry in the DNS. Then we convert
- www0.example.com
to a proxy-only server,
- i.e., we configure this machine so all arriving URLs
- are simply passed through its internal proxy to one of
- the 5 other servers (www1-www5
). To
- accomplish this we first establish a ruleset which
- contacts a load balancing script lb.pl
- for all URLs.
-RewriteEngine on -RewriteMap lb prg:/path/to/lb.pl -RewriteRule ^/(.+)$ ${lb:$1} [P,L] -
Then we write lb.pl
:
-#!/path/to/perl -## -## lb.pl -- load balancing script -## - -$| = 1; - -$name = "www"; # the hostname base -$first = 1; # the first server (not 0 here, because 0 is myself) -$last = 5; # the last server in the round-robin -$domain = "foo.dom"; # the domainname - -$cnt = 0; -while (<STDIN>) { - $cnt = (($cnt+1) % ($last+1-$first)); - $server = sprintf("%s%d.%s", $name, $cnt+$first, $domain); - print "http://$server/$_"; -} - -##EOF## -
www0.example.com
still is overloaded? The
- answer is yes, it is overloaded, but with plain proxy
- throughput requests, only! All SSI, CGI, ePerl, etc.
- processing is handled done on the other machines.
- For a complicated site, this may work well. The biggest
- risk here is that www0 is now a single point of failure --
- if it crashes, the other servers are inaccessible.There are more sophisticated solutions, as well. Cisco, - F5, and several other companies sell hardware load - balancers (typically used in pairs for redundancy), which - offer sophisticated load balancing and auto-failover - features. There are software packages which offer similar - features on commodity hardware, as well. If you have - enough money or need, check these out. The lb-l mailing list is a - good place to research.
-Suppose we want to load balance the traffic to
- www.example.com
over www[0-5].example.com
- (a total of 6 servers). How can this be done?
There are many possible solutions for this problem.
- We will first discuss a common DNS-based method,
- and then one based on
The simplest method for load-balancing is to use
- DNS round-robin.
- Here you just configure www[0-9].example.com
- as usual in your DNS with A (address) records, e.g.,
-www0 IN A 1.2.3.1 -www1 IN A 1.2.3.2 -www2 IN A 1.2.3.3 -www3 IN A 1.2.3.4 -www4 IN A 1.2.3.5 -www5 IN A 1.2.3.6 -
Then you additionally add the following entries:
- --www IN A 1.2.3.1 -www IN A 1.2.3.2 -www IN A 1.2.3.3 -www IN A 1.2.3.4 -www IN A 1.2.3.5 -
Now when www.example.com
gets
- resolved, BIND
gives out www0-www5
- - but in a permutated (rotated) order every time.
- This way the clients are spread over the various
- servers. But notice that this is not a perfect load
- balancing scheme, because DNS resolutions are
- cached by clients and other nameservers, so
- once a client has resolved www.example.com
- to a particular wwwN.example.com
, all its
- subsequent requests will continue to go to the same
- IP (and thus a single server), rather than being
- distributed across the other available servers. But the
- overall result is
- okay because the requests are collectively
- spread over the various web servers.
A sophisticated DNS-based method for
- load-balancing is to use the program
- lbnamed
which can be found at
- http://www.stanford.edu/~riepel/lbnamed/.
- It is a Perl 5 program which, in conjunction with auxiliary
- tools, provides real load-balancing via
- DNS.
In this variant we use www0.example.com
to be actually
- www.example.com
by using a single
-www IN CNAME www0.example.com. -
entry in the DNS. Then we convert
- www0.example.com
to a proxy-only server,
- i.e., we configure this machine so all arriving URLs
- are simply passed through its internal proxy to one of
- the 5 other servers (www1-www5
). To
- accomplish this we first establish a ruleset which
- contacts a load balancing script lb.pl
- for all URLs.
-RewriteEngine on -RewriteMap lb prg:/path/to/lb.pl -RewriteRule ^/(.+)$ ${lb:$1} [P,L] -
Then we write lb.pl
:
-#!/path/to/perl -## -## lb.pl -- load balancing script -## - -$| = 1; - -$name = "www"; # the hostname base -$first = 1; # the first server (not 0 here, because 0 is myself) -$last = 5; # the last server in the round-robin -$domain = "foo.dom"; # the domainname - -$cnt = 0; -while (<STDIN>) { - $cnt = (($cnt+1) % ($last+1-$first)); - $server = sprintf("%s%d.%s", $name, $cnt+$first, $domain); - print "http://$server/$_"; -} - -##EOF## -
www0.example.com
still is overloaded? The
- answer is yes, it is overloaded, but with plain proxy
- throughput requests, only! All SSI, CGI, ePerl, etc.
- processing is handled done on the other machines.
- For a complicated site, this may work well. The biggest
- risk here is that www0 is now a single point of failure --
- if it crashes, the other servers are inaccessible.There are more sophisticated solutions, as well. Cisco, - F5, and several other companies sell hardware load - balancers (typically used in pairs for redundancy), which - offer sophisticated load balancing and auto-failover - features. There are software packages which offer similar - features on commodity hardware, as well. If you have - enough money or need, check these out. The lb-l mailing list is a - good place to research.
-