Apache Load Balancing

Source: Internet
Author: User
Overview

Load Balancing is built on the existing network structure, it provides a cheap, effective, and transparent method to expand the bandwidth of network devices and servers, increase throughput, enhance network data processing capabilities, and improve network flexibility and availability.

Prerequisites

You have installed Apache and can run it. The system used in this article is: centos6.2, Apache: Apache 2.2.

Configure Apache as loadbalance

Open the following services in HTTP. conf:

  • Mod_proxy.so
  • Mod_proxy_ajp.so
  • Mod_proxy_balancer.so
  • Mod_proxy_connect.so
  • Mod_proxy_http.so
  • Mod_proxy_ftp.so

Using Apache as the load balance front-end server, there are three different deployment methods: Round Robin balancing policy configuration, weighted distribution balancing policy configuration, and weighted Request Response load balancing policy configuration.

1) configure a polling balancing policy

The so-called round-robin balancing policy focuses on two-word round-robin. Literally, it means to constantly access each server in order. This is a bit like Loop Playing in the song. The priority of this policy comes from the order you configured. The following describes the detailed configuration of this policy.

Go to the conf. d directory of Apache, and create a new file with ". conf" as the file Suffix: Michael. conf. Add the following at the end of the file:

Proxypass/balancer: // proxy/# Note: it ends "/".

<Proxy balancer: // proxy>
Balancermember http: /// 10.0.11.106: 8088/
Balancermember http: /// 10.0.11.106: 8888/
</Proxy>

Observe the preceding parameter "proxypass/balancer: // proxy/". "proxypass" indicates the command to configure the virtual server. "/" indicates the URL prefix of the Web request, for example: http: // myserver/or http: // myserver/AAA, these URLs will comply with the above filter conditions; "balancer: // proxy/" indicates that you want to configure Server Load balancer, "proxy" indicates the name of the Server Load balancer instance. balancermember and its url indicate the backend server to be configured. The URL is the URL of the backend server request. The preceding configuration is used as an example to describe how Server Load balancer works:

If Apache receives an http: // localhost/AAA request, because the request meets the proxypass condition (its URL prefix is "/"), the request will be distributed to a balancermember in the background, for example, the request may be forwarded to http: // 10.0.11.106: 8088/AAA for processing. When the Second Matching URL request comes over, the request may be distributed to another balancermember. For example, the request may be forwarded to http: // 10.0.11.106: 8088 /. The load balancing mechanism is realized after such a loop.

2) weight-based balancing policy configuration

To understand this strategy, you only need to understand the weight in 2 words. The following is a metaphor:
For example, if you give it 100 points and your boss gives it 60 points, the average is (100 + 60)/2 = 80 points. but because the boss said that the weight is heavier than you, if the boss's weight is 2 and you are 1, then the average value is the weighted average, and the result is (100*1 + 60*2) /(1 + 2) = 73.3 points, apparently tilted to your boss. If the boss's weight is 1 and your weight is 3, the result is (100*3 + 60*1)/(1 + 3) = 90. This is the calculation of the mean based on different weights, so it is also called the weighted average.

After understanding the weight, let's talk about what this policy actually means. In fact, this policy adds weight based on the first policy. When the client accesses your application, the access weight is high. This is a bit similar to the priority in the thread, the CPU with a higher priority will allocate more time for it to execute, which is also the same. Apache will allow more accesses with higher weights. Detailed configuration is as follows:

Proxypass/balancer: // proxy/# note that it ends "/"
<Proxy balancer: // proxy>
Balancermember http: // 10.0.11.106: 8088/loadfactor = 3
Balancermember http: // 10.0.11.106: 8888/loadfactor = 1
</Proxy>

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, this request is separately loaded to the backend server, and three consecutive such requests are loaded to the server where balancermember is http: // 10.0.11.106: 8088, one such request was loaded with the backend server balancermember http: // 10.0.11.106: 8088. Implements a balance policy that distributes weights continuously.

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

Proxypass/balancer: // proxy/# Note: it ends "/".

<Proxy balancer: // proxy>


Balancermember http: // 10.0.11.106: 8088/loadfactor = 3

Balancermember http: // 10.0.11.106: 8888/loadfactor = 1

Proxyset lbmethod = bytraffic

</Proxy>

The proxyset command is similar to map and sets the value of a parameter. lbmethod is used to select the load balancing mode of the balancer. It can be byrequests for weighted request count, or bytraffic for weighted traffic Byte Count balancing. The default value is the number of requests. 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 above configuration, the Server Load balancer is balanced. If Apache receives an http: // myserver/AAA request and forwards the request to the backend server, if balancermember is http: // 10.0.11.106: 8088 if the backend server loads this request, the number of bytes for processing the request and response is
Http: // 10.0.11.106: 3 times the server 8888.

Test and prepare the above configurations. 1. Two Web servers are required. In this article, Tomcat is selected as the test server.
2. Create a new folder test in the webapp directory of Tomcat, create test. jsp, and write
<%System.out.println("===========================");%>

Perform the first test: Access http: // ip: 80/test. jsp
Test results: http: // 10.0.11.106: 8088 and http: // 10.0.11.106: 8888 are polling and printed on the background.
Other tests are not performed ......
For more information about Server Load balancer configurations, see: http://httpd.apache.org/docs/2.2/mod/mod_proxy.html#proxypass

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.