Apache and Tomcat Load balancer (reprint)

Source: Internet
Author: User

Apache HTTP Server and Tomcat three ways to connect Jk,http_proxy,ajp_proxy. Let's introduce each of the following (the examples presented here are based on the previously established Tomcat cluster, all native, with ports 18080 and 28080, respectively):

JK:
JK is the most common way, JK itself has two versions are 1 and 2, the current 1 the latest version is 1.2.37, and version 2 has been obsolete, and no longer have a new version of the launch, so it is recommended that you adopt version 1.
JK is communicating with the Tomcat server through the AJP protocol, and the tomcat default AJP Connector port is 8009 (the native modification is configured to 18009 and 28009). JK itself provides a monitoring and management page Jkstatus, through which jkstatus can monitor the current working status of JK and set up a connection to Tomcat.
Configuring JK
1. Download Mod_jk,tomcat website to download
http://tomcat.apache.org/download-connectors.cgi, download the corresponding version
2. Modify Httpd.conf

  1  # (httpd.conf)   2  # load mod_jk module   loadmodule jk_module modules/mod_jk.so   4   #   6  # Configure mod_jk   7  #   8  jkworkersfile conf/ Workers.properties   9  jkmountfile conf/ Uriworkermap.properties  10  jklogfile Logs/mod_jk.log  11  Jkloglevel warn 

3. Add the configuration file Workers.properties in the Conf directory, consistent with the configuration jkworkersfile above  

 ## workers.properties## list the workers by name# dlog4j The name is random worker.list  =dlog4j, 1#----------- -------------worker.s1.port  =18009worker.s1.host  =localhostworker.s1.type  =#------------------------worker.s2.port  =28009worker.s2.host  =localhostworker.s2.type  =ajp13worker. Dlog4j.type  =lbworker.retries  =3worker . Dlog4j.balance_workers  =s1, S2worker. Dlog4j.sticky_session  =1worker.status.type  =status 

4. Add the configuration file Uriworkermap.properties in the Conf directory, consistent with the configuration jkmountfile above

/*=dlog4j/jkstatus=status!/*.gif=dlog4j!/*.jpg=dlog4j!/*.png=dlog4j!/* . css=dlog4j!/*.js=dlog4j!/*.htm=dlog4j!/*.html=dlog4j

The above mapping means that all requests are handled by the dlog4j worker, but with a few exceptions, the/jkstatus request is handled by the status worker. In addition, the exclamation point in front of each row of data in the configuration indicates that the next URI is not processed by JK, that is, Apache directly handles all images, CSS files, JS files, and static HTML text files.
5. Launch Apache, two tomcat
6. Testing
Visit Http://192.168.1.101:8080/jkstatus first to see the status of Jkstatus
Re-visit http://192.168.1.101:8080/ClusterValidate/index.jsp

Http_proxy
This is the use of Apache's own mod_proxy module to connect Tomcat using proxy technology. Make sure you are using the 2.2.x version of the Apache server before you configure it. Because the 2.2.x version of this module has been rewritten, greatly enhanced its functionality and stability.

Http_proxy mode is a proxy based on the HTTP protocol, so it requires Tomcat to provide HTTP services, which means that Tomcat's HTTP Connector must be enabled.
Configure Http_proxy
1. Resume loading Http_proxy related modules
In the httpd.conf file, remove the comments from the following lines
LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_module modules/mod_proxy_ajp.so
LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule Proxy_http_module modules/mod_proxy_http.so
LoadModule Proxy_http_module modules/mod_status.so

2. Add proxy agent Proxypass in httpd.conf

Add the following configuration:

proxypass/images! Proxypass/css! Proxypass/js! Proxypass/balancer-manager  ! Proxypass/balancer://mycluster/<proxy balancer://mycluster/>balancermember http://localhost:18080  /balancermember http://localhost:28080/</proxy><location/balancer-manager> SetHandler Balancer-manager           Order Deny, allow #Deny from all to, from           localhost ip6-localhost</ Location>

3. Start Apache,tomcat
4. Testing
Http://192.168.1.101:8080/balancer-manager View equalization Status
http://192.168.1.101:8080/ClusterValidate/index.jsp Test Load Balancing

Ajp_proxy
Basically consistent with http_proxy, just in the Proxypass address, the address of the HTTP is converted to AJP address, and Tomcat strong AJP port number. As follows:

proxypass/images! Proxypass/css! Proxypass/js! Proxypass/balancer-manager  ! Proxypass/balancer://mycluster/<proxy balancer://mycluster/>balancermember ajp://localhost:18009/ Balancermember ajp://localhost:28009/</proxy><location/balancer-manager> SetHandler Balancer-manager           Order Deny, allow #Deny from all to, from           localhost ip6-localhost</ Location>

The above three kinds of load scheme are OK, but the official suggestion still is JK mode is good, high efficiency, stable.

Apache and Tomcat Load balancer (reprint)

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.