TOMCAT6_APACHE2.2_AJP load Balancing plus cluster combat sharing _tomcat

Source: Internet
Author: User
Tags documentation parent directory tomcat tomcat server

Environment:
--------------------------------------------
One apache2.2 server, three tomcat servers:

apache2.2 Server
1.ip:192.168.1.20
2. Only install Apache software: httpd-2.2.6.tar.bz2
Installation path:/usr/local/apache2

Tomcat server: All are configured with the same application.
1. Cluster Name: Balancer://tomcatcluster
2. Three Cluster server IP:
ip_1:192.168.1.31
ip_2:192.168.1.32
ip_3:192.168.1.33
3. Test application Folder in the WebApps directory of TOMCAT6

The operating system are: CentOS 4.5_x86
Jre:1.6:jdk-6u1-linux-i586-rpm.bin
tomcat6.0: Compiled binary package apache-tomcat-6.0.13.tar.gz
tomcat6.0 Installation path:/USR/LOCAL/TOMCAT6

Oralce's Jdbc:class12.jar

Path to package storage:/home/xiutuo/software/
Java Installation path:/usr/java/jdk1.6.0_01
Use normal User: Xiutuo to start Tomcat6
TOMCAT6 Boot auto start script:/etc/init.d/tomcat

Download path:
http://java.sun.com/javase/downloads/index.jsp
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++

A: Preface:

1.apache There are two ways to support Tomcat clustering:

A. After the apache2.1 version after the PROXY_AJP built.
B. For the apache2.1 version, through Tomcat's jk2.0.4 mod_jk2.so:
(This version has stopped developing)
The mod_jk2.so in the modules directory in the unpacked directory
The files are copied to the modules directory under the Apache installation directory.
********************
Two ways to compare:
PROXY_AJP configuration is simpler, mainly in PROXY_AJP currently only supports configuration to directory,
Pattern mode matching for file names is also not supported
(That is, it cannot be defined to work only with JSP files.)

And JK2 is configurable, but has stopped developing
********************

Official description of AJP and JK2:
JK2 has been put in maintainer mode and no further development would take place.
The reason for shutting down JK2 development is the lack of developers interest.
Other reason is lack of users interest in adopting JK2,
Caused by configuration complexity when compared to JK.

The latest official JK2 is 2.0.4.

JK2 'll have it ' s successor within core apache2.1/2.2 distribution.
We have developed new PROXY_AJP this is a addition to the Mod_proxy
and uses Tomcat ' s AJP protocol stack. It is developped in httpd-2.1
and integrated in it. We have also developed a new proxy_balancer
Module for load Balancing HTTP and AJP protocol stacks.

JK'll is fully supported for all other Web servers.
The next JK release are planned for the ' end of November.
Lots of code from JK2 has been ported to JK

2.tomcat Cluster Mode:
A.deltamanager
--The way it is now used: internal machine clusters are less used
B.backupmanager
********************
Two types of cluster methods official description:
Using the Deltamanager to replicate session deltas.
By all-to-all we mean so gets replicated to
All of the other nodes in the cluster. This works great for smaller cluster
But we don ' t recommend it for larger clusters (a lot of tomcat nodes).
Also when using the Delta manager it would replicate to all nodes,
Even nodes that don ' t have the application deployed.

To get around this problem and you'll want to use the Backupmanager.
This manager is only replicates the sessions data to one backup node,
And only to nodes that have the application deployed. Downside of
The Backupmanager:not quite as battle tested as the Delta Manager.
********************

3. Load balancing (load-balance) Definition:
With a large number of requests on the server side for a short period of time, a single server cannot respond to these requests in a short time,
At this point the server needs a mechanism to request a reasonable allocation of these requests according to the different load capabilities of multiple servers.

4. Cluster (cluster):
Share user information, resources, etc. among multiple servers.

tomcat6_apache2.2 load Balancing plus clustering: high availability to high expression.
Now with the cluster function related software oracle10g,mysql5,tomcat and so on.

Second: Software Installation

1.apache Server Installation:
Here the main introduction of APACHE2 source installation
# cd/home/xiutuo/software/
# TAR-ZVXF Httpd-2.2.6.tar.gz
# CD httpd-2.2.6
# mkdir-p/usr/local/apache2
#./configure \
--PREFIX=/USR/LOCAL/APACHE2 \
--ENABLE-MODULES=SO \
--enable-mods-shared=all \
--enable-proxy \
--enable-proxy-connect \
--ENABLE-PROXY-FTP \
--enable-proxy-http \
--ENABLE-PROXY-AJP \
--enable-proxy-balancer

Note: This test uses, compiles all the available modules, and activates the Tomcat cluster required
Enable-proxy,enable-proxy-http,enable-proxy-connect,enable-proxy-ajp
and Enable-proxy-balancer, where PROXY-AJP and Proxy-balancer must rely on proxy,
If it is a custom compilation, in addition to the above several necessary modules, Mod_status also need to compile, remember.
ENABLE-PROXY-FTP can not be compiled.
# make
# make Install

2. Three Tomcat Server installation

Mainly introduces the installation of JDK1.6U1 and TOMCAT6, three machines to repeat this work on it,
Of course remember IP must be set correctly.

jdk1.6 Installation
-------------------------------
A. Uninstall the system with its own JDK
# RPM-E J2sdk-1.4.1-fcs

B. Installing a new JDK
# Cd/home/xiutuo/software
Enter Package storage Directory

# chmod A+x Jdk-6u1-linux-i586-rpm.bin
Give it permission to execute

#./jdk-6u1-linux-i586-rpm.bin
Knock a few more spaces, and then when you see [yes], enter Yes, return
Then the jdk-6u1-linux-i586-rpm is generated in the current directory.

# RPM-IVH jdk-6u1-linux-i586-rpm

C. Setting Environment variables
Setting up only one user, not all users, can modify the ~/.cshrc,~/.bash_profile file.
Append the following paragraph, if you add an environment variable for all users and later users,
Append/etc/profie file.
The idea is not to repeat the additional * in profile and ~/.CSHRC or ~/.bash_profile

Over here:
# Vi/etc/profile
Java
If you install the J2SDK path is not the same, please modify your own

Java_home=/usr/java/jdk1.6.0_01
Export Java_home
Classpath=/usr/java/jdk1.6.0_01/lib:/usr/java/jdk1.6.0_01/jre/lib
Export CLASSPATH
Path= $PATH: $JAVA _home/bin: $JAVA _home/jre/bin
Export PATH
Jre=/usr/java/jdk1.6.0_01/jre
Export JRE

D: Effective immediately     
//If you modify the/etc/profile    
# Source/etc/profile     
//If you modify the ~/.cshrc    
# source ~/.cshrc     
//If you modify the ~/.bash_profile    
# source ~/.bash_profile    
   
E: Test Success no     
# java-version
Java (TM) SE Runtime Environment (Bui LD 1.6.0_01-b06)
Java HotSpot (TM) Client VM (build 1.6.0_01-b06, mixed mode, sharing)
See this message, OK
------------ ----------------------------------

TOMCAT6 Installation
TOMCAT6 more detailed installation please see the blog on the Tomcat article
----------------------------------------------
A. Install Tomcat,
# Cd/home/xiutuo/software//Enter Package storage directory
# TAR-ZVXF apache-tomcat-6.0.13.tar.gz/Decompression
# MV APACHE-TOMCAT-6.0.13/USR/LOCAL/TOMCAT6//Installation

# cd/usr/local/tomcat6/bin//Enter installation directory
# TAR-ZVXF jsvc.tar.gz/Decompression
# CD JSVC-SRC//Enter JSVC-SRC directory
# autoconf
#./configure--with-java=/usr/java/jdk1.6.0_01
# Remember to add Java JDK path when configure, otherwise you can't start Tomcat automatically with normal user boot

# make//compile generate Jsvc file
# CP Jsvc. Copy Jsvc to parent directory
# CD ... Back to the parent directory


# cd/usr/local/tomcat6/

Run the following command to enable Tomcat to run in daemon mode
#./BIN/JSVC-CP/bin/bootstrap.jar \
-outfile./logs/catalina.out \
-errfile./logs/catalina.err \
Org.apache.catalina.startup.Bootstrap

B. Configuring JDBC for Oralce
Copy Oracle JDBC to/usr/local/tomcat6/lib directory
# Cp/home/software/class12.jar/lib/.

C. Configuring Tomcat Users
# cd/usr/local/tomcat6/conf
# VI Tomcat-users.xml
The contents are as follows:
<?xml version= ' 1.0 ' encoding= ' utf-8 '?>
<tomcat-users>
<role rolename= "Tomcat"/>
<role rolename= "Role1"/>
<role rolename= "Manager"/>
<role rolename= "admin"/>
<user username= "Tomcat" password= "Tomcat" roles= "Tomcat"/>
<user username= "Role1" password= "Tomcat" roles= "Role1"/>
<user username= "Both" password= "Tomcat" roles= "Tomcat,role1"/>
<user username= "admin" password= "admin" roles= "Admin,manager"/>
</tomcat-users>
Please modify the password for all defined users in Tomcat: that is, modify password for the value you want.

D. Put the application Folder test under WebApps

3.tomcat load balancing and cluster configuration
Refer to official Configuration documentation:
Http://tomcat.apache.org/tomcat-6.0-doc/cluster-howto.html
Http://tomcat.apache.org/tomcat-6.0-doc/balancer-howto.html

A.TOMCAT6 configuration file Server.xml and application Web.xml

* * Open load Balancing using port 8009 when using the AJP protocol (8080 port when using HTTP protocol)
* * Modify Tomcat's Conf/server.xml <Engine> (configuration when using AJP protocol)
Put
<!--should set Jvmroute to support load-balancing via AJP ie:
<engine name= "Standalone" defaulthost= "localhost" jvmroute= "jvm1" >
-->
<engine name= "Catalina" defaulthost= "localhost" >
Change into

<!--should set Jvmroute to support load-balancing via AJP ie:
-->
<engine name= "Standalone" defaulthost= "localhost" jvmroute= "TOMCAT1" >
<!--
<engine name= "Catalina" defaulthost= "localhost" >
-->
Description
The first Tomcat put jvmroute= "TOMCAT1"
The second Tomcat puts jvmroute= "TOMCAT2"
The third Tomcat puts Jvmroute= "TOMCAT3"


* * Open Cluster
* * Modify Tomcat's Conf/server.xml (configured when using AJP protocol)
In the <Engine> behind or <Host> simply add
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
You can also add more detailed parameters to the cluster configuration content (this is the official default, please modify the relevant parameters):

<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"
channelsendoptions= "8" >

<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= "3000"/>
     <receiver classname= " Org.apache.catalina.tribes.transport.nio.NioReceiver "
           address= "Auto"
          port= "4000"
           autobind= "+"
           selectortimeout= "5000"
          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"/>
</Channel>

<valve classname= "Org.apache.catalina.ha.tcp.ReplicationValve"
Filter= ""/>
<valve classname= "Org.apache.catalina.ha.session.JvmRouteBinderValve"/>

<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.JvmRouteSessionIDBinderListener"/>
<clusterlistener classname= "Org.apache.catalina.ha.session.ClusterSessionListener"/>
</Cluster>

* * * * web.xml Configuration Application
* * * in each WEBAPPS application, modify the profile Web.xml file add element <distributable/>
in Web.xml file <web-app> element, add the following:
<!--This application will replicate with the cluster Server session-->
<distributable/>
Specific modifications are as follows:
before modifying:
<?xml version = "1.0" encoding= "iso-8859-1"?>
<web-app xmlns= "Http://java.sun.com/xml/ns/javaee"
xmlns:xsi= "http://" Www.w3.org/2001/XMLSchema-instance "
xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee http:// Java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
version=" 2.5 ">
</web-app>
Modified:
<?xml Version= "1.0" encoding= "iso-8859-1"?>
<web-app xmlns= "Http://java.sun.com/xml/ns/javaee"
xmlns:xsi= " Http://www.w3.org/2001/XMLSchema-instance "
xsi:schemalocation=" Http://java.sun.com/xml/ns/javaee http:// Java.sun.com/xml/ns/javaee/web-app_2_5.xsd "
version=" 2.5 ">
<!--This application will replicate with the cluster server session-->
< Distributable/>
</web-app>

4. Configure Apache AJP load Balancing function, be sure to enable reverse proxy here.
******************************
For the principle, please refer to the official documentation.

The typical use of forward proxies is to provide access to the Internet for LAN clients within the firewall.
The forward proxy can also use buffering features (provided by Mod_cache) to reduce network usage.

A typical use of a reverse proxy is to provide the server behind the firewall to Internet user access.
The reverse proxy can also provide load balancing for multiple servers on the back end, or provide buffering services for slower servers on the back end.
In addition, you can enable advanced URL policies and management techniques so that Web pages that are in different Web server systems
exists in the same URL space.
*****************************

Reference Documentation:
TOMCAT6 Official documents
Http://tomcat.apache.org/tomcat-6.0-doc/balancer-howto.html
Apache Chinese version
Http://man.chinaunix.net/newsoft/ApacheMenual_CN_2.2new/mod/mod_proxy.html
Http://man.chinaunix.net/newsoft/ApacheMenual_CN_2.2new/mod/mod_proxy_balancer.html
Apache official English version
Http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
Http://httpd.apache.org/docs/2.2/mod/mod_proxy_balancer.html

Configure Apache
modifying/usr/local/apache2/conf/httpd.conf files

Be sure to remove the comments for the following module
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.so
LoadModule Status_module modules/mod_status.so

And on the last side, increased
<Location/server-status>
SetHandler Server-status
Order Deny,allow
Deny from all
Allow from all
</Location>
<Location/balancer-manager>
SetHandler Balancer-manager
Order Deny,allow
Deny from all
Allow from all
</Location>
Proxyrequests off
Proxypass/test Balancer://tomcatcluster/stickysession=jsessionid Nofailover=on

<proxy balancer://tomcatcluster>
Balancermember ajp://192.168.1.30:8009 loadfactor=1
Balancermember ajp://192.168.1.31:8009 loadfactor=2
Balancermember ajp://192.168.1.32:8009 loadfactor=3
</Proxy>
Comments:
Proxyrequests off indicates that the reverse proxy is enabled.
Proxypass the URL forwarded for the agent to forward all access/requests to
Cluster Balancer://tomcatcluster, where/test forward all access/requests to the cluster balancer://tomcatcluster/test directory

Balancermember is a member of the cluster,
Cluster Server 1 or 2 or 3, the load balancing server sends the request to the Balancermember according to the Equalization rules.

Once configured, start the APAHCE server and visit localhost to see the results of the application returned from the cluster server.

Access to Http://192.168.1.20/balancer-manager to display load balancing related information


5. Debug load Balanced cluster system

Before debugging, be sure to:
Start the Tomcat service for the three TOMCAT6 servers first!
Then open Apache server Apache service, remember!

A. Opening tomcat services
# Cd/usr/local/tomcat6/bin
#./shutdown.sh/Stop Tomcat
#./start.sh/Start Tomcat

To view the process of Tomcat:
# Ps-e | grep java
This process of Java shows that your tomcat is up.

B. Open Apache Service
# Cd/usr/local/apache2/bin
#./apachectl Configtest
command to check the configuration is incorrect, display syntax OK, indicating that the configuration is correct
#./apachectl Stop/Halt Apache
#./apachectl Start/Launch Apache

6. Test whether load balanced cluster system succeeds

Accessing the Web services of the Apache server
Http://192.168.1.20/balancer-manager
If information about load balancing is displayed, it is successful.
Then you can access Http://192.168.1.20/test, which accesses the Tomcat test application.

7. Specific Tomcat cluster load Balancing optimization Please refer to the documentation to set the relevant parameters
Specific Apache optimization Please refer to the documentation to set the relevant parameters

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.