Apache Load Balancing

Source: Internet
Author: User
As the traffic volume increases and the response speed is required, it is necessary to configure the Server Load balancer. The company's system was initially designed with the Server Load balancer plan taken into account. Two www static servers were configured. Due to the tight schedule of the initial project and the low access volume, so at that time, only one instance was used, and the other was used in the internal network.

With the increasing traffic volume and the demand for response speedServer Load balancerConfiguration is very necessary. The company's system was initially designed with the Server Load balancer plan taken into account. Two www static servers were configured. Due to the tight schedule of the initial project and the low access volume, so at that time, only one instance was used, and the other instance was synchronized in the internal network to make full use of it. This is a simple test of Server Load balancer.

Apache mod_proxy_balaNcSeveral er configuration rules:

Using Apache as the front-end server of LoadBalance has three different deployment methods:

1) configure a polling balancing policy

Go to the conf directory of Apache and openHttpdAdd the. conf file to the end of the file:
ProxyPass/Balancer: // Proxy/# Note that the end is "/"
Balancer : // Proxy> 
BalancerMember http: // 192.168.6.37: 6888/ 
BalancerMember http: // 192.168.6.38: 6888/
 
Let's observe the above parameter"ProxyPass/Balancer: // Proxy/", where"ProxyPass"Is to configure the Virtual ServerCommand, "/" Indicates the URL prefix for sending Web requests, such as http: // myserver/or http: // myserver/aaa. All these URLs comply with the preceding filter conditions."Balancer: // Proxy/"indicates that Server Load balancer is to be configured, and proxy indicates the Server Load balancer name;BalancerMember and Its URLs indicate the backend server to be configured. The URL is the request URL of the backend server. The preceding configuration is used as an example to describe how Server Load balancer works: 
If Apache receives an http: // localhost/aaa requestProxyPassCondition (its URL prefix is "/"), the request will be distributed to a backgroundBalancerFor example, this request may be forwarded to http: // 192.168.6.37: 6888/aaa for processing. When the second URL request meets the conditions, the request may be distributed to anotherBalancerMember, for example, may be forwarded to http: // 192.168.6.38: 6888 /. The load balancing mechanism is realized after such a loop.

2) weight-based balancing policy configuration

ProxyPass/Balancer: // Proxy/# Note that the end is "/"
Balancer : // Proxy> 
BalancerMember http: /// 192.168.6.37: 6888/loaDfActor = 3 
BalancerMember http: // 192.168.6.38: 6888/loadfactor = 1
 
The "loadfactor" parameter indicates the weight from the backend server load to the request sent by Apache. The default value is 1. You can set this value to any value between 1 and 100. The preceding configuration is used as an example to describe how to implement Load Balancing Based on weights. Now, Apache receives four such requests: http: // myserver/aaa, if the request is separately loaded to the backend server, three consecutive requests are loadedBalancerThe Member is a server with http: // 192.168.6.37: 6888, and one such request is loadedBalancerMember is an http: // 192.168.6.38: 6888 backend server. Implements a balance policy that distributes weights continuously.

3) Configure the server Load balancer policy for responding to weight requests

ProxyPass/Balancer: // Proxy/lbmethod =TrAffic# Note: it ends "/".
Balancer : // Proxy> 
BalancerMember http: /// 192.168.6.37: 6888/loadfactor = 3 
BalancerMember http: // 192.168.6.38: 6888/loadfactor = 1 
  
The parameter "lbmethod = bytraffic" indicates the number of bytes of the backend server load requests and responses, and the number of bytes processed is expressed by the weight. "Loadfactor" indicates the backend server's weight for processing load requests and response bytes. The default value is 1. You can set this value to any value ranging from 1 to 100. According to the preceding configuration, the Server Load balancer is load balanced. If Apache receives an http: // myserver/aaa request, it forwards the request to the backend server. IfBalancerMember is http: // 192.168.6.37: 6888 when the backend server loads this request, the number of bytes it processes the request and response isBalancerMember is three times of the http: // 192.168.6.38: 6888 server (recall (2) Server Load balancer configuration, (2) the number of requests as the weight of Server Load balancer, (3) load Balancing is based on traffic weights, which is the biggest difference ).

You can configure the three methods based on your needs. According to the third configuration, I feel that this kind of load balancing is more comprehensive and reasonable. My configuration is very simple, as follows:
Configure the balancer first:

BalancerMember ajp: // 127.0.0.1: 8009/loadfactor = 1
BalancerMember http: // 192.168.10.6: 8083/loadfactor = 1

Http: // 192.168.10.6: 8083 is actually apache started on another port. For testing, it simply forwards all requestsMcAt.
Make the following changes to the last VirtualHost:

ServerName www.test.com
DocumentRoot/www
DirectoryInd ExIndex.html index. jsp

Options Indexes FollowSymLinks
AllowOverr IdE None
Order allow, deny
Allow from all


Options Indexes FollowSymLinks
AllowOverride None
Order allow, deny
Allow from all

ProxyPass/nxt/images /!
ProxyPass/nxt/js /!
ProxyPass/nxt/css /!
# ProxyPass/ajp: /127.0.0.1: 8009/
# ProxyPassReverse/ajp: // 127.0.0.1: 8009/
ProxyPass/balancer: // proxy/
ProxyPassReverse/balancer: // proxy/

Comment out the previous ajp forwarding and configure it to be processed by balancer.
By observing the access log, some requests are indeed sent to apache on port 8083, while some are directly forwarded to tom by ajp.Cat.

Related Article

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.