TOMCAT: Cluster building based on Apache+tomcat

Source: Internet
Author: User

According to Tomcat's official documentation, it is possible to use the Tomcat configuration cluster to be used in conjunction with other Web servers, typically Apache and IIS.

This is done using the Apache+tomcat method to complete the cluster configuration based on Tomcat.

Software preparation

1) Apache HTTP Server:

Use Baidu search Httpd-2.2.25-win32-x86-no_ssl.msi, should be able to find a lot of relevant download links. Also available here is a: HTTP://VDISK.WEIBO.COM/S/C3TRK_UGGKRMC

2) Tomcat 7:

TOMCAT7 Download Link: http://tomcat.apache.org/download-70.cgi

3) Tomcat connector--JK:

http://mirrors.cnnic.cn/apache/tomcat/tomcat-connectors/jk/binaries/windows/

Open Connection Download version: Tomcat-connectors-1.2.40-windows-i386-httpd-2.2.x.zip

Cluster design

Here is a cluster design architecture diagram:

If you are using WebLogic or using a server such as GlassFish, you only need to follow the instructions to make the relevant configuration. But no matter what server you use, the architecture is the above.

Tomcat is a single-instance, which means that a tomcat can only be used as a server.

Tomcat Connector

Connector's role: Extradition of requests for different protocols to Tomcat's Web container. The requests that can now be processed in Tomcat can be divided into HTTP, AJP, HTTP requests, and HTTP requests that can include the APR mode, depending on the protocol.

Related Reference documents:

Http://tomcat.apache.org/connectors-doc/reference/apache.html

In addition, the configuration in the recipe can be found under such links.

Jk

JK is actually a tomcat Connector. Apache, IIS is a web Server that does not support the Jsp/servlet processing feature, and JK can be used to transition JSP/SERVERLT requests to Tomcat for Tomcat to handle.

Cluster construction

Here's how to build a clustered environment based on Apache +tomcat.

Apache server acts as the LB servers, and the other Tomcat instances act as server roles. Follow the steps below to quickly set up:

1 ) Install Apache Server

Software installation is not clear, and other software installation methods are the same.

2 ) Install Tomcat .

Unzip it and then copy it onto the disk. This is two Tomcat.

3 ) in Apache Server add JK in Module

Unzip the previously downloaded JK and place the mod_jk.so in the modules directory of the Apache server.

4 ) configuration Work.properties and Uriworkmap.properties

Work.properties as follows:

Worker.list=controller,s1,s2worker.s1.type=ajp13worker.s1.port=8009worker.s1.host=localhostworker.s1.lbfactor= 1worker.s2.type=ajp13worker.s2.port=9009worker.s2.lbfactor=1worker.s2.host=localhostworker.controller.type= Lbworker.controller.balanced_workers=s1,s2worker.controller.sticky_session=false

3 workers are configured, where the controller represents a LB server. The S1,S2 represents two tomcat servers. Configuration Description:

Uriworkermap.properties as follows:

/*=controller

The two files are then placed in the Conf directory of the Apache server. There is no provision for this in fact.

Other than that:

Worker.properties How to configure, you can refer to the documentation:

Http://tomcat.apache.org/connectors-doc/reference/workers.html

Uriworkermap.properties How to configure, you can refer to the documentation:

Http://tomcat.apache.org/connectors-doc/reference/uriworkermap.html

5) in Apache server under Configuration mod_jk.conf

Mod_jk.conf content is as follows:

# Load MOD_JK module LoadModule jk_module modules/mod_jk.so # Where to find Workers.properties jkworkersfile.  Properties Jkmountfile conf/uriworkermap.properties# Where to put JK logs Jklogfile Logs/mod_jk.log # Set the JK log level [Debug/error/info] Jkloglevel Info # Select the log Format Jklogstampformat "[%a%b%d%h:%m:%s%Y]" # jkoptions indicate to send SSL KEY SI ZE, Jkoptions +forwardkeysize +forwarduricompat-forwarddirectories # Jkrequestlogformat Set the request format JkRequest  Logformat "%w%V%T" # Send servlet for context/examples to worker named Ajp13 #JkMount/servlet/* Controller # Send JSPs For Context/examples to worker named Ajp13 #JkMount/* Controller

After the configuration is complete, place the files in the Conf directory of Apache server.

6 ) configuration httpd.conf , the introduction of JK

Open the httpd.conf file under the Conf directory of Apache server, and then add the following:

Include conf/mod_jk.conf

This configuration is to allow Apache server to load MOD_JK when it is started.

7 ) The Tomcat Configure as a clustered instance

When Tomcat is a cluster instance, it can be on a different machine or on the same machine, as long as it is configured to host and port. I have configured it on the same machine.

Here is the configuration of these two Tomcat ports:

Tomcat

S1 Port

S2 Port

Connector http/1.1

8001

9001

Connector ajp/1.3

8009

9009

Then configure the following:

For <engine name= "Catalina" defaulthost= "localhost" > Add Jvmroute, change to:

<engine name= "Catalina" defaulthost= "localhost" jvmroute= "S1" >

Remove the annotations before and after <cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>.

<engine name= "Catalina" defaulthost= "localhost" jvmroute= "S1" >

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

....

</Engine>

After configuration is complete

S1:

S2:

The cluster will be ready to build.

Accessing applications in a clustered environment

1) Create a web App Clustertest

Add index.jsp:

<Body>Hello, index.jsp.<BR><%=Session.getid ()%><%=Request.getlocalname ()%><%=Request.getlocalport ()%></Body>

Configure Web. XML to:

<?XML version= "1.0" encoding= "UTF-8"?><Web-appXmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xmlns= "Http://java.sun.com/xml/ns/javaee"Xmlns:web= "Http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemalocation= "Http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"ID= "webapp_id"version= "2.5">  <Display-name>Clustertest</Display-name>    <distributable/>  <welcome-file-list>    <Welcome-file>index.jsp</Welcome-file>  </welcome-file-list></Web-app>

Export to war file Clustertest.war using Eclipse.

2) Deploy Web Apps

Place the Clustertest.war in the two Tomcat WebApps directory.

3) Start the cluster:

Start Apacheserver, Tomcat (S1), Tomcat (S2) sequentially.

4) The browser accesses the Web app.

Input Link: http://localhost/ClusterTest can:

You can see the SessionID (the previous segment of the dot), the host name, the requested port number. Where the indication after the dot is the server name that handles the request. Constantly refresh the browser, Seesionid is the same, except that the server name is different.

You can also access S1 or S2 directly using your browser:

In fact, the use of Apache+tomcat has 3 options, reference: http://www.ibm.com/developerworks/cn/opensource/os-lo-apache-tomcat/index.html

If you want to configure the cluster using Iis+tomcat, you can refer to: http://tomcat.apache.org/connectors-doc/reference/iis.html

TOMCAT: Cluster building based on Apache+tomcat

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.