Apache+2tomcat Cluster and its tuning

Source: Internet
Author: User
First, cluster configuration 1.1 Required Software

a) Apache_2.2.4-win32-x86-no_ssl.msi;

b) Apache-tomcat-6.0.28.rar

c) configuration of mod_jk-apache-2.2.4.so 1.2 Apache

1. In the Apache installation directory in the Conf directory to find http.conf, at the end of the file plus the following sentence can be, the following figure:

Include conf/mod_jk.conf

2. Put the mod_jk-apache-2.2.4.so file in the following folder

Path: C:\Apache\Apache2.2\modules

3. http.conf the same directory under the new mod_jk.conf file, the contents are as follows:

#加载mod_jk Module

LoadModule Jk_module modules/mod_jk-apache-2.2.4.so

#指定 workers.properties file path

Jkworkersfile conf/workers.properties

#指定请求交给tomcat处理, "Controller" for the load allocation controller specified in Workers.propertise

Jkmount/* Controller

4. Create a new workers.properties file in the same directory as http.conf:

worker.list = Controller #server List

#========tomcat1========

worker.tomcat1.port=8009 #ajp13端口号, Server.xml configuration under Tomcat, default 8009

worker.tomcat1.host=10.2.121.184 #tomcat的主机地址, if not for this machine, please fill in the IP address

Worker.tomcat1.type=ajp13

Worker.tomcat1.lbfactor = 1 #server的加权比重, the higher the value, the more requests to be divided

#========tomcat2========

worker.tomcat2.port=8009 #ajp13端口号, Server.xml configuration under Tomcat, default 8009

worker.tomcat2.host=10.2.121.234 #tomcat的主机地址, if not for this machine, please fill in the IP address

Worker.tomcat2.type=ajp13

Worker.tomcat2.lbfactor = 1 #server的加权比重, the higher the value, the more requests to be divided

#========controller, load Balancing controller ========

Worker.controller.type=lb

WORKER.CONTROLLER.BALANCED_WORKERS=TOMCAT1,TOMCAT2 #指定分担请求的tomcat

Worker.controller.sticky_session=1

Worker.controller.recovery_options=3

#worker. controller.socket_keepalive=1

#worker. controller.connection_pool_size=50

#worker. controller.connection_pool_minsize=25

#worker. controller.connection_pool_timeout=600

#worker. controller.socket_timeout=20

Description:

The Recovery_options property describes how the Web server recovers after a tomcat failure has been detected. By default, Web server forwards the request to another tomcat in load-balanced mode. A property value of 0 indicates full recovery; The property value is 1, which means that if a failure condition occurs after Tomcat is received, no recovery is performed; The property value is 2, which means that if a failure condition occurs after Tomcat sends the HTTP headers to the client, no recovery is performed; The property value is 3. Explains that if a failure condition occurs after Tomcat is requested or if a failure condition occurs after Tomcat sends an HTTP header to the client, no recovery is performed. This property is added in the JK 1.2.6 version to avoid Tomcat crashes and problems that occur on the servlet engine that supports AJP13. This property defaults to full recovery.

By default,JK detects Tomcat's work, so it wastes a lot of resources, more than 1.6 times times the resources needed for Tomcat to work properly. If recovery is not detected, it is more efficient, can handle more than 2.6 times times the number of requests, and Tomcat is not dead-no response, but the number of errors than detect recovery after the number of errors is less, performance also enhanced 1.3 Tomcat configuration

Modify the TOMCAT1/TOMCAT2 configuration file Server.xml to set the Jvmroute:

L Configure the Tomcat configuration file (Server.xml) in the 184 server, as shown below:

L Configure the Tomcat configuration file (Server.xml) in 234 server, as follows: 1.4 cluster Test

1. Tomcat default home page in 184 server index.html

(Path:%tomcat_home%\webapps\root\index.html), added at the top of the page:

Access TOMCAT1

2. Tomcat default home page in 234 server index.html

(Path:%tomcat_home%\webapps\root\index.html), added at the top of the page:

Access TOMCAT2

3. Start Apache,tomcat1,tomcat2 and test:

Through http://localhost access, access to the Tomcat welcome interface shows a 234 tomcat node and a refresh once, showing the 184 Tomcat node being accessed, and seeing that the request will be handled in turn by TOMCAT1,TOMCAT2. Implementation of load Balancing

As shown in figure:

   two, Apache load balanced tuning

1. httpd.conf release httpd-mpm.conf, httpd-default.conf

Open httpd.conf configuration file

L Remove the # annotation before the #Include conf/extra/httpd-mpm.conf

L Remove the # annotation before the #Include conf/extra/httpd-default.conf

2. Configure httpd-mpm.conf

L through Httpd-l, I can see which module is deployed by Apache.

C:\Apache\Apache2.2\bin\httpd-l
Complied in Modules:
Core.c
Mod_win32.c
Mpm_winnt.c
Http_core.c
Mod_so.c

See that there are mpm_winnt.c, we are httpd-mpm.conf <ifmodule mpm_winnt_module> to configure

L Configure the Mpm_winnt_module module

<ifmodule mpm_winnt_module>
Threadlimit 350
Threadsperchild 350
Maxrequestsperchild 10000
Win32disableacceptex
Enablemmap off
Enablesendfile off
</IfModule>

3. Configure httpd-default.conf

Timeout50
KeepAlive on
Maxkeepaliverequests 100
KeepAliveTimeout 15

Note:timeout set Apache to wait for a continuous read and write operation of the length of time, that is, after the connection, Apache waiting for the client to complete the request to send the time, or after the corresponding start, Apache write data to the client connection length of time,
For that application, the default for 300 seconds is a bit too long, means that if the client has an unknown factor caused by a hysteresis connection, a server connection and all the resources corresponding to the 300 seconds, this is a bit too long for overloaded servers, it is recommended to set this value smaller, This length is sufficient to ensure that the application of various clients can pass the data normally. Depending on the connection status of the various clients and the server's busy level. generally set 3-5;
KeepAlive on
Using the stay connected feature, that is, the customer can only respond to one file at a time, it is recommended that the user set the value of this parameter to on, that is, the ability to keep the connection; If the same page contains a large number of static file applications, set to on to improve performance; If used primarily for dynamic page applications, to conserve memory resources; If the server runs with squid or other seven-tier devices, set to on;
Maxkeepaliverequests 100
When using the stay-connected feature, set a client request connection to be able to respond to the maximum upper limit of the file, that is, the number of requests per connection (maximum number of active long links). If this is set to "0", the number of requests is not limited. It is recommended that you set this value to a value between 100-500 to ensure optimal server performance.
KeepAliveTimeout 5
When using the stay-connect feature, two contiguous connection intervals of more than 5 seconds cut off the connection; that is, the number of seconds a server waits between two requests in a persistent connection, and a large keeplivetimeout value for a high load server can cause some performance problems, the greater the timeout value, The more connection processes are maintained with the idle client; Third, session replication control

For most clustered servers to prevent session loss, you need to consider session replication, which means that any of the added sessions of Tomcat are replicated to other Tomcat, and Tomcat in the cluster has the same session. The specific configuration process is as follows:

1. Remove the annotations in TOMCAT1 and TOMCAT2:

2. Modify the 4001 port in Tomcat to 4002:

3. Additional JVMROUTE,TOMCAT1 and TOMCAT2 are required:

  

Note:under the TOMCAT1 jvmroute= "TOMCAT1", Tomcat2 under Jvmroute= "Tomcat2".

4. Test session Replication

L in 184 server,%tomcat_home%\webapps\root directory, create test.jsp, content as follows:

<%@ page contenttype= "text/html; CHARSET=GBK "%>

<%@ page import= "java.util.*"%>

Server Info:

<%

Out. println (Request. getlocaladdr () + ":" + request. Getlocalport ()+"

");%>

<%

Out. println ("

ID "+ Session. getId ()+"

");

If you have a new session property setting

String dataname = Request. GetParameter ("Dataname");

if (Dataname!=null&& dataname. Length() >0) {

String DataValue = Request. GetParameter ("DataValue");

Session. setattribute (Dataname, DataValue);

}

Out. Print ("Session list");

Enumeration E = Session. Getattributenames ();

while (E.hasmoreelements()) {

String name = (String) e.nextelement();

String value = Session. getattribute (name). toString ();

Out. println (name + "=" + value+)

");

System.out. println (name + "=" + value);

}

%>

<form action= "index.jsp" method= "POST" >

Name: <input type=text size=20 name= "Dataname" >

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.