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.

See also

top
@@ -133,6 +134,54 @@ RewriteRule ^page\.html$ page.cgi [ +
top
+
+

Load Balancing

+ + + +
+
Description:
+ +
+

We wish to randomly distribute load across several servers + using mod_rewrite.

+
+ +
Solution:
+ +
+

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.

+ +
+ +
Discussion
+
+

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 [ +
+ + Load Balancing + +
+
Description:
+ +
+

We wish to randomly distribute load across several servers + using mod_rewrite.

+
+ +
Solution:
+ +
+

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.

+ +
+ +
Discussion
+
+

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.

+
+
+ +
+ + + diff --git a/docs/manual/rewrite/rewrite_guide.html.en b/docs/manual/rewrite/rewrite_guide.html.en index c52e482923..4c27d4543f 100644 --- a/docs/manual/rewrite/rewrite_guide.html.en +++ b/docs/manual/rewrite/rewrite_guide.html.en @@ -51,7 +51,6 @@
  • Structured Homedirs
  • Dynamic Mirror
  • Retrieve Missing Data from Intranet
  • -
  • Load Balancing
  • New MIME-type, New Service
  • Document With Autorefresh
  • Mass Virtual Hosting
  • @@ -482,163 +481,6 @@ RewriteRule ^/home/([^/]+)/.www/?(.*) http://www2.quux-corp.dom
    top
    -

    Load Balancing

    - - - -
    -
    Description:
    - -
    -

    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?

    -
    - -
    Solution:
    - -
    -

    There are many possible solutions for this problem. - We will first discuss a common DNS-based method, - and then one based on mod_rewrite:

    - -
      -
    1. - DNS Round-Robin - -

      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.

      -
    2. - -
    3. - DNS Load-Balancing - -

      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.

      -
    4. - -
    5. - Proxy Throughput Round-Robin - -

      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##
      -
      - -
      A last notice: Why is this useful? Seems like - 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.
      -
    6. - -
    7. - Dedicated Load Balancers - -

      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.

      -
    8. -
    -
    -
    - -
    top
    -

    New MIME-type, New Service

    diff --git a/docs/manual/rewrite/rewrite_guide.xml b/docs/manual/rewrite/rewrite_guide.xml index 4695b2ce0d..5e52db3fa3 100644 --- a/docs/manual/rewrite/rewrite_guide.xml +++ b/docs/manual/rewrite/rewrite_guide.xml @@ -477,165 +477,6 @@ RewriteRule ^/home/([^/]+)/.www/?(.*) http://www2.quux-corp.dom -
    - - Load Balancing - -
    -
    Description:
    - -
    -

    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?

    -
    - -
    Solution:
    - -
    -

    There are many possible solutions for this problem. - We will first discuss a common DNS-based method, - and then one based on mod_rewrite:

    - -
      -
    1. - DNS Round-Robin - -

      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.

      -
    2. - -
    3. - DNS Load-Balancing - -

      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.

      -
    4. - -
    5. - Proxy Throughput Round-Robin - -

      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##
      -
      - - A last notice: Why is this useful? Seems like - 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. -
    6. - -
    7. - Dedicated Load Balancers - -

      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.

      -
    8. -
    -
    -
    - -
    -
    New MIME-type, New Service