Tomcat Cluster Setup

Source: Internet
Author: User

about how to build a Tomcat cluster online or can find a lot of relevant tutorials, here combined with my own in the actual application of the operation to do the next memo.

Case Description:

The cluster is done here with 2 Tomcat deployed natively. Of course, the Tomcat cluster can be distributed, and the difference is only in the address-port configuration, which is discussed later in the article.

Deployment environment:

6.01.6. 0_45

Cluster composition:

httpd + tomcat + mod_jk

Version selection:

httpd-2.2.  - Apache-tomcat-7.0.  the mod_jk-1.2. -httpd-2.2. 3 #这里写的是httpd -2.2.3, but in fact it fits with httpd-2.2.26.

The above documents (all I downloaded from the Apache official website) I have done the package and upload to the Baidu cloud disk, the need for friends can use the following link to download:

http://pan.baidu.com/s/1mg1i1v6

After uploading the required files to the server, we are ready to build.

1. First install the httpd, the process is simple as follows:

#解压httpd包 tar -zxf httpd-2.2. . Tar . GZCD httpd-2.2. /#配置预编译选项, here only the output directory is available. /configure--prefix=~/apache2# compile make#安装 makeinstall

2. Deploying Tomcat

#解压tomcat包, and copied into 2 copies tar -zxf apache-tomcat-7.0. A. Tar . GZ MV apache-tomcat-7.0. tomcat1/CP -R tomcat1/tomcat2/

2.1 Configure the Tomcat property, here is the example of TOMCAT1, 2 ( the main place to note here is the port, do not cause conflicts when set ):

#修改tomcat配置文件server. XML, main modifications: Shutdown port, connect service port, AJP Port<server port="8006"shutdown="SHUTDOWN"><connector port="8081"Protocol="http/1.1"redirectport="8443"/><connector port="8010"Protocol="ajp/1.3"redirectport="8443"/>#修改集群名称和tomcat别名<engine name="Catalina"defaulthost="localhost"Jvmroute="TOMCAT1">#去掉cluster节点的注释<cluster classname="Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>#修改以上端口是为了避免本机内多个tomcat同时运行造成端口冲突 # Modify the Tomcat configuration file context.xml to<Context> node Increase distributable="true"Property

Similarly, the configuration of the TOMCAT2:

#修改tomcat配置文件server. XML, main modifications: Shutdown port, connect service port, AJP Port<server port="8007"shutdown="SHUTDOWN"><connector port="8082"Protocol="http/1.1"redirectport="8443"/><connector port="8011"Protocol="ajp/1.3"redirectport="8443"/>#修改集群名称和tomcat别名<engine name="Catalina"defaulthost="localhost"Jvmroute="TOMCAT2">#去掉cluster节点的注释<cluster classname="Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>#修改以上端口是为了避免本机内多个tomcat同时运行造成端口冲突 # Modify the Tomcat configuration file context.xml to<Context> node Increase distributable="true"Property

2.2 Add a test file for Tomcat and post-test cluster performance using:

<!--edit webapps/test/test.jsp, used primarily to test load balancing scenarios -<%@ Page ContentType="text/html; charset=gb2312" %><HTML>    <Head>        <title>Tomcat-cluster-test-page</title>    </Head>    <Body>SessionID:<%=Session.getid ()%>     </Body></HTML>

OK, basically the configuration of Tomcat is here to end.

3. Add the cluster configuration file for httpd

#在apache2/conf/add content in the wokers.properties file # file under the following form: #serverworker. List=Loadbalancer#tomcat1worker.tomcat1.port=8010#该端口是tomcat1的AJP服务端口, set the method as shown in the following section Worker.tomcat1.host=localhost #如果tomcat部署在其他机器上, can fill out its server IPworker.tomcat1.type=Ajp13worker.tomcat1.lbfactor=1#tomcat2worker. Tomcat2.port=8011#该端口是tomcat2的AJP服务端口, set the method as shown in the following section Worker.tomcat2.host=Localhostworker.tomcat2.type=Ajp13worker.tomcat2.lbfactor=1#loadbalancerworker. Loadbalancer.type=lbworker.loadbalancer.balance_workers=tomcat1,tomcat2worker.loadbalancer.sticky_session=1

3.1 After extracting mod_jk apache2/modules and naming the file as mod_jk.so, then modify the configuration file as follows:

#编辑apache2/conf/httpd.conf, add configuration at bottom: #加载mod_jk模块LoadModule jk_module modules/mod_jk.so# Specify load Balancer profile Jkworkersfile conf/workers.properties# define log output Jklogfile logs/mod_jk.logjkloglevel Debug #将任意请求都交由loadbalancer控制器处理JkMount  /*  loadbalancer

3.2 Handwriting A boot controller for httpd:

#!/bin/bash#file: Run.SH# what:httpd-controler, Usage:run.SH[OPTIONS] <start|status|stop> Case " $" inchstart)/tomcat/apache2/bin/apachectl-f/tomcat/apache2/conf/httpd.confEcho "apache-httpd started."        ;; Stop)Kill-term 'Cat/ecis3/apache2/logs/Httpd.pid 'Echo "apache-httpd stopped."        ;; Status)if[-Z"' ps-ef|grep httpd|grep-v grep '"]; Then            Echo "apache-httpd not started."        Else            Echo "apache-httpd is running."        fi        ;; *)        Echo "Usage: $ [OPTIONS] <start|stop|status>"        ;;Esac

4. Launch Tomcat and HTTPD:

Tomcat1/bin/startup. SH tomcat2/bin/startup. SH apache2/bin/run. SH start

After booting, access to the http://localhost:8080/test/test.jsp through the browser, the page appears normal:

So let's find a machine to test the load Balancer performance, the test results are as follows:

 [[email protected] ~/test]$for  ((I= 0 ; I<1000 ; I++ > do  > wget  http:// 192.168.1.100:8080/test/test.jsp 2>/dev/null  > done  [[email protected]  ~/test]$awk -F.   /sessionid/{a[$2]++}end{for (i in a) {print I, A[i]}}   " test.jsp*500  tomcat2  500  

From the results: After the load, Tomcat received almost 1:1 of the request, or good.

The above is the Tomcat cluster construction of the whole process, the article if there are inappropriate for everyone please enlighten.

Tomcat Cluster Setup

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.