APACHE 2.2.8+tomcat6.0.14 Configuring Load Balancing

Source: Internet
Author: User

Target:Using Apache and Tomcat to configure a Web site that can be applied, to meet the following requirements: 1, Apache as Httpserver, behind the connection of multiple Tomcat application instances, and load balancing. 2, set the Session timeout for the system, including Apache and TOMCAT3, for the System screen file list, including Apache and Tomcat Note: This example takes a machine as an example, that is, the same machine is loaded with Apache and 4 tomcat. First, preparatory work: Installation of the program (provided that the installation of JDK1.5 more than the version)Apahce 2.2.8 Download: apache_2.2.8-win32-x86-no_ssl.msitomcat6.0.14 Download: Apache-tomcat-6.0.14.zip Direct decompression. second, the installation processAPAHCE installation directory: D:\Apache. Four Tomcat directories: Unzip yourself to (D:\Tomcat Cluster Server \). The installation process for tomcat6.0,tomcat6.01,tomcat6.02,tomcat6.03, respectively, is not described in detail. Third, the configuration 1 , Apache configuration 1.1 , httpd.conf configurationModify the Apache configuration file D:\Apache \conf\httpd.conf to remove the comments from the following module, which does not use mod_jk.so for Apache and Tomcat links, since the 2.X Apache itself has integrated mod_ The jk.so function. Simply remove the following lines of comments, equivalent to the previous use of mod_jk.so more cumbersome configuration. Here the main use of the agent method, it is so simple.
LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_connect_module modules/mod_proxy_connect.so
LoadModule Proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule Proxy_http_module modules/mod_proxy_http.so
LoadModule Proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule Proxy_balancer_module modules/mod_proxy_balancer.soFind it again.<ifmodule dir_module></ifmodule>Plus index.jsp modified into<ifmodule dir_module>directoryindex index.html index.jsp </IfModule> 1.1.1, join at the bottomProxyrequests off<proxy balancer://cluster>balancermember ajp://127.0.0.1:8009 loadfactor=1 route= Jvm1balancermember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2balancermember ajp://127.0.0.1:9001 loadfactor=1 Route=jvm3balancermember ajp://127.0.0.1:9003 loadfactor=1 route=jvm4</proxy> above four BalancermemberMembers are the Tomcat clusters that we configured. It will be explained later. 1.2 , httpd-vhosts.conf settingsNext, make the virtual host settings. Apache's virtual host settings are as follows: first, modify conf/httpd.conf to find (#Include conf/extra/httpd-vhosts.conf) Remove the comment. # Virtual Hostsinclude conf/extra/httpd-vhosts.conf at the bottom of the file (extra/httpd-vhosts.conf)<virtualhost *:80>ServerAdmin [email protected] ServerName localhostserveralias localhostProxypass/balancer://cluster/stickysession=jsessionid Nofailover=onproxypassreverse/balancer://cluster/</VirtualHost>Where the domain name and path are set according to your own situation and then set up the Tomcat virtual host 2 Configure Tomcat 2.1. Configure shutdown for serverWe need to run 4 different tomcat on a single machine and need to modify the different Tomcat's shut-off ports to avoid port occupancy. Where tomcat6.0 is not modified with the default value. Three other modifications. In tomcat6.01\conf, tomcat6.02\conf and tomcat6.03\conf under the server.xml found in the server, will: <server port= "8005" shutdown= " SHUTDOWN "> To <server port=" XXXX "shutdown=" SHUTDOWN ">xxxx here to represent different ports: my other three tomcat use 9005,8006, 9007 2.2. Configure EnginePut the original configuration Comment out, put the following sentence Remove Comments。 and marked jvmroute= "jvm2". <engine name= "Standalone" defaulthost= "localhost" jvmroute= "jvm2" > The following is the original configuration. <!--<engine name= "Catalina" defaulthost= "localhost" > Other (tomcat6.02 and tomcat6.03) are also configured. Note: The Jvmroute configuration is not the same. <engine name= "Standalone" defaulthost= "localhost" jvmroute= "jvm3" > <engine name= "Standalone" defaulthost= " localhost "jvmroute=" JVM4 "> 2.3. Configure ConnectorThe original default configuration. <!--Define an AJP 1.3 Connector on port 8009--><connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/& gt; This is the key to Apache and Tomcat links, and the foreground Apache communicates with Tomcat via the AJP protocol to achieve load balancing. You can also use the HTTP protocol. Notice how they connect to the communication, the red part above (port= "8009") is the interface of the connection.   Change the other three tomcat <connector port= "XXX"/>port to the above <proxy balancer://cluster>       #与tomcat6.0 correspondence, Route and <engine jvmroute= "JVM1" > corresponding. Balancermember ajp://127.0.0.1:8009 loadfactor=1 route=jvm1# and tomcat6.01 corresponding, route and <engine jvmroute= "JVM2" > Correspondence. Balancermember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2# corresponds to tomcat6.02, route and <engine jvmroute= "JVM3" > corresponding. Balancermember ajp://127.0.0.1:9001 loadfactor=1 route=jvm3# corresponds to tomcat6.03, route and <engine jvmroute= "JVM4" > corresponding. The ports in the Balancermember ajp://127.0.0.1:9003 loadfactor=1 route=jvm4</proxy> correspond to,tomcat6.01  AJP ports port:9009. tomcat6.02  AJP Port port:9001. tomcat6.03  AJP Port port:9003. Be sure to agree with the above. Also change the value of the Redirectport to be unique, making sure that four Tomcat are different. 2.5. Configure cluster (to be modified in each tomcat)The original configuration. <cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/> modified to the following code: <receiver port= "XX"/> Port is also guaranteed to be unique. <cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"   channelsendoptions= "6" >< Manager classname= "Org.apache.catalina.ha.session.BackupManager" expiresessionsonshutdown= "false" Notifylistenersonreplication= "true" mapsendoptions= "6"/><!--<manager classname= " Org.apache.catalina.ha.session.DeltaManager "expiresessionsonshutdown=" false "notifylistenersonreplication=" true "/>--><channel classname=" Org.apache.catalina.tribes.group.GroupChannel "><membership classname=" Org.apache.catalina.tribes.membership.McastService "address=" 228.0.0.4 "port=" 45564 "frequency=" "Droptime=" "/><receiver classname=" Org.apache.catalina.tribes.transport.nio.NioReceiver "address=" Auto "port=" 5001 "Selectortimeout=" "maxthreads=" 6 "/><sender classname=" Org.apache.catalina.tribes.transport.ReplicationTransmitter "><transport CLassname= "Org.apache.catalina.tribes.transport.nio.PooledParallelSender"/></sender><interceptor Classname= "Org.apache.catalina.tribes.group.interceptors.TcpFailureDetector"/><interceptor classname= " Org.apache.catalina.tribes.group.interceptors.MessageDispatch15Interceptor "/><interceptor classname=" Org.apache.catalina.tribes.group.interceptors.ThroughputInterceptor "/></channel><valve classname=" Org.apache.catalina.ha.tcp.ReplicationValve "filter=". *\.gif;. *\.js;. *\.jpg;. *\.png;. *\.htm;. *\.html;. *\.css;. *\.txt; " /><deployer classname= "Org.apache.catalina.ha.deploy.FarmWarDeployer" tempdir= "/tmp/war-temp/" deploydir= "/ tmp/war-deploy/"watchdir="/tmp/war-listen/"watchenabled=" false "/><clusterlistener className=" Org.apache.catalina.ha.session.ClusterSessionListener "/></cluster> This setting is primarily used for Tomcat clusters. Iv. Start the service and test the example of Tomcat's own1. Test Apache and Tomcat collaboration. Add the following test code section to the index.jsp under \webapps\root in each tomcat: (x for different Tomcat output different information), remove the index.html to avoid affecting the test effect. At the end of the Add. that is between </table></body>. <% System.out.println ("tomcat6.0x deal with Request");%> then pass HTTP///127.0.0.1When you visit, you will be familiar with cats and cats. And then by accessing HTTP/127.0.0.1:8080, http://127.0.0.1:9080,http://127.0.0.1:8081,http://127.0.0.1:9002 The content they access and the above 127.0.0.1is the same. This illustrates the success of Apache and Tomcat integration! 2. Test the Equalizer by HTTP///127.0.0.1Multiple visits, to see the real effect, you have to use a few stress test tools, Microsoft Web Application Stress tool for a simple stress test, or you can not keep on refreshing is reflected, you will only have a tomcat console output results. Using only the stress test tool to simulate a large number of simultaneous users, you will find four Tomcat consoles with control information indicating that the equalizer is working properly.

This article is from the "Interviewing Technical column" blog, please be sure to keep this source http://weijie.blog.51cto.com/340746/68195

APACHE 2.2.8+tomcat6.0.14 Configuring Load Balancing

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.