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 for the system... 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/your LoadModule proxy_ftp_module modules/your LoadModule proxy_http_module modules/your LoadModule proxy_ajp_module modules/your LoadModule modules/modules Add index. jsp DirectoryIndex index.html index. jsp 1.1.1 add ProxyRequests Off at the bottom 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 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 at the bottom of the file (extra/httpd-vhosts.conf) ServerAdmin ServerName localhost ServerAlias localhost ProxyPass/balancer: // cluster/stickysession = jsessionid nofailover = On ProxyPassReverse/balancer: // cluster/ Set the domain name and path 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. Tomcat6.0 uses the default value, which is not modified. The other three modifications. Find the server in tomcat6.01 \ conf, tomcat6.02 \ conf, and tomcat6.03 \ conf in server. xml: Change XXXX indicates different ports here: the other three tomcat servers use 9007, 2.2, respectively. configure the Engine to comment out the original configuration and remove the comment in the following sentence. And Mark jvmRoute = "jvm2 ". The following is the original configuration. Other configurations (tomcat6.02 and tomcat6.03) must be the same. Note: The jvmRoute configuration should not be the same. 2.3. configure the default Connector configuration. This is 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. Put the other three tomcat The port is changed # Corresponds to tomcat6.0, route and . BalancerMember ajp: // 127.0.0.1: 8009 loadfactor = 1 route = jvm1 # corresponds to tomcat6.01, route corresponds . BalancerMember ajp: // 127.0.0.1: 9009 loadfactor = 1 route = jvm2 # corresponds to tomcat6.02, route corresponds . BalancerMember ajp: // 127.0.0.1: 9001 loadfactor = 1 route = jvm3 # corresponds to tomcat6.03, route corresponds . BalancerMember ajp: // 127.0.0.1: 9003 loadfactor = 1 route = jvm4 Corresponding to the port in, the ajp port of tomcat6.01: 9009. The ajp port of tomcat6.02: 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. Modify to the following code: Port must also be unique.                           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.. <% 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
Related Article

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.