Configure Apache tomcat to achieve load balancing

Source: Internet
Author: User
Tags server port apache tomcat

AJP is a protocol that Apache provides to complete communication with other servers. In Apache through the MOD_PROXY_AJP module to send AJP data, the other end of the server needs to implement the AJP protocol, can accept the MOD_PROXY_AJP module sent AJP protocol data, after receiving the AJP protocol data to do appropriate processing, The processing results can be sent back to the MOD_PROXY_AJP module in the AJP protocol.

When using a separate server, a local Web server is used on the front end of the Tomcat instance, and performance is much worse than using Tomcat and its default HTTP connection alone, even though a considerable portion of the Web application itself is composed of static files. If you need to integrate Tomcat with a local Web server, the AJP connection is superior to proxy HTTP and provides better performance. From the Tomcat point of view, AJP is the most effective. It also has the same HTTP functionality (when using a single server, the performance time using a native webserver in front of the Tomcat instance I s most of the time significantly worse than a standalone Tomcat with it default HTTP connector, even if a large part of T He web application is made of static files. If integration with the native webserver are needed for all reason, an AJP connector'll provide faster performance p Roxied HTTP. AJP clustering is the most efficient from the TOMCAT perspective. It is otherwise functionally equivalent to HTTP clustering.)

With this protocol, there is a higher performance because it uses binary transmissions. Higher efficiency than HTTP text transfer. In Apache you want to use Mod_proxy and MOD_PROXY_AJP, and in Tomcat you open the AJP service.

First, preparatory work: Installation of the program (the prerequisite to ensure that the JDK1.5 has been installed above the version)
Apahce 2.2.4

TOMCAT6.0
Second, the installation process
APAHCE installation directory: D:\Apache group\apache2.
L Two Tomcat directory: uncompressed to (D:\Apache group\ Cluster Server \). For Tomcat6_1,tomcat6_2, these few installation procedures are not explained in detail.

Third, the configuration
1, Apache Configuration
1.1, httpd.conf Configuration
Modify Apache configuration file D:\Apache group\apache2\conf\httpd.conf
Remove the comments from the following module, which do not use mod_jk.so for Apache and Tomcat links, and since 2.X the Apache itself has integrated mod_jk.so functionality. Simply take the following lines off the annotation, which is equivalent to the previous use of mod_jk.so more cumbersome configuration. Here the main use of the AJP agent method, it is so simple.

Remove the comments below: (in fact, the comment off the first three lines is OK, because the use of the AJP agent)

LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule Proxy_connect_module modules/mod_proxy_connect.so
LoadModule Proxy_http_module modules/mod_proxy_http.so
LoadModule Proxy_ftp_module modules/mod_proxy_ftp.so

And then find <ifmodule dir_module></ifmodule> plus index.jsp modified into
<ifmodule dir_module>
DirectoryIndex index.html index.jsp
</IfModule>

1.1.1, join at the bottom
Proxyrequests off
<proxy balancer://cluster>
Balancermember ajp://127.0.0.1:8109 loadfactor=1 route=jvm1
Balancermember ajp://127.0.0.1:8209 loadfactor=1 route=jvm2
</proxy>
The above two Balancermember members are our configured Tomcat cluster, pay attention to the red port number above, with TOMCAT1 server.xml <connector port= "8109" protocol= "ajp/1.3" redirectport= "8443"/> Tomcat2 for

<connector port= "8209" protocol= "ajp/1.3" redirectport= "8443"/>

 1.2, httpd-vhosts.conf set  
next to the settings for the virtual host. The Apache virtual host settings are as follows:  
First Modify  conf/httpd.conf find (#Include conf/extra/httpd-vhosts.conf)  
Remove the annotations. &NBSP
# Virtual hosts 
Include conf/extra/httpd-vhosts.conf 
in file (extra/ httpd-vhosts.conf) Join   at the bottom;
<virtualhost *:80> 
          serveradmin 979398098@qq.com
         ServerName localhost &NBSP
         serveralias localhost 
          Proxypass/balancer://cluster/stickysession=jsessionid nofailover=on 
         proxypassreverse/balancer://cluster/ 
</virtualhost >&NBSP
where the mailboxes, domain names, and paths are set according to your own  
and then set up Tomcat virtual host  
 

2  configuration  tomcat 
2.1.   configuration  server  shutdown  
We need to run a different  2 on a single machine. &NBSP;TOMCAT&NBSP, you need to modify the different  tomcat  closing ports to avoid the occurrence of the port being occupied. Where tomcat6.0 with the default value, not modified. Three other modifications. In tomcat6_1\conf, tomcat6_2\conf  server.xml  found  server,  will:  
<server port= "8005" shutdown= "Shutdown" > 
to  
<server port= "XXXX" shutdown= "shutdown" >&NBSP;
xxxx  This represents a different port: My two  tomcat  use  8105,8205 separately.

2.2. Configure Engine
Comment out the original configuration, and remove the annotation from the following sentence. and marked jvmroute= "JVM1".
<engine name= "Standalone" defaulthost= "localhost" jvmroute= "jvm1" >
The following is the original configuration.
<!--<engine name= "Catalina" defaulthost= "localhost" >-->
Tomcat6_2 will also be configured. Note: Jvmroute configuration is not the same.
<engine name= "Standalone" defaulthost= "localhost" jvmroute= "jvm2" >
2.3. Configure Connector
The original default configuration.
<!--Define a AJP 1.3 Connector on port 8009-->
<connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/>
This is the key to Apache and Tomcat links (as mentioned before), and the front desk Apache communicates with Tomcat through the AJP protocol to achieve load balancing. You can also use the HTTP protocol. Notice how they connect to the communication, and the red section above (port= "8009") is the interface of the connection.
My two Tomcat is set to 8109 and 8209, respectively.

Note that this port must be associated with httpd. The corresponding port in Conf is the same

Balancermember ajp://127.0.0.1:8109 loadfactor=1 route=jvm1

2.5. Configure cluster (to be modified in each tomcat)
The original configuration.
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
Modify to the following code: <receiver port= "XX"/>port also to ensure uniqueness.
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster" channelsendoptions= "6" >
<manager classname= "Org.apache.catalina.ha.session.BackupManager"
Expiresessionsonshutdown= "false"
Notifylistenersonreplication= "true"
mapsendoptions= "6"/>
<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"/>
<receiver 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"/> <

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.