Installation and Implementation of apache Load Balancing

Source: Internet
Author: User

In fact, whether it is distributed, data cache, or load balancing, it is nothing more than improving the performance bottleneck of the website. When the website source code is not optimized, server Load balancer can be said to be the most direct means. In fact, if we leave this term alone, we hope that users can be diverted. That is to say, we will distribute the access pressure of all users to multiple servers, it can also be distributed to multiple tomcat servers. If multiple tomcat servers are installed on one server, the performance of Server Load balancer cannot be improved much, but the stability can be improved, that is, fault tolerance. When one of the main tomcat servers fails, other tomcat servers can also be added because Session sharing is implemented between tomcat servers. After the tomcat server is repaired, it will be restarted, all session data is automatically copied and then added to the cluster. In this way, services can be provided continuously. If you want to improve performance in essence, it must be distributed across multiple servers. tomcat can also be used. There are a lot of relevant information on the Internet, which can be easily found, but the quality is not high. I hope you can use this article, system summary.

In this example, two tomcat servers are run on the same server to achieve load balancing between the two tomcat servers. In fact, you can configure one tomcat for each server. In this case, you can use the installed version of tomcat, instead of the installation-free tomcat in the following sections, and the tomcat port configuration does not need to be modified 。

Tomcat server Load balancer needs to be added to the apache server. Before configuration, uninstall the installed tomcat, then check the apache version. This configuration uses the apache-tomcat-6.0.18 installation-free version. I personally tested it and concluded that the installed version of tomcat cannot start more than two on the same machine, it may be because the installed version of tomcat intruded into the system, and even on the server. if the configuration is modified in xml, the conflict still occurs. Therefore, I use the tomcat free installation version 。

Apache uses a apache_2.2.11-win32-x86-no_ssl.msi. If versions earlier than 2.2Apache Server Load balancer are configured differently, because 2.2.11 and 2.2.8 are integrated with load balancing tools such as jk2, therefore, the configuration is much simpler. I have no specific tests for other versions and need to learn more. These two software can be downloaded from the official website 。

Install Apache as a Windows Service Running on port 80. After successful installation, you can see the Apache2.2 service in the System Service list. After the service is started, enter http: // localhost in the browser for testing, if you can see an "It works! "The page indicates that Apache is working normally. Decompress tomcat to any directory and assign a different name. The name and path have no effect on the configuration. However, ensure that the port does not conflict, if a user installed with Oracle or IIS needs to modify or disable services related to interfaces, of course, jdk configuration is also required. This is not described too much 。

To achieve load balancing, first find conf/httpd in the Apache installation directory. conf file, remove the annotator (#) before the following text so that Apache can automatically load the proxy module at startup 。

Copy codeThe Code is 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 the <IfModule dir_module> node, and add index after DirectoryIndex index.html. jsp, this step is just to wait for the configuration of tomcat can see the kitten home page, you can not do. Continue to pull down the document to find Include conf/extra/httpd-vhosts.conf, remove the previous annotator 。

Open the conf/extra/httpd-vhosts.conf, configure the virtual site, and addCopy codeThe Code is as follows: <VirtualHost *: 80>
ServerAdmin administrator email
ServerName localhost
ServerAlias localhost
ProxyPass/balancer: // sy/stickysession = jsessionid nofailover = On
ProxyPassReverse/balancer: // sy/
ErrorLog "log/sy-error.log"
CustomLog "logs/sy-access.log" common
</VirtualHost>

Return to httpd. conf and addCopy codeThe Code is 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 indicates that Apache needs to use a reverse proxy. The IP address and port uniquely determine the tomcat node and the configured ajp accept port. loadfactor is the load factor, apache will forward requests to the backend tomcat node according to the load factor. The larger the load factor, the more requests the tomcat server will process. For example, if both tomcat servers are 1, apache forwards data in a ratio of. If it is 2 and 1, it forwards data in a ratio of. In this way, you can make the configuration more flexible. For example, you can increase the proportion of processing work for servers with good performance, if multiple servers are used, you only need to modify the IP address and port. The route parameter corresponds to the engine path (jvmRoute) in the subsequent tomcat Load Balancing 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.