Apache Tomcat Cluster

Source: Internet
Author: User
Tags server port apache tomcat

It took about two hours today to complete the Tomcat and Apache cluster. Now record, also hope to help the latter.


Before reading this blog, read the next my book Tomcat integrated Apache
After watching that, then the cluster, it is very fast.


As in the previous Tomcat integration Apache, the software version number for this cluster is as follows:
JDK 7, the version number of Tomcat 6.0.44,APACHE2.2.4,MOD_JK is 1.2.26.


Configure Apache

Change the httpd.conf under Apache

First change the Listen 80 to listen 81 or something else, we all know that 80 of this port is often occupied.
Add on the last line
Include "C:\Program Files (x86) \apache software foundation\apache2.2\conf\mod_jk.conf"
Then create a mod_jk.conf under the Conf folder and write
LoadModule jk_module Modules/mod_jk.sojkworkersfile conf/workers.properties# Specify those requests to Tomcat processing, "controller" Jkmount/*.jsp controller name for the load-distribution controllers specified in the Workers.propertise
If I had read my previous blog, MOD_JK's content would be easy to understand.


You see conf/workers.properties This line of code, very easy, relative path conf under the establishment of workers.properties

#serverworker. List = controller#========tomcat1========worker.tomcat1.port=18009worker.tomcat1.host= Localhostworker.tomcat1.type=ajp13worker.tomcat1.lbfactor = 1#========tomcat2========worker.tomcat2.port= 28009worker.tomcat2.host=localhostworker.tomcat2.type=ajp13worker.tomcat2.lbfactor = 1#========tomcat3======== Worker.tomcat3.port=38009worker.tomcat3.host=localhost worker.tomcat3.type=ajp13worker.tomcat3.lbfactor = 1 #===== ===controller, Load balancer controller ========WORKER.CONTROLLER.TYPE=LBWORKER.CONTROLLER.BALANCED_WORKERS=TOMCAT1,TOMCAT2, Tomcat3worker.controller.sticky_session=falseworker.controller.sticky_session_force=1#worker.controller.sticky _session=1
OK, fix it.

What is lbfactor for?

Assuming that TOMCAT1,TOMCAT2,TOMCAT3 's lbfactor are 2,5,4, then all requests will be assigned to TOMCAT1 processing, and 5/11 will give tomcat2 ....



Configuring Tomcat changes Port here, let me explain one point, a Tomcat has three port# each support http1.1 Connectorport, support ajp1.3 Connectorport and Tomcat serverport# Respectively for example the following:
<connector port= "8080" protocol= "http/1.1"                connectiontimeout= "20000"                redirectport= "8443"/>       ... <connector port= "8009" protocol= "ajp/1.3" redirectport= "8443"/> ... <server port= "8005" shutdown= "SHUTDOWN" >
Under normal circumstances, we are modifying 8080, which is the port that supports the http1.1 protocol.
Today, we need to execute three tomcat on a single machine, so this three Tomcat has a total of 9 ports that are all different.
In addition, in the workers.properties inside the worker.tomcat3.port=38009 this port also refers to the Tomcat Ajpport.

We have 3 Tomcat, it's best to put it together, like the following



First change the 9 port number, in order to clear, the TOMAT1 three ports each is 18080,18009,18005, the other two similar
Change engine changes every tomcat under Server.xml engine, followed by jvmroute= "TOMCAT1", of course tomcat2 Jvmroute is TOMCAT2, pay attention to this TOMCAT1, Tomcat2 and Workers.properties in the same.
<engine name= "Catalina" defaulthost= "localhost" jvmroute= "TOMCAT1" >
Add cluster this, in fact, do not need to write again, under the engine, the cluster would have been staring off, remove the gaze can
<cluster classname= "Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
Change Web. XML to copy three copies of a javaweb project into each tomcat/webapps, then change the Web. XML for each project
Add the following line to the Web-app root folder to allow the project to support the cluster.
<distributable/>


Try adding a JSP to each project's root folder (this JSP is from the network)
mytest.jsp<%@ page contenttype= "text/html; CHARSET=GBK "%><%@ page import=" java.util.* "%>Then we interview
http://localhost:81/PathTest/mytest.jsp


Refresh a few, add the name and value to see the following page:






Ok,session is unified in three Tomcat, the cluster is done


Several questions 1 originally had 3 Tomcat, we shut down one after, if is TOMCAT2, then after we refresh mytest.jsp again, will find only has TOMCAT1 and TOMCAT3 in processing request. OK, this is in line with our push. When we start tomcat2 again, and then refresh, we find that the request is still not sent to Tomcat2 # Suppose we start a session again (that is, open a browser again) discovery requests can be recycled in three Tomcat #
This indicates that Tomcat's request distribution mechanism is: for a session, first check which Tomcat can handle, the first time there are three, then use these three processing; Suppose that a certain check of the time, found that a tomcat can not be used, then let the session remember it, After the request will not give that Tomcat, even if the back of this tomcat can use, still do not give him plainly, you refuse me once, I am not looking for you! But after another session, two browsers are OK # can be understood as: "Listen to my sister said, you can, Then I'll give you one more chance. "~ ~ ~

The above is the understanding of Charyle. For a detailed review see http://www.iteye.com/topic/1017961


2 Do not forget, I am in pathtest this project, there are several JSP with the picture, we look at
http://localhost:81/PathTest/jsp/a.jsp
We interviewed, this place, can't find the picture
What to do?


Change the mod_jk to look like this.

LoadModule jk_module modules/mod_jk.sojkworkersfile conf/workers.properties # Set up a virtual host, define port for Bayi <virtualhost 127.0.0.1:81>     ServerName 127.0.0.1     documentroot "E:/cluster/tomcat1/webapps"     #定义站点项目所在路径, pointing the path Default site folder in Tomcat     directoryindex index.html index.htm index.jsp     errorlog logs/shsc-error_log.txt     # Specify those requests to be given to Tomcat processing, "controller" for the load assignment controller name specified in Workers.propertise jkmount/*.jsp controller </VirtualHost>


About VirtualHost and the overall Apache configuration, I am not very clear, in short, the above configuration can solve the problem of not finding JPG.

The following is a 2016-8-16 day change

Very ashamed, found that everyone is using TOMCAT8 or TOMCAT7, I this is still 6, but also lazy to upgrade

Let's read this blog:

http://blog.csdn.net/flyliuweisky547/article/details/21293071

Above is the cluster of TOMCAT8 and Apache.

Let's say Tomcat is going to put the session in Redis and look at the following blog

http://blog.csdn.net/caiwenfeng_for_23/article/details/45666831

///////////above is 2016-8-16 Day change

References http://www.iteye.com/topic/1017961

Apache Tomcat Cluster

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.