How to install and implement Apache load Balancing _linux

Source: Internet
Author: User
Tags tomcat server

In fact, whether distributed, data caching, or load balancing, nothing more than to improve the performance of the site bottlenecks, in the site source code does not optimize the situation, load balance can be said to be the most direct means of the 。 In fact, put aside this noun, let go, that is, want users to be able to divert, that is, the access pressure of all users dispersed to more than one server, can also spread to multiple tomcat, if a server installed multiple tomcat, then even load balance, performance can not improve too much, But it can improve stability, that is, fault-tolerant 。 When one of the main Tomcat is dropped, other tomcat can also be made up, because Tomcat implements session sharing 。 When the tomcat server is repaired and restarted again, all session data is automatically copied and then added to the cluster 。 This will provide uninterrupted service 。 If you want to really improve performance in nature, you have to distribute to multiple servers 。 and Tomcat can do the same 。. More information on the Internet, can be easily found, but the quality is not high 。 I hope to pass this essay, the summary of the system 。 of this paper

Example is running two tomcat on the same server and doing the load balancing between two Tomcat 。 In fact, multiple servers can be configured with a tomcat, and in that case, you can use the installation version of Tomcat instead of the installation-free tomcat below, and the Tomcat port configuration will not be modified 。 The following will also refer to 。

Tomcat load Balancing requires the addition of Apache servers to implement 。 Uninstall the installed Tomcat before you make the configuration, and then check the Apache version 。 I am using the apache-tomcat-6.0.18 version of this configuration, I personally tested after the assumption that the installation version of Tomcat on the same machine will not be able to boot more than two, may be because the installation version of Tomcat intrusion into the system, This can cause conflicts even if the configuration is modified in the Server.xml 。 So I'm using tomcat-free version 。

Apache is using Apache_2.2.11-win32-x86-no_ssl.msi。. If the version is less than 2.2Apache load-balanced configuration, because this 2.2.11 and 2.2.8 version integrates JK2 and other load balancing tools, the configuration is a lot simpler 。 Other version I have no specific test, waiting to be refined 。 These two software can be downloaded to the official website 。

To install Apache as a Windows service running on port 80, the Apache2.2 service is visible in the system Services list after the installation is successful 。 After the service is started, enter http://localhost in the browser to test, if you can see an "It works!" The page on behalf of Apache has been working properly 。 Extract tomcat to any directory, assigning a different named 。 Name and path have no effect on configuration 。 However, to ensure that the port does not conflict, if the user with Oracle or IIS needs to modify or close the relevant interface services 。 Of course JDK configuration is also necessary, this is no longer too much narrative 。

To achieve load balancing, first, locate the conf/httpd.conf file under the Apache installation directory, and remove the annotation (#) before the following text so that Apache automatically loads the proxy module at startup 。

Copy Code code as follows:

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 <ifmodule dir_module> node, after DirectoryIndex index.html plus index.jsp, this step is only to be configured after Tomcat will be able to see the kitten home, can not do 。 Continue with the dropdown document to find include conf/extra/httpd-vhosts.conf, and remove the previous annotation character 。

Then open conf/extra/httpd-vhosts.conf, configure the virtual site, and at the bottom add
Copy Code code as follows:

<virtualhost *:80>
ServerAdmin Administrator Mailbox
ServerName localhost
Serveralias localhost
Proxypass/balancer://sy/stickysession=jsessionid Nofailover=on
proxypassreverse/balancer://sy/
ErrorLog "Logs/sy-error.log"
Customlog "Logs/sy-access.log" common
</VirtualHost>

Then go back to httpd.conf and add the bottom of the document
Copy Code code as follows:

Proxyrequests off
<proxy balancer://sy>
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 reverse proxy, IP address and port uniquely determine the Tomcat node and configure the AJP accept Port 。 Loadfactor is the load factor, Apache will forward the request by the ratio of load factor to the back end Tomcat node, the larger the load factor, the corresponding Tomcat server will handle more requests, such as two Tomcat are 1,apache on the 1:1 of the ratio forward, If it's 2 and 1, forward the 。 by 2:1. This can make the configuration more flexible, such as the performance of the server can increase the proportion of processing work, if multiple servers, only need to modify the IP address and port on the 。 Route parameter corresponds to the engine path in subsequent Tomcat load Balancing configuration (Jvmroute)

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.