
rbowen at apache
Nov 12, 2009, 4:30 AM
Post #1 of 1
(168 views)
Permalink
|
|
svn commit: r835364 - in /httpd/httpd/trunk/docs/manual/rewrite: advanced.html.en advanced.xml rewrite_guide.html.en rewrite_guide.xml
|
|
Author: rbowen Date: Thu Nov 12 12:30:05 2009 New Revision: 835364 URL: http://svn.apache.org/viewvc?rev=835364&view=rev Log: Removes a lengthy and unnecessary discussion of the various methods of load balancing. Removes a RewriteMap prg load balancing script, and replaces it with a RewriteMap rnd example of the same, as well as an admonition to use mod_proxy_balancer instead. Modified: httpd/httpd/trunk/docs/manual/rewrite/advanced.html.en httpd/httpd/trunk/docs/manual/rewrite/advanced.xml httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.html.en httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.xml Modified: httpd/httpd/trunk/docs/manual/rewrite/advanced.html.en URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/rewrite/advanced.html.en?rev=835364&r1=835363&r2=835364&view=diff ============================================================================== --- httpd/httpd/trunk/docs/manual/rewrite/advanced.html.en (original) +++ httpd/httpd/trunk/docs/manual/rewrite/advanced.html.en Thu Nov 12 12:30:05 2009 @@ -34,6 +34,7 @@ </div> <div id="quickview"><ul id="toc"><li><img alt="" src="../images/down.gif" /> <a href="#sharding">URL-based sharding accross multiple backends</a></li> <li><img alt="" src="../images/down.gif" /> <a href="#on-the-fly-content">On-the-fly Content-Regeneration</a></li> +<li><img alt="" src="../images/down.gif" /> <a href="#load-balancing">Load Balancing</a></li> </ul><h3>See also</h3><ul class="seealso"><li><a href="../mod/mod_rewrite.html">Module documentation</a></li><li><a href="intro.html">mod_rewrite introduction</a></li><li><a href="remapping.html">Redirection and remapping</a></li><li><a href="access.html">Controlling access</a></li><li><a href="avoid.html">When not to use mod_rewrite</a></li></ul></div> <div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> <div class="section"> @@ -133,6 +134,54 @@ </dd> </dl> +</div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> +<div class="section"> +<h2><a name="load-balancing" id="load-balancing">Load Balancing</a></h2> + + + + <dl> + <dt>Description:</dt> + + <dd> + <p>We wish to randomly distribute load across several servers + using mod_rewrite.</p> + </dd> + + <dt>Solution:</dt> + + <dd> + <p>We'll use <code class="directive"><a href="../mod/mod_rewrite.html#rewritemap">RewriteMap</a></code> and a list of servers + to accomplish this.</p> + +<div class="example"><pre> +RewriteEngine on +RewriteMap lb rnd:/path/to/serverlist.txt + +RewriteRule ^/(.*) http://${lb:servers}/$1 [P,L] +</pre></div> + +<p><code>serverlist.txt</code> will contain a list of the servers:</p> + +<div class="example"><pre> +## serverlist.txt + +servers one.example.com|two.example.com|three.example.com +</pre></div> + +<p>If you want one particular server to get more of the load than the +others, add it more times to the list.</p> + + </dd> + + <dt>Discussion</dt> + <dd> +<p>Apache comes with a load-balancing module - +<code class="module"><a href="../mod/mod_proxy_balancer.html">mod_proxy_balancer</a></code> - which is far more flexible and +featureful than anything you can cobble together using mod_rewrite.</p> + </dd> + </dl> + </div></div> <div class="bottomlang"> <p><span>Available Languages: </span><a href="../en/rewrite/avoid.html" title="English"> en </a></p> Modified: httpd/httpd/trunk/docs/manual/rewrite/advanced.xml URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/rewrite/advanced.xml?rev=835364&r1=835363&r2=835364&view=diff ============================================================================== --- httpd/httpd/trunk/docs/manual/rewrite/advanced.xml (original) +++ httpd/httpd/trunk/docs/manual/rewrite/advanced.xml Thu Nov 12 12:30:05 2009 @@ -142,4 +142,55 @@ </section> +<section id="load-balancing"> + + <title>Load Balancing</title> + + <dl> + <dt>Description:</dt> + + <dd> + <p>We wish to randomly distribute load across several servers + using mod_rewrite.</p> + </dd> + + <dt>Solution:</dt> + + <dd> + <p>We'll use <directive + module="mod_rewrite">RewriteMap</directive> and a list of servers + to accomplish this.</p> + +<example><pre> +RewriteEngine on +RewriteMap lb rnd:/path/to/serverlist.txt + +RewriteRule ^/(.*) http://${lb:servers}/$1 [P,L] +</pre></example> + +<p><code>serverlist.txt</code> will contain a list of the servers:</p> + +<example><pre> +## serverlist.txt + +servers one.example.com|two.example.com|three.example.com +</pre></example> + +<p>If you want one particular server to get more of the load than the +others, add it more times to the list.</p> + + </dd> + + <dt>Discussion</dt> + <dd> +<p>Apache comes with a load-balancing module - +<module>mod_proxy_balancer</module> - which is far more flexible and +featureful than anything you can cobble together using mod_rewrite.</p> + </dd> + </dl> + +</section> + + + </manualpage> Modified: httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.html.en URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.html.en?rev=835364&r1=835363&r2=835364&view=diff ============================================================================== --- httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.html.en (original) +++ httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.html.en Thu Nov 12 12:30:05 2009 @@ -51,7 +51,6 @@ <li><img alt="" src="../images/down.gif" /> <a href="#structuredhomedirs">Structured Homedirs</a></li> <li><img alt="" src="../images/down.gif" /> <a href="#dynamic-mirror">Dynamic Mirror</a></li> <li><img alt="" src="../images/down.gif" /> <a href="#retrieve-missing-data">Retrieve Missing Data from Intranet</a></li> -<li><img alt="" src="../images/down.gif" /> <a href="#load-balancing">Load Balancing</a></li> <li><img alt="" src="../images/down.gif" /> <a href="#new-mime-type">New MIME-type, New Service</a></li> <li><img alt="" src="../images/down.gif" /> <a href="#autorefresh">Document With Autorefresh</a></li> <li><img alt="" src="../images/down.gif" /> <a href="#mass-virtual-hosting">Mass Virtual Hosting</a></li> @@ -482,163 +481,6 @@ </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> <div class="section"> -<h2><a name="load-balancing" id="load-balancing">Load Balancing</a></h2> - - - - <dl> - <dt>Description:</dt> - - <dd> - <p>Suppose we want to load balance the traffic to - <code>www.example.com</code> over <code>www[0-5].example.com</code> - (a total of 6 servers). How can this be done?</p> - </dd> - - <dt>Solution:</dt> - - <dd> - <p>There are many possible solutions for this problem. - We will first discuss a common DNS-based method, - and then one based on <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code>:</p> - - <ol> - <li> - <strong>DNS Round-Robin</strong> - - <p>The simplest method for load-balancing is to use - DNS round-robin. - Here you just configure <code>www[0-9].example.com</code> - as usual in your DNS with A (address) records, e.g.,</p> - -<div class="example"><pre> -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 -</pre></div> - - <p>Then you additionally add the following entries:</p> - -<div class="example"><pre> -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 -</pre></div> - - <p>Now when <code>www.example.com</code> gets - resolved, <code>BIND</code> gives out <code>www0-www5</code> - - 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 <code>www.example.com</code> - to a particular <code>wwwN.example.com</code>, 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.</p> - </li> - - <li> - <strong>DNS Load-Balancing</strong> - - <p>A sophisticated DNS-based method for - load-balancing is to use the program - <code>lbnamed</code> which can be found at <a href="http://www.stanford.edu/~riepel/lbnamed/"> - http://www.stanford.edu/~riepel/lbnamed/</a>. - It is a Perl 5 program which, in conjunction with auxiliary - tools, provides real load-balancing via - DNS.</p> - </li> - - <li> - <strong>Proxy Throughput Round-Robin</strong> - - <p>In this variant we use <code class="module"><a href="../mod/mod_rewrite.html">mod_rewrite</a></code> - and its proxy throughput feature. First we dedicate - <code>www0.example.com</code> to be actually - <code>www.example.com</code> by using a single</p> - -<div class="example"><pre> -www IN CNAME www0.example.com. -</pre></div> - - <p>entry in the DNS. Then we convert - <code>www0.example.com</code> 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 (<code>www1-www5</code>). To - accomplish this we first establish a ruleset which - contacts a load balancing script <code>lb.pl</code> - for all URLs.</p> - -<div class="example"><pre> -RewriteEngine on -RewriteMap lb prg:/path/to/lb.pl -RewriteRule ^/(.+)$ ${lb:$1} [P,L] -</pre></div> - - <p>Then we write <code>lb.pl</code>:</p> - -<div class="example"><pre> -#!/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## -</pre></div> - - <div class="note">A last notice: Why is this useful? Seems like - <code>www0.example.com</code> 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.</div> - </li> - - <li> - <strong>Dedicated Load Balancers</strong> - - <p>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 <a href="http://vegan.net/lb/">lb-l mailing list</a> is a - good place to research.</p> - </li> - </ol> - </dd> - </dl> - - </div><div class="top"><a href="#page-header"><img alt="top" src="../images/up.gif" /></a></div> -<div class="section"> <h2><a name="new-mime-type" id="new-mime-type">New MIME-type, New Service</a></h2> Modified: httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.xml URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.xml?rev=835364&r1=835363&r2=835364&view=diff ============================================================================== --- httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.xml (original) +++ httpd/httpd/trunk/docs/manual/rewrite/rewrite_guide.xml Thu Nov 12 12:30:05 2009 @@ -477,165 +477,6 @@ </section> - <section id="load-balancing"> - - <title>Load Balancing</title> - - <dl> - <dt>Description:</dt> - - <dd> - <p>Suppose we want to load balance the traffic to - <code>www.example.com</code> over <code>www[0-5].example.com</code> - (a total of 6 servers). How can this be done?</p> - </dd> - - <dt>Solution:</dt> - - <dd> - <p>There are many possible solutions for this problem. - We will first discuss a common DNS-based method, - and then one based on <module>mod_rewrite</module>:</p> - - <ol> - <li> - <strong>DNS Round-Robin</strong> - - <p>The simplest method for load-balancing is to use - DNS round-robin. - Here you just configure <code>www[0-9].example.com</code> - as usual in your DNS with A (address) records, e.g.,</p> - -<example><pre> -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 -</pre></example> - - <p>Then you additionally add the following entries:</p> - -<example><pre> -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 -</pre></example> - - <p>Now when <code>www.example.com</code> gets - resolved, <code>BIND</code> gives out <code>www0-www5</code> - - 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 <code>www.example.com</code> - to a particular <code>wwwN.example.com</code>, 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.</p> - </li> - - <li> - <strong>DNS Load-Balancing</strong> - - <p>A sophisticated DNS-based method for - load-balancing is to use the program - <code>lbnamed</code> which can be found at <a - href="http://www.stanford.edu/~riepel/lbnamed/"> - http://www.stanford.edu/~riepel/lbnamed/</a>. - It is a Perl 5 program which, in conjunction with auxiliary - tools, provides real load-balancing via - DNS.</p> - </li> - - <li> - <strong>Proxy Throughput Round-Robin</strong> - - <p>In this variant we use <module>mod_rewrite</module> - and its proxy throughput feature. First we dedicate - <code>www0.example.com</code> to be actually - <code>www.example.com</code> by using a single</p> - -<example><pre> -www IN CNAME www0.example.com. -</pre></example> - - <p>entry in the DNS. Then we convert - <code>www0.example.com</code> 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 (<code>www1-www5</code>). To - accomplish this we first establish a ruleset which - contacts a load balancing script <code>lb.pl</code> - for all URLs.</p> - -<example><pre> -RewriteEngine on -RewriteMap lb prg:/path/to/lb.pl -RewriteRule ^/(.+)$ ${lb:$1} [P,L] -</pre></example> - - <p>Then we write <code>lb.pl</code>:</p> - -<example><pre> -#!/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## -</pre></example> - - <note>A last notice: Why is this useful? Seems like - <code>www0.example.com</code> 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.</note> - </li> - - <li> - <strong>Dedicated Load Balancers</strong> - - <p>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 <a - href="http://vegan.net/lb/">lb-l mailing list</a> is a - good place to research.</p> - </li> - </ol> - </dd> - </dl> - - </section> - <section id="new-mime-type"> <title>New MIME-type, New Service</title>
|