Load Balancing between Apache-2.2.29 and Tomcat-6.0.41 in CentOS-6.4-minimal, tomcat6.0.41

Source: Internet
Author: User

Load Balancing between Apache-2.2.29 and Tomcat-6.0.41 in CentOS-6.4-minimal, tomcat6.0.41

/*** In the CentOS-6.4-minimal version of Apache-2.2.29 and Tomcat-6.0.41 Load Balancing * balance * about the Load Balancer (Load Balancer) and Cluster (Cluster) difference, and different configuration methods, see the http://blog.csdn.net/jadyer/article/details/39623209 * configure * Server Load balancer * this article is based on Apache-2.2.29 and Tomcat-6.0.41 integration, the integration process see http://blog.csdn.net/jadyer/article/details/39613523 * 1) modify the port (because I copied multiple tomcat servers on one machine, you need to modify the port. skip this step if it is a different machine) * [root @ CentOS64 app] # vi tomcat/conf/server. xml (modify 8005 to-1 for the reason see http://blog.csdn.net/jadyer/article/details/39613771) * [root @ CentOS64 app] # cp-a tomcat tomcat1 * [root @ CentOS64 app] # cp-a tomcat tomcat2 * [root @ CentOS64 app] # cp-a tomcat tomcat3 * [root @ CentOS64 app] # vi extends AT1/conf/server. xml (modify the ssl port and ajp port to 8543 and 8109 respectively, that is, + 100) * [root @ CentOS64 app] # vi tomcat2/conf/server. xml (modify the ssl port and ajp port to 8643 and 8209 respectively, that is, + 200) * [root @ CentOS64 app] # vi tomcat3/conf/server. xml (modify the ssl port and ajp port to 8743 and 8309 respectively, that is, + 300) * 2) Modify/app/apache/conf/workers. properties. The modified content is as follows * worker. list = status, tomcatlb * worker. status. type = status * worker. tomcat1.port = 8109 * worker. tomcat1.host = 127.0.0.1 * worker. tomcat1.type = ajp13 * worker. tomcat1.lbfactor = 1 * worker. tomcat2.port = 8209 * worker. tomcat2.host = 127.0.0.1 * worker. tomcat2.type = ajp13 * worker. tomcat2.lbfactor = 1 * worker. tomcat3.port = 8309 * worker. tomcat3.host = 127.0.0.1 * worker. tomcat3.type = ajp13 * worker. tomcat3.lbfactor = 1 # load weight. The higher the value, the higher the probability of requests being distributed. The default value is 1 * worker. tomcatlb. type = lb # optional values: ajp13, ajp14, jni, lb or status * worker. retries = 6 # Number of retries when the communication fails. The default value is 2 * worker. tomcatlb. balanced_workers = tomcat1, tomcat2, tomcat3 # Web server involved in Server Load balancer * 3) Modify/app/apache/conf/extra/httpd-vhosts.conf * change the default tomcat to tomcatlb, that is, specify all requests to be processed by tomcatlb * ---------------------------------------------------------------------------------------------------------------------- * test Server Load balancer * 1) After apache and three tomcat servers are started, you can view the three tomcat servers and other parameters involved in Server Load balancer through jkstatus, we can also modify the Server Load balancer parameters through jkstatus * about jkstatus configuration and use, see http://blog.csdn.net/jadyer/article/details/39613553 * 2) next test the Server Load balancer access, the test code has been pasted below * access page. We will find that every time we refresh the page, we can see that the request is randomly allocated to three tomcat servers through the background log, it indicates that the three tomcat servers are equally responsible, that is, the Server Load balancer is successful * and, because no cluster is configured here, every time you refresh the page, the SessionID printed on the page is changed * worker * about workers. for more property descriptions of properties, refer to the following two URLs * http://tomcat.apache.org/connectors-doc/reference/workers.html * http://blog.csdn.net/chumeng411/article/details/7541767 * and add two workers property descriptions to be validated * 1) worker. tomcatlb. sticky_session = true * specify whether the cluster needs session replication. If it is set to true, it indicates session stickiness and no session replication * when a user's request is distributed to Tomcat for the first time, subsequent requests will be distributed to the Tomcat server for processing. * if it is set to false, session replication is required. The default value of this attribute is true * when it is set to 0 (false, is a request-Based Server Load balancer. If it is 1 (true), it is a user-based Server Load balancer * 2) worker. tomcatlb. sticky_session_force = true * the default value of this attribute is false. If the preceding sticky_session is set to true, we recommend that you set this parameter to true. * This parameter indicates that if a Tomcat server in the cluster does not respond to multiple requests, whether to forward the current request to other Tomcat servers for processing * this parameter has a great impact when sticky_session = true, the original session cannot be found for requests forwarded to other Tomcat servers. * if some information in the session is read in the request, will cause the application Null exception * required * @ create Sep 27,201 4 6:29:49 * @ author Xuan Yu 


<% @ Page language = "java" pageEncoding = "UTF-8" %> <% out. println ("<br> Session ID:" + session. getId () + "<br>"); session. setAttribute ("myname", "session"); String dataName = request. getParameter ("dataName"); if (null! = DataName & dataName. length ()> 0) {String dataValue = request. getParameter ("dataValue"); session. setAttribute (dataName, dataValue);} out. print ("<B> Session List </B> <br>"); java. util. enumeration e = session. getAttributeNames (); while (e. hasMoreElements () {String name = (String) e. nextElement (); String value = session. getAttribute (name ). toString (); out. println (name + "=" + value + "<br>") ;}%> <form action = "demo. jsp "method =" POST "> attribute name: <input type = text size = 20 name =" dataName "> <br> attribute value: <input type = text size = 20 name = "dataValue"> <br> <input type = submit> </form>


Centos 52 high-availability web Load Balancing Solution

We recommend that you use mainstream devices such as array, f5, and ---.
 
Apache tomcat Load Balancing session

Session sharing is not configured.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.