Apache and Tomcat load Cluster integration method configuration

Source: Internet
Author: User

Apache and Tomcat load cluster integration methods have 3 jk, jk_proxy, http_proxy

Apache:httpd-2.2.17-win32-x86-no_ssl.msi
Tomcat:apache-tomcat-6.0.20.zip

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.

[html]View PlainCopy
    1. <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.

[html]View PlainCopy
    1. <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.

[html]View PlainCopy
    1. <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.

[html]View PlainCopy
    1. <Engine name= "Catalina" defaulthost="localhost" jvmroute="worker2">
    2. <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:

[html]View PlainCopy
    1. <Context distributable="true">


If you do not want to add distributable= "true" to context.xml, there is another way to add a <distributeable/> in the Application's web. XML

Configuration complete, Access Address Is: http://127.0.0.1:8079

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. The port number cannot be the same

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

[plain]View PlainCopy
    1. LoadModule Jk_module modules/mod_jk.so
    2. Jkworkersfile conf/workers.properties
    3. Jklogfile Logs/mod_jk.log
    4. Jkloglevel Debug
    5. Jkmount/*.do LoadBalancer
    6. jkmount/*.jsp LoadBalancer

Add a conf/workers.properties file, adding content

[plain]View PlainCopy
    1. Worker.list=loadbalancer
    2. worker.worker2.port=8077 #ajp的监听端口
    3. worker.worker2.host=108.88.3.105
    4. Worker.worker2.type=ajp13
    5. Worker.worker2.lbfactor=1
    6. worker.worker3.port=9009
    7. worker.worker3.host=127.0.0.1
    8. Worker.worker3.type=ajp13
    9. Worker.worker3.lbfactor=1
    10. Worker.loadbalancer.type=lb
    11. Worker.loadbalancer.balance_workers=worker2,worker3 #这里在的worker2, Worker3 are consistent with aliases that need to be set on top tomcat
    12. 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

[plain]View PlainCopy
    1. Include conf/extra/httpd-vhosts.conf
    2. LoadModule Proxy_module modules/mod_proxy.so
    3. LoadModule Proxy_ajp_module modules/mod_proxy_ajp.so
    4. LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so
    5. LoadModule Proxy_connect_module modules/mod_proxy_connect.so
    6. LoadModule Proxy_ftp_module modules/mod_proxy_ftp.so
    7. LoadModule 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

[html]View PlainCopy
    1. Proxyrequests OFF
    2. <proxy Balancer://loadbalancer>
    3. Balancermember ajp://127.0.0.1:9009 loadfactor=1 route=worker3
    4. Balancermember ajp://108.88.3.105:8077 loadfactor=1 route=worker2
    5. </proxy>


conf/extra/httpd-vhosts.conf Add Configuration

[html]View PlainCopy
  1. <VirtualHost *:8081>
  2. ServerAdmin [email protected]
  3. ServerName localhost
  4. Serveralias localhost
  5. proxypass/balancer://loadbalancer/ stickysession=jsessionid nofailover= on
  6. proxypassreverse/balancer://loadbalancer/
  7. Errorlog "logs/loadbalancer-error.log"
  8. Customlog "logs/loadbalancer-access.log" Common
  9. </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

[html]View PlainCopy
    1. Proxyrequests OFF
    2. <proxy Balancer://loadbalancer>
    3. Balancermember http://127.0.0.1:8078 loadfactor=1 route=worker3
    4. Balancermember http://108.88.3.105:8079 loadfactor=1 route=worker2
    5. </proxy>


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

Apache and Tomcat load Cluster integration method configuration

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.