Apache + Tomcat load balancing in CentOS

Source: Internet
Author: User

The combination of apache and tomcat is still quite large. To use jsp, most companies adopt apache + tomcat:

I. System Version: Centos 5.3 64-bit System

 
 
  1. Nginx version: httpd-2.2.13.tar.bz2

  2. Jdk version: 1.6.0 _ 18_64

  3. Tomcat version: Apache Tomcat/6.0.30

  4. Other similar versions are supported! The package required for service installation is as follows: Download the integration section of this website:

  5. Download jdk from the following website: Select jdk of your system.

  6. Https://cds.sun.com/is-bin/INTERSHOP.enfinity/WFS/CDS-CDS_Developer-Site/en_US/-/USD/ViewFilteredProducts-SingleVariationTypeFilter

  7. Download Apache and Tomcat to/usr/src]

  8. Cd/usr/src & wget http://blog.mgcrazy.com/download/?httpd-2.2.13.tar.bz2,apache-tomcat-6.0.30.tar.gz}

Ii. install Apache
 
 
  1. cd /usr/src && tar -jxvf httpd-2.2.13.tar.bz2 && cd httpd-2.2.13/srclib/apr &&./configure --prefix=/usr/local/apr &&make &&make install &&cd ../apr-util/ && ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr &&make&&make install && cd ../../ && ./configure --prefix=/usr/local/apache2 --enable-mods-shared=all --with-mpm=worker --enable-deflate --enable-cache --enable-disk-cache --enable-mem-cache --enable-file-cache --enable-proxy --enable-proxy-ajp --enable-proxy-balancer --enable-proxy-http --enable-rewrite --enable-charset-lite --disable-ipv6 --disable-dav --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

You can directly copy and install apache. [Note * install mod_proxy to process the Tomcat jsp page module. Install apr and apr-util to increase Tomcat processing performance. Of course, you can also use mod_jk, if it is mod_jk approach, you can refer to this article: http://bbs.linuxtone.org/thread-1195-1-1.html] III. Tomcat installation configuration: download the required package to the/usr/src directory; first install jdk: chmod o + x jdk *&&. /jdk *; the package prompts you to press the Enter key. You can install the package as prompted. After decompression, the jdk1.6.0 _ 18 folder is generated in the current directory.
 
 
  1. Mkdir-p/usr/java & mv jdk1.6.0 _ 18/usr/java/

  2. Add the following statement to the end of vi/etc/profile:

  3. Export JAVA_HOME =/usr/java/jdk1.6.0 _ 18

  4. Export CLASSPATH = $ CLASSPATH: $ JAVA_HOME/lib: $ JAVA_HOME/jre/lib

  5. Export PATH = $ JAVA_HOME/bin: $ JAVA_HOME/jre/bin: $ PATH: $ HOMR/bin

  6. Source/etc/profile // make the environment variable take effect immediately

  7. Java-version // check the java version. if the version is 1.6.0 _ 18 and 64-bit, the installation is successful!

  8. Java HotSpot (TM) 64-Bit Server VM (build 16.0-b10, mixed mode)

  9. Apache-tomcat-6.0.30.tar.gz cd/usr/src & tar xzf

  10. Decompress the package and execute:

  11. Mv apache-tomcat-6.0.30/usr/local/tomcat_1 & cp/usr/local/tomcat_1/usr/local/tomcat_2-r

Set tomcat java Variables
 
 
  1. Cd/usr/local/tomcat_1/bin/& vi setenv. sh create a setenv. sh script file and add the following statement:

  2. JAVA_HOME =/usr/java/jdk1.6.0 _ 18

  3. JAVA_JRE =/usr/java/jdk1.6.0 _ 18/jre

  4. And copy the setenv. sh file to atat_2/bin:

  5. Cp-p/usr/local/tomcat_1/bin/setenv. sh/usr/local/tomcat_2/bin!

  6. Save and exit

  7. Check whether the *. sh file in the bin directory of the two tomcat servers has executable permissions. If not, go to the corresponding directory and execute chmod o + x *. sh!

  8. Create different directories for the two tomcat servers: mkdir-p/usr/webapps/{www_1, www_2}

  9. Modify the Tomcat_1 server. xml file as follows:

  10. <Enginename = "Catalina" defaultHost = "localhost" jvmRoute = "tomcat1">

  11. Add

  12. <Contextpath = "" docBase = "/usr/webapps/www_1" reloadable = "true"/>

  13. In the same way, set tomcat_2:

  14. <Enginename = "Catalina" defaultHost = "localhost" jvmRoute = "tomcat2">

  15. <Contextpath = "" docBase = "/usr/webapps/www_2" reloadable = "true"/>

  16. Set the jvmroute names of the two tomcat servers to tomcat1 and tomcat2, which will be used in the apache configuration file later!

4. Configure the Apache Virtual Host to modify vhosts. conf
 
 
  1. NameVirtualHost *:80

  2. <VirtualHost *:80>

  3. ServerAdmin wgkgood@163.com

  4. DocumentRoot "/usr/webapps/www"

  5. ServerName 192.168.2.79

  6. <Directory "/usr/webapps/www ">

  7. AllowOverride None

  8. Options None

  9. Order allow,deny

  10. Allow from all

  11. </Directory>

  12. ProxyRequests Off

  13. RewriteEngine On

  14. ProxyPreserveHost On

  15. RewriteRule ^$ balancer://wwwCluster/ [P,L,NC]

  16. RewriteRule ^/(.*)$ balancer://wwwCluster/$1 [P,L,NC]

  17. <Proxy balancer://wwwCluster>

  18. BalancerMember ajp://localhost:8411 route=tomcat1

  19. BalancerMember ajp://localhost:8412 route=tomcat2

  20. </Proxy>

  21. </VirtualHost>

As shown above, ports 8411 and 8412 are the AJP ports of two tomcat servers and can be modified as needed. In this case, all configurations are complete! Start apache OK! Create an index. jsp file in both tomcat release directories and enter the following content:
 
 
  1. <body>

  2. <%=new java.util.Date()

  3. %>

  4. </body>

The second machine writes the following content:
 
 
  1. <body>

  2. <%=new java.util.Date()

  3. %>

  4. </body>

Then, access http: // 192.168.2.79. Different pages are displayed, that is, the content of two tomcat servers.


This article from the "Wu guangke-Focus on automated O & M" blog, please be sure to keep this source http://wgkgood.blog.51cto.com/1192594/558220


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.