Configure Server Load balancer in APACHE2.2.8 + TOMCAT6.0.14

Source: Internet
Author: User

Objective: To use apache and tomcat to configure a web site that can be applied, you must meet the following requirements: 1. Use Apache as an HttpServer, and connect multiple tomcat application instances to achieve load balancing. 2. Set the Session Timeout time for the system, including Apache and tomcat. 3. List of blocked files for the system, including Apache and tomcat. Note: This routine uses a machine as an example, that is, one apache and four Tomcat servers are installed on the same machine. I. Preparations: the installation program (ensure that JDK or later versions are installed) is directly decompressed by APAHCE unzip. Ii. installation directory of APAHCE: D: \ Apache. Four TOMCAT directories: decompress them to (D: \ Tomcat Cluster Server. The installation process is not described in detail in tomcat6.0, tomcat6.01, tomcat6.02, and tomcat6.03 respectively. Iii. Configuration 1. Apache configuration 1.1 and httpd. conf configuration modify APACHE configuration file D: \ Apache \ conf \ httpd. conf removes the comments of the following modules. mod_jk.so is not used to link apache and tomcat. after X, apache has integrated the mod_jk.so function. Simply remove the comments of the following lines, which is equivalent to the tedious configuration with mod_jk.so. Here we mainly use the proxy method, which is so simple. LoadModule proxy_module modules/mod_proxy.so LoadModule proxy_connect_module modules/mod_proxy_connect.so LoadModule modules/mod_proxy_ftp.so LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule modules/mod_proxy_ajp.so LoadModule modules/modules and find <IfModule dir_module> </IfModule> add index. modify jsp to <IfModule dir_module> Di RectoryIndex index.html index. jsp </IfModule> 1.1.1. Add ProxyRequests 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> the above four BalancerMember members are the tomcat cluster we configured. It will be explained later. 1.2. httpd-vhosts.conf settings are followed by virtual host settings. APACHE's Vm settings are as follows: First modify conf/httpd. conf to find (# Include conf/extra/httpd-vhosts.conf) and remove the comments. # Virtual hostsInclude conf/extra/httpd-vhosts.conf add <VirtualHost *: 80> ServerAdmin ServerName localhost ServerAlias localhost ProxyPass/balancer: // cluster/stickysession = jsessionid nofailover = On ProxyPassReverse/balancer: // cluster/</VirtualHost> the domain name and path are set based on your own situation, and then set TOMCAT virtual host 2 to configure tomcat 2.1. to disable the server, we need to run four different tomcat servers on one machine. We need to modify the closing ports of different tomcat servers to avoid port occupation. Status. Tomcat6.0 uses the default value, which is not modified. The other three modifications. In tomcat6.01 \ conf, tomcat6.02 \ conf, and tomcat6.03 \ conf. find the server in xml, and set: <Server port = "8005" shutdown = "SHUTDOWN"> change to <Server port = "XXXX" shutdown = "SHUTDOWN"> XXXX indicates different ports here: the other three tomcat servers use 9007, 2.2, and respectively. configure the Engine to comment out the original configuration and remove the following sentence. Specify jvmRoute = "jvm2". <Engine name = "Standalone" defaultHost = "localhost" jvmRoute = "jvm2"> The following is the original configuration. <! -- <Engine name = "Catalina" defaultHost = "localhost"> --> other configurations (tomcat6.02 and tomcat6.03) must be the same. Note: The jvmRoute configuration should not be the same. <Engine name = "Standalone" defaultHost = "localhost" jvmRoute = "jvm3"> <Engine name = "Standalone" defaultHost = "localhost" jvmRoute = "jvm4"> 2.3. configure the default Connector configuration. <! -- Define an AJP 1.3 Connector on port 8009 --> <Connector port = "8009" protocol = "AJP/1.3" redirectPort = "8443"/> the key to connecting apache and tomcat, apache at the front end communicates with tomcat through the AJP protocol to achieve load balancing. You can also use the HTTP protocol. Note how they connect and communicate. The red part above (port = "8009") is the connection interface. Replace the <ctor port = "XXX"/> ports of the other three tomcat with the preceding <proxy balancer: // cluster> # Corresponds to tomcat6.0, route corresponds to <Engine jvmRoute = "jvm1">. BalancerMember ajp: // 127.0.0.1: 8009 loadfactor = 1 route = jvm1 # Corresponds to tomcat6.01, and route corresponds to <Engine jvmRoute = "jvm2">. BalancerMember ajp: // 127.0.0.1: 9009 loadfactor = 1 route = jvm2 # Corresponds to tomcat6.02, and route corresponds to <Engine jvmRoute = "jvm3">. BalancerMember ajp: // 127.0.0.1: 9001 loadfactor = 1 route = jvm3 # Corresponds to tomcat6.03, and route corresponds to <Engine jvmRoute = "jvm4">. BalancerMember ajp: // port in 127.0.0.1: 9003 loadfactor = 1 route = jvm4 </proxy> corresponds to the port in tomcat6.01 ajp port: 9009. tomcat6.02 ajp port: 9001. Port: 9003 on the ajp port of tomcat6.03 must be consistent with the above. At the same time, you must change the redirectPort value to unique to ensure that the four tomcat servers are different.. Configure the original configuration of Cluster (each tomcat has to be modified. <Cluster className = "org. apache. catalina. ha. tcp. SimpleTcpCluster"/> modify the code as follows: <javaser port = "XX"/> port must also be unique. <Cluster className = "org. apache. catalina. ha. tcp. simpleTcpCluster "channelSendOptions =" 6 "> <Manager className =" org. apache. catalina. ha. session. backupManager "expireSessionsOnShutdown =" false "yylistenersonreplication =" true "mapSendOptions =" 6 "/> <! -- <Manager className = "org. apache. catalina. ha. session. deltaManager "expireSessionsOnShutdown =" false "yylistenersonreplication =" 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 =" 500 "dropTime =" 3000 "/> <Cycler className =" org. apache. catalina. tribes. Transport. nio. nioReceiver "address =" auto "port =" 5001 "selectorTimeout =" 100 "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. ca Talina. 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 mainly used for tomcat clusters. 4. Start the service and test the built-in tomcat Example 1. Test apache and tomcat collaboration. Add the following test code under index. jsp under \ webapps \ ROOT in each tomcat: (X indicates that the output of different tomcat servers is different. Delete index.html to avoid affecting the test result. Add. Between </table> </body> at the end. <% System. out. println ("tomcat6.0X deal with request"); %> then you can use http: // 127.0.0.1 to access the System. Then access http: // 127.0.0.1: 8080, http: // 127.0.0.1: 9080, http: // 127.0.0.1: 8081, http: // 127.0.0.1:, http: // 127.0.0.1: 9002 they access the same content as http: // 127.0.0.1. This indicates that apache and TOMCAT are successfully integrated! 2. The test balancer has been accessed for multiple times through http: // 127.0.0.1. To see the real effect, you must use some Stress testing tools to perform simple Stress tests using Microsoft Web Application Stress Tool, otherwise, you will not be able to achieve this by constantly refreshing. You will only have output results on a tomcat console. You can use a stress testing tool to simulate simultaneous access by a large number of users. You will find that the four tomcat consoles have output control information, indicating that the balancer works properly. Author: wiselyman

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.