Apache + Tomcat server Load balancer in session sticky Mode

Source: Internet
Author: User

Apache HTTP Server is selected as the front-end Server Load balancer, and two Tomcat clusters are selected at the backend. The selected configuration method is session sticky (sticky session ), this method forwards requests from the same user to a specific Tomcat server to avoid session replication in the cluster. The disadvantage is that the user only communicates with one server, if the server is down, it will be abolished.
The model used is mod_proxy_ajp.so. The configuration is annotated in the tomcat configuration file. You only need to modify the configuration accordingly.
Apache HTTP server2.2.4 and tomcat5.5.16 are selected.
First install Apache HTTP server, then modify its configuration file HTTP. conf. First load three models,CodeAs follows:

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

Add the following code at the end of the configuration file: proxypass/balancer: // tomcatcluster/lbmethod = byrequests stickysession = JSESSIONID nofailover = off timeout = 5 maxattempts = 3
Proxypassreverse/balancer: // tomcatcluster/

<Proxy balancer: // tomcatcluster>
Balancermember AJP: // localhost: 8009 route =
Balancermember AJP: // localhost: 9009 route = B
</Proxy>

The preceding Code configures relevant proxy parameters. The <proxy> module defines the Server Load balancer configuration. Both Tomcat servers are configured on the same server, with ports 8009 and 9009 respectively, and configure the respective route, so that the Apache server can forward the request to a specific Tomcat Based on the route.
Next, modify the Tomcat server. xml file as follows: <! -- Define an AJP 1.3 connector on port 8009 -->
< Connector Port = "8009"
Enablelookups = "False" Redirectport = "8443" Protocol = "AJP/1.3" />

The port is the port set in the preceding <proxy> and the route is also configured. The Code is as follows:<! --Define the top level container in our container hierarchy-->
<EngineName= "Catalina"Defaulthost= "Localhost"Jvmroute= "">

Jvmroute must be the same as the preceding settings.

The following uses jmeter to perform a test on the configured Server Load balancer. First, start two Tomcat servers, then start Apache server, and create a test plan in jmeter, create test under JSP-Examples of two Tomcat servers. JSP (this jsp can be written in just two sentences), and then tested. The following is the result of some samplerers: HTTP Response Headers:
HTTP/1.1 200 OK
Date: Wed, 11 Jul 2007 02:17:55 GMT
Set-COOKIE:JSESSIONID = ac7ef1caa8c6b0feb68e77d7d375e2af. B; Path =/JSP-Examples
Content-Type: text/html; charset = ISO-8859-1
Content-Length: 3
Keep-alive: timeout = 5, max = 79
Connection: keep-alive

The above red code indicates that the JSESSIONID in the HTTP request has a route suffix ,. B indicates that the request will be forwarded to the Tomcat server where route is B. You will find that the JSESSIONID of some of the requests is suffixed. a, that is, it is forwarded to the Tomcat server whose route is.

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.