remm 2004/02/05 08:05:31 Modified: webapps/docs balancer-howto.xml cluster-howto.xml project.xml Log: - Document other methods for load balancing. - The mod_rewrite + mod_proxy one is untested (at least by me; Pier did it). Revision Changes Path 1.3 +117 -9 jakarta-tomcat-catalina/webapps/docs/balancer-howto.xml Index: balancer-howto.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/balancer-howto.xml,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- balancer-howto.xml 25 Nov 2003 18:38:49 -0000 1.2 +++ balancer-howto.xml 5 Feb 2004 16:05:31 -0000 1.3 @@ -8,13 +8,119 @@ <properties> <author email="[EMAIL PROTECTED]">Yoav Shapira</author> + <author>Remy Maucherat</author> + <author>Andy Oliver</author> <title>Load Balancer HOW-TO</title> </properties> <body> +<section name="Table of Contents"> +<p> +<a href="#Using the JK native connector"> +Using the JK native connector</a><br /> +<a href="#Using Apache 2 with mod_proxy and mod_rewrite"> +Using Apache 2 with mod_proxy and mod_rewrite</a><br /> +<a href="#Using the balancer webapp">Using the balancer webapp</a><br /> +</p> +</section> + +<section name="Using the JK native connector"> + +Please refer to the JK documentation. + +</section> -<section name="Overview"> +<section name="Using Apache 2 with mod_proxy and mod_rewrite"> + +<subsection name="Overview"> + +<p> +It is possible to use Apache 2, with mod_proxy and mod_rewrite, to load balance +requests to a set of Tomcat servers, using the HTTP protocol rather than AJP. +Although it does not have any advanced load balancing or failover strategies, +it is very easy to setup. +</p> + +<p> +Thanks to Pier Fumagalli for helping document this method. +</p> + +</subsection> + +<subsection name="Configuring Tomcat"> + +<p> +Edit <code>$CATALINA_HOME/conf/server.xml</code>, and find the Engine element +and add an attribute called jvmRoute. Set its value to LB1. +</p> + +<source> +<Engine name="MainEngine" defaultHost="localhost" jvmRoute="LB1"> +</source> + +<p> +Do the same for each server in the group, giving each a different ID: LB2, +LB3, ... +</p> + +</subsection> + +<subsection name="Apache 2 configuration"> + +<p> +First we must create a rewrite map (for mod_rewrite) (balancing.conf): +</p> + +<source> +LB1 tomcat1.foo.com:8080 +LB2 tomcat2.foo.com:8080 +LB3 tomcat3.foo.com:8888 +ALL tomcat1.foo.com:8080|tomcat2.foo.com:8080|tomcat3.foo.com:8888 +</source> + +<p> +This means each worker is associated with a specific server and port. The name +associated with each node <strong>must</strong> match the one used for the +jvmRoute attribute specified on the Engine element of each node's server.xml. +</p> + +<p> +In <code>httpd.conf</code>: +</p> + +<source>RewriteMap SERVERS rnd:/usr/local/httpd/conf/servers.conf + +<Location /webapp> + RewriteEngine On + + RewriteCond "%{HTTP_COOKIE}" "(^|;\s*)jsessionid=\w*\.(\w+)($|;)" + RewriteRule "(.*)" "http://${SERVERS:%2}%{REQUEST_URI}" [P,L] + RewriteRule "^.*;jsessionid=\w*\.(\w+)($|;)" "http://${SERVERS:$1}%{REQUEST_URI}" [P,L] + RewriteRule "(.*)" "http://${SERVERS:ALL}%{REQUEST_URI}" [P,L] +</Location> +</source> + +<p> +The first entry means that we want to load the server map which we +created. The "ALL" entry in the server map will affect those users who +do not yet have a session ID. Meaning the session cookie which Tomcat +creates will have the LBx id in it, the other entries will govern which +host we're directed to. +</p> + +<p>The rewrite rules govern those users with a cookie. Apache will +rewrite the URL and point you to one of the instances of Tomcat. This +is vodoo but it should work. +</p> + +</subsection> + +</section> + +<section name="Using the balancer webapp"> + +<subsection name="Overview"> <p> Tomcat 5.0.15 and later ships with a webapp named balancer. This is @@ -30,9 +136,9 @@ to use a filter to redirect traffic. If you wish to redirect traffic using a servlet, you may use any servlet container. </p> -</section> +</subsection> -<section name="Sample Configuration"> +<subsection name="Sample Configuration"> <p> The default balancer installation uses a single filter, BalancerFilter, mapped to all requests (url-pattern /*). The filter reads its rules @@ -53,9 +159,9 @@ http://localhost:8080/balancer/BlahBlah?paramName=paramValue will be redirected to http://www.yahoo.com. </p> -</section> +</subsection> -<section name="Balancer Rules"> +<subsection name="Balancer Rules"> <p> A <i>Rule</i> in the balancer system is a combination of a request matching criterion and a redirection URL for @@ -85,9 +191,9 @@ in the Servlet Specification. Each filter will have its own RuleChain. </p> -</section> +</subsection> -<section name="How it Works"> +<subsection name="How it Works"> <p> <ol> <li>You write a rules configuration file containing various @@ -104,13 +210,15 @@ </ol> </p> -</section> +</subsection> -<section name="Comments"> +<subsection name="Comments"> <p> Please direct questions, comments, suggestions, etc. to the tomcat-user mailing list. Thank you. </p> +</subsection> + </section> </body> 1.5 +2 -2 jakarta-tomcat-catalina/webapps/docs/cluster-howto.xml Index: cluster-howto.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/cluster-howto.xml,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- cluster-howto.xml 9 Jan 2004 23:36:34 -0000 1.4 +++ cluster-howto.xml 5 Feb 2004 16:05:31 -0000 1.5 @@ -26,8 +26,8 @@ attribute is unique for each instance.</li> <li>Make sure your <code>web.xml</code> has the <code><distributable/></code> element</li> </ul> -<p>Then all you have to do is start Tomcat, I suggest using <a href="http://balance.sourceforge.net">Balance</a> - as a load balancer. Apache/mod_jk will also do or hardware of course</p> +<p>Load balancing can be achieved through many techniques, as seen in the +<a href="balancer-howto.html">Load Balancing</a> chapter.</p> <p>Note: Remember that your session state is tracked by a cookie, so your URL must look the same from the out side otherwise, a new session will be created.</p> <p>Note: Clustering support currently requires the JDK version 1.4 or later.</p> 1.20 +1 -1 jakarta-tomcat-catalina/webapps/docs/project.xml Index: project.xml =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/webapps/docs/project.xml,v retrieving revision 1.19 retrieving revision 1.20 diff -u -r1.19 -r1.20 --- project.xml 13 Dec 2003 17:21:21 -0000 1.19 +++ project.xml 5 Feb 2004 16:05:31 -0000 1.20 @@ -37,7 +37,7 @@ href="mbeans-descriptor-howto.html"/> <item name="17) Default Servlet" href="default-servlet.html"/> <item name="18) Clustering" href="cluster-howto.html"/> - <item name="19) Balancer" href="balancer-howto.html"/> + <item name="19) Load Balancer" href="balancer-howto.html"/> </menu> <menu name="Reference">
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]