Now, basically all enterprises use the network for daily work. In the network operation of an enterprise, the transmission and data sending and receiving processes are not evenly distributed. Then, using Server Load balancer technology can achieve a balanced concept. So how to implement it? If it is not realistic to purchase large load balancing equipment, software control is a commonly used method. Now we will introduce the simple configuration process of Apache Server Load balancer.
With the increasing traffic volume and the demand for response speed, Server Load balancer settings are very necessary. The company's system has already taken into account the Server Load balancer plan in its initial design, two static www servers were configured. Because the initial project time was tight and the access volume was not high, only one server was used and the other server was synchronized in the internal network, this is a simple test of Server Load balancer 。
Using Apache as the front-end server of loadbalance has three different deployment methods:load balancing
1) configure a polling balancing policy
Go to the conf directory of Apache, open the httpd. conf file, aws load balancer and add the following content to the end of the file:elastic load balancer
Proxypass/balancer: // proxy/# note that it ends "/"
<Proxybalancer: // proxy>
Balancermemberhttp: // 192.168.6.37: 6888/
Balancermemberhttp: // 192.168.6.38: 6888/
</Proxy>
Let's observe the above parameter "proxypass/balancer: // proxy/", where "proxypass" is the command to configure the virtual server, "/" represents the URL prefix for sending Web requests, 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, the proxy represents the Server Load balancer name. The balancermember and its url indicate the backend server to be configured. The URL is the URL of the backend server request. The above configuration is used as an example to describe how to implement Server Load balancer:
If Apache receives an http: // localhost/AAA request, because the request meets the proxypass condition (its URL prefix is "/"), the request is distributed to a balancermember in the background, for example, the request may be forwarded to http: // 192.168.6.37: 6888/AAA for processing. When the second URL request that meets the conditions is sent, this request may be distributed to another balancermember. For example, the request may be forwarded to http: // 192.168.6.38: 6888/. The load balancing mechanism is implemented by repeating this loop 。
2) weight-based balancing policy configuration
Proxypass/balancer: // proxy/# note that it ends "/"
<Proxybalancer: // proxy>
Balancermemberhttp: // 192.168.6.37: 6888/loadfactor = 3
Balancermemberhttp: // 192.168.6.38: 6888/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 achieve Load Balancing by weight. Now, Apache receives http: // For myserver/aaa4 requests, the requests are loaded to the backend server, and three consecutive requests are loaded to balancermember as http: // 192.168.6.37: 6888 of the servers, once such a request is loaded with the balancermember http: // 192.168.6.38: 6888 backend server. A balanced policy is implemented based on the continuous distribution of weights 。
3) Configure the server Load balancer policy for responding to weight requests
Proxypass/balancer: // proxy/lbmethod = bytraffic # note that it ends "/" f5 load balancer
<Proxybalancer: // proxy>
Balancermemberhttp: // 192.168.6.37: 6888/loadfactor = 3
Balancermemberhttp: // 192.168.6.38: 6888/loadfactor = 1
</Proxy>
The parameter "lbmethod = bytraffic" indicates the number of bytes for the backend server load requests and responses, the number of bytes processed is expressed by the weight. "loadfactor" indicates the weight of the backend server 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. Load Balancing is performed based on the above configuration. Suppose Apache receives the http: // myserver/AAA request, forward the request to the backend server. If the balancermember is http: // 192.168.6.37: 6888 and the backend server loads the request, the number of bytes for processing the request and response is http: // 192.168.6.38: 3 times of the 6888 server (recall (2) Server Load balancer configuration. (2) Server Load balancer is weighted by the number of requests. (3) Server Load balancer is weighted by traffic, this is the biggest difference )。network load balancer
You can configure the Server Load balancer according to different requirements. I have configured the Server Load balancer in the third way, which is more comprehensive and reasonable. My configuration is very simple, as shown below:
Configure the balancer first:azure load balancer
<Proxybalancer://proxy>
BalancerMemberajp://127.0.0.1:8009/loadfactor=1
BalancerMemberhttp://192.168.10.6:8083/loadfactor=1
</Proxy>
Http: // 192.168.10.6: 8083 is actually Apache started on another port. For testing, it simply forwards all requests to Tomcat 。
Make the following changes to the last virtualhost:aws elastic load balancer
<VirtualHost*:80>
ServerNamewww.test.com
DocumentRoot/www
DirectoryIndexindex.htmlindex.jsp
<Directory"/www">
OptionsIndexesFollowSymLinks
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>
<Directory"/control">
OptionsIndexesFollowSymLinks
AllowOverrideNone
Orderallow,deny
Allowfromall
</Directory>
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/
</VirtualHost>
Comment out the previous AJP forwarding and configure it to be processed by balancer 。
By observing accesslog, some requests are indeed sent to Apache on port 8083, what is load balancing while some are directly forwarded to Tomcat by AJP. For more Server Load balancer parameter detection, wait until it is empty 。