3 Ways to load a cluster with Apache and Tomcat

Source: Internet
Author: User

It took two days to learn about the integration of Apache and Tomcat, and now it's time to record the learning results.
Apache and Tomcat load cluster integration methods have 3 JK, Jk_proxy, Http_proxy
Software version used for this integration:

Apache:httpd-2.2.17-win32-x86-no_ssl.msi
Tomcat:apache-tomcat-6.0.20.zip
Jdk:jdk-6u14-windows-i586.exe


This test is a 1 Apache integrated with two tomcat.
Install Apache HTTP Server omitted, Access address is http://127.0.0.1:8081
Install Tomcat, unzip the Apache-tomcat-6.0.20.zip, and test when I put two Tomcat separately on a different virtual machine, one of which is the same virtual machine as Apache.
Two Tomcat named Worker2 and Worker3, respectively
First say the configuration of Tomcat.worker2:
Server.xml
(1) Configure the HTTP listening port, where the port is set to 8079, this step is not necessary, as long as there is no conflict on the line.

<connector port="8079" protocol="http/1.1" connectiontimeout="20000 " redirectport= "8443" />

(2) Configure the AJP listening port, where the port is set to 8077, this step is not necessary, as long as there is no conflict on the line.

<connector port="8077" protocol="ajp/1.3 " redirectport= "8443"/>

(3) Configure the server identity, where the identity name is configured as: Worker2, add jvmroute= "Worker2", the step must be.

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

In the engine node to enable the cluster configuration, just remove the cluster node before the comment on the line, the step must be configured to achieve session replication, if there is only one cluster, just under my configuration on the line, if more than one cluster, you can not press this configuration, The help documentation inside the Tomcat server is/docs/cluster-howto.html,/docs/config/cluster.html, which you need to refer to below.

<engine name="Catalina" defaulthost="localhost" jvmroute="Worker2">   < Cluster classname="Org.apache.catalina.ha.tcp.SimpleTcpCluster"/

To implement session replication, you also need to add the attribute distributable= "true" in Context.xml, as follows:

<context distributable="true">

If you do not want to add distributable= "true" to context.xml, there is another way to add <distributeable/> to the application's Web. XML, but this method is not tested.
Configuration complete, access address is: http://127.0.0.1:8079

The configuration of another Tomcat.worker3
Server.xml

<connector port="8078" protocol="http/1.1" connectiontimeout="20000 " redirectport= "8443" /><connector port="9009" protocol="ajp/1.3 " redirectport= "8443"/ ><engine name="Catalina" defaulthost="localhost" jvmroute="Worker3" > <cluster classname="Org.apache.catalina.ha.tcp.SimpleTcpCluster"/>

Context.xml configuration Tomcat.worker2.
Configuration complete, access address is: http://127.0.0.1:8078
Note: If two Tomcat is placed in the same machine, server.xml may also need to modify the other ports, confirming that two tomcat can start normally.

Add the same test file to the WebApps folder in Tomcat.worker2 and Tomcat.worker3 "test.jsp

<HTML><Head>  <title>HelloApp</title></Head><Body><%System.out.println ("Call test.jsp");%>SessionID:<%=Session.getid ()%>  </Body></HTML>

Access http://127.0.0.1:8078/test/test.jsp and http://127.0.0.1:8079/test/test.jsp to ensure successful access.

Now start the different ways Apache and Tomcat integrate
1. JK Mode Integration


Download mod_jk-1.2.31-httpd-2.2.3.so, please download the appropriate MOD_JK version, renamed to mod_jk.so in Modules folder
Modifying the conf/httpd.conf configuration

LoadModule jk_module modules/mod_jk.so
jkworkersfile conf/workers.properties
jklogfile Logs/mod_jk.log
jkloglevel Debug
jkmount/*.do LoadBalancer
jkmount/*.jsp LoadBalancer

Add a conf/workers.properties file, adding content

worker.list=Loadbalancerworker.worker2.port=8077#ajp的监听端口worker. Worker2.host=108.88.3.105Worker.worker2.type=Ajp13worker.worker2.lbfactor=1Worker.worker3.port=9009Worker.worker3.host=127.0.0.1Worker.worker3.type=Ajp13worker.worker3.lbfactor=1Worker.loadbalancer.type=lbworker.loadbalancer.balance_workers=Worker2,worker3 #这里在的worker2, Worker3 are consistent with aliases that need to be set on top tomcat worker.loadbalancer.sticky_session=1

Configure complete tasks, Access http://127.0.0.1:8081/test/test.jsp, and check for normal access.

2, Ajp_proxy


Remove the note from the httpd.conf file (delete #) to open the configuration below

Include conf/extra/httpd-vhosts.confloadmodule proxy_module modules/mod_proxy.soloadmodule proxy_ajp_module Modules /mod_proxy_ajp.soloadmodule Proxy_balancer_module Modules/mod_proxy_balancer.soloadmodule Proxy_connect_module Modules/mod_proxy_connect.soloadmodule Proxy_ftp_module Modules/mod_proxy_ftp.soloadmodule Proxy_http_module Modules/mod_proxy_http.so

Attention:
Except Mod_proxy.so,mod_proxy_balancer.so,mod_proxy_connect.so.
If the use of ajp_proxy, need to load mod_proxy_ajp.so this module;
If the use of http_proxy, need to load mod_proxy_http.so this module;

httpd.conf, delete the configuration content of the JK mode, add the configuration below

proxyrequests Off
<proxy balancer://loadbalancer>
balancermember ajp://127.0.0.1:9009 loadfactor=1 route=worker3
balancermember ajp://108.88.3.105:8077 loadfactor=1 route=worker2
</proxy>

conf/extra/httpd-vhosts.conf Add Configuration

<virtualhost *:8081>         ServerAdmin [email protected]         ServerName localhost         serveralias localhost          /balancer:///Loadbalancer/stickysession=jsessionid nofailover=on         Proxypassreverse/balancer://loadbalancer/         "Logs/loadbalancer-error.log" "Logs/loadbalancer-access.log "  common</virtualhost>          

Configure complete tasks, Access http://127.0.0.1:8081/test/test.jsp, and check for normal access.

3, Http_proxy
Http_proxy configuration is similar to Ajp_proxy, modify Method 2 httpd.conf configuration as follows, other unchanged

proxyrequests Off
<proxy balancer://balancermember http://127.0.0.1:8078 loadfactor=1 route= Worker3balancermember http://108.88.3.105:8079 loadfactor=1 route=worker2</ 

Configure complete tasks, Access http://127.0.0.1:8081/test/test.jsp, and check for normal access.

File Download:

http://download.csdn.net/download/li1669852599/8153513

3 Ways to load a cluster with Apache and 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.