Apache + Tomcat Cluster configuration detailed (1)

Source: Internet
Author: User

First, software preparation

Apache 2.2:http://httpd.apache.org/download.cgi, download MSI installer, select No SSL version

Tomcat 6.0:http://tomcat.apache.org/download-60.cgi, download tomcat 6.0.18 zip file

Note: Because the Apache and Tomcat project-related modules are in continuous development and optimization, the author does not guarantee that the configuration method in this article applies to all Apache and Tomcat versions.

Second, software Installation

Install Apache as a Windows service running on port 80 and you will see the Apache2.2 service in the list of system services after successful installation. For machines that have IIS installed, you must first stop the IIS Admin service before starting the Apache service, or it will not start because of a port conflict. After the service is started, enter http://localhost in the browser to test if you can see an "It works!" The page will indicate that Apache is working properly.

Unzip the tomcat zip file to two folders, T1 and T2 respectively, with the following T1 and T2 representing two tomcat servers. Configure the Java_home and CLASSPATH system environment variables, start T1 and T2 respectively, make sure Tomcat is available, and then turn off Tomcat.

This article only explains the configuration process, both Apache and Tomcat work on the same machine. There is no limit to the actual deployment, and Apache and individual tomcat can be deployed on separate servers.

Three, Apache configuration

Apache 2.2 is a mod_jk feature that, compared to the 1.3 version, does not require cumbersome worker.properties configuration and greatly simplifies the configuration process.

First, locate the conf/httpd.conf file in the Apache installation directory and open it as a text editor.

Remove the comment (#) before the following text to allow Apache to automatically load the proxy module at startup.

LoadModule Proxy_module modules/mod_proxy.so
LoadModule Proxy_ajp_module modules/mod_proxy_ajp.so
LoadModule Proxy_balancer_module modules/mod_proxy_balancer.so
LoadModule Proxy_connect_module modules/mod_proxy_connect.so
LoadModule Proxy_ftp_module modules/mod_proxy_ftp.so
LoadModule Proxy_http_module modules/mod_proxy_http.so

Pull down the document to find the <ifmodule dir_module> node, after DirectoryIndex index.html add index.jsp, this step is only to be configured after Tomcat can see the kitten home, you can not do.

Continue to the drop-down document to find the include conf/extra/httpd-vhosts.conf, removing the previous comment.

Open the conf/extra/httpd-vhosts.conf with a text editor, configure the virtual site, and at the bottom, add

<virtualhost *:80>
ServerAdmin Admin Mailbox
ServerName Domain name (no IP address available instead)
Serveralias localhost
Proxypass/balancer://cluster/stickysession=jsessionid Nofailover=on
proxypassreverse/balancer://cluster/
Errorlog "Logs/lbtest-error.log"
Customlog "Logs/lbtest-access.log" common
</VirtualHost>

Here balancer://is to tell Apache need to load balance agent, the following cluster is the cluster name, can be arbitrary, two log engine errorlog responsible for logging errors, Customlog is responsible for recording all HTTP access and return status, The log name can be taken by itself, the author takes it as Lbtest. Httpd-vhosts.conf configuration, back to httpd.conf, at the bottom of the document to add

Proxyrequests OFF
<proxy balancer://cluster>
Balancermember ajp://127.0.0.1:8009 loadfactor=1 route=jvm1
Balancermember ajp://127.0.0.1:9009 loadfactor=1 route=jvm2
</proxy>

Proxyrequests Off is to tell Apache to use a reverse proxy (using Apache for load balancing must use reverse proxy, for more load balancing and reverse proxy details can refer to the author of another blog http://zyycaesar.iteye.com/ admin/blogs/293839), <proxy balancer://cluster> is used to configure all nodes working in the Tomcat cluster, where the "cluster" must be consistent with the cluster name above. Apache communicates with Tomcat via the AJP protocol, and the IP address and port uniquely identify the Tomcat node and the configured AJP accept port. Loadfactor is a load factor, Apache forwards requests to the Tomcat node in proportion to the load factor, and the larger the load factor, the more requests will be processed by the corresponding Tomcat server, such as two Tomcat is 1,apache on a 1:1 scale. If it is 2 and 1, it is forwarded at a 2:1 ratio. The route parameter corresponds to the engine path (Jvmroute) in the subsequent Tomcat configuration.

To restart the Apache service, if accessing http://localhost/at this time will return a 503 error, open the error log just configured logs/ Lbtest-error.log, you can see that the reason for the error is because the background server is not responding because Tomcat is not configured and started at this time.

Apache + Tomcat Cluster configuration detailed (2) | Load Balancing Technology

Apache + Tomcat Cluster configuration detailed (1)

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.