Configure Server Load balancer for apache2 + tomcat6

Source: Internet
Author: User

 

1. install Apache and tomcat. Assume that apache2.2.3, tomcat6.x, Apache is installed on apachehost, Tomcat is installed on tomcathost1 and tomcathost2, respectively. modify/etc/httpd/CONF/httpd. CONF file. Make sure the following lines are not commented out. <textarea cols="50" rows="15" name="code" class="python">Loadmodule proxy_module modules/mod_proxy.so <br/> loadmodule proxy_http_module modules/mod_proxy_http.so <br/> loadmodule proxy_balancer_module modules/mod_proxy_balancer.so</textarea> 3. Modify the/etc/httpd/CONF/httpd. conf file and add the following lines: <Textarea Cols = "50" rows = "15" name = "code" class = "Python"> proxyrequests off <br/> <proxy balancer: // tccluster> <br/> balancermember http: // tomcathost1: 8080 loadfactor = 2 route = route AT1 max = 150 Smax = 145 <br/> balancermember http: // tomcathost2: 8080 loadfactor = 1 route = tomcat2 max = 150 Smax = 145 <br/> order deny, allow <br/> allow from all <br/> # proxyset lbmethod = byrequests | bytraffic | bybusyness <br/> </Proxy> <br/> <location/balancer-Manager> <br/> sethandler balancer-manager <br/> order deny, allow <br/> allow from all <br/> </location> <br/> <location/examples> <br/> proxypass balancer: // tccluster/examples stickysession = JSESSIONID <br/> proxypassreverse balancer: // tccluster/examples <br/> order deny, allow <br/> allow from all <br/> </location> </textarea>* Lbmethod configuration instructions:
Lbmethod = byrequests balanced by the number of requests (default)
Lbmethod = bytraffic traffic balancing
Lbmethod = bybusyness balanced by the degree of busy (always allocated to the server with the least number of active requests)
* In the balancermember configuration, route = Tomcat <ID> is the server in Tomcat. the jvmroute value in the XML configuration. In this way, if both Tomcat servers are available, requests from the same browser will be forwarded to the same Tomcat server. 4. make sure that apachehost and two Tomcat hosts can communicate with each other, and the two Tomcat machines are in the same network segment; 5. make sure that the two Tomcat host multicast is enabled. You can use CAT/proc/NET/dev_mcast on the Linux machine to check whether the file exists; in addition, make sure that the/etc/hosts file of the two Tomcat machines contains "XXX. xxx. xxx. xxx hostname "such as" 172.17.1.101 tomcathost1 "or" 172.17.1.102 tomcathost2 "; 6. modify the conf/Server of two Tomcat servers. add jvmroute = "tomcat1" and jvmroute = "tomcat2" to the engine node, and add the following content: <Cluster classname = "org. apache. catalina. ha. TCP. simpletcpcluster "<br/> channelsendoptions =" 6 "> </P> <p> <manager classname =" org. apache. catalina. ha. session. deltamanager "<br/> expiresessionsonshutdown =" false "<br/> yylistenersonreplication =" true "/> <br/> <! -- <Br/> <manager classname = "org. apache. catalina. ha. session. backupmanager "<br/> expiresessionsonshutdown =" false "<br/> notifylistenersonreplication =" true "<br/> mapsendoptions =" 6 "/> <br/> --> <br/> <channel classname = "org. apache. catalina. tribes. group. groupchannel "> <br/> <membership classname =" org. apache. catalina. tribes. membership. mcastservice "<br/> address =" 228.0.0.5 "<br/> Port =" 45564 "<br/> frequency =" 500 "<br/> droptime =" 3000 "/> <br/> <er classname = "org. apache. catalina. tribes. transport. NIO. nioreceiver "<br/> address =" Auto "<br/> Port =" 4000 "<br/> selectortimeout =" 100 "<br/> maxthreads =" 6 "/> <br/> <sender classname = "org. apache. catalina. tribes. transport. replicationtransmitter "> <br/> <transport classname =" org. apache. catalina. tribes. transport. NIO. pooledparallelsender "/> <br/> </sender> <br/> <interceptor classname =" org. apache. catalina. tribes. group. interceptors. tcpfailuredetector "/> <br/> <interceptor classname =" org. apache. catalina. tribes. group. interceptors. messagedispatch15interceptor "/> <br/> </channel> <br/> <valve classname =" org. apache. catalina. ha. TCP. replicationvalve "filter = ". */. GIF ;. */. JS ;. */. JPG ;. */. PNG ;. */. htm ;. */. HTML ;. */. CSS ;. */. txt; "/> </P> <p> <clusterlistener classname =" org. apache. catalina. ha. session. jvmroutesessionidbinderlistener "/> <br/> <clusterlistener classname =" org. apache. catalina. ha. session. clustersessionlistener "/> <br/> </cluster>
7. create a web app, here to simply use the Tomcat built-in examples web app (webapps/examples), modify the WEB-INF/web. XML file. After adding the <display-Name> Servlet and jsp examples </display-Name> node, <distributable/> indicates that the application copies the session with the cluster server. 8. create a test under the webapps/examples directory of two Tomcat servers. JSP file, used to test the session replication of two Tomcat servers in the cluster, Code As follows: <HTML> <br/> <pead> <br/> <title> </title> <br/> </pead> <br/> <body> <br/> <% <br/> string mydata = request. getparameter ("mydata"); <br/> If (mydata! = NULL & mydata. Length ()! = 0) {<br/> session. setattribute ("mydata", mydata); <br/>}</P> <p> out. println ("request. getlocaladdr (): "+ request. getlocaladdr (); <br/> out. println ("<br/>"); <br/> out. println ("request. getlocalport (): "+ request. getlocalport (); <br/> out. println ("<br/>"); <br/> out. println ("session ID:" + session. GETID (); <br/> out. println ("<br/>"); </P> <p> out. println ("mydata:" + session. getattribute ("mydata ")); <br/> %> <br/> <form> <br/> <input type = text size = 20 name = "mydata"> <br/> <br /> <input type = submit> <br/> </form> <br/> </body> <br/> </ptml>
9. start Tomcat and Apache and access http: // apachehost/examples/. You can modify the value in the session, and you can see that the values in the two Tomcat sessions are the same; 10. visit http: // apachehost/balancer-manager. You can use this Server Load balancer Management page to dynamically enable/disable one of the Tomcat servers.

 

References:

Http://httpd.apache.org/docs/2.2/mod/mod_proxy.html

 

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.