loadbalance apache2

With the continuous increase of traffic and the requirement for response speed, it is very necessary to perform load balancing settings. The company's system has already taken into account the planning of load balancing when it was originally designed. Two www static servers were configured. Since the initial project time was tight and the number of visits was not high, only one was used at that time, and the other was in In the intranet, only synchronization is performed, and it is used for effectiveness. This time is a simple test of load balancing.        

Let's first introduce several configuration rules of apache mod_proxy_balancer:  

There are three different deployment methods for using Apache as the LoadBalance front-end, which are: 

1) Configuration of round-robin balancing strategy      

Go to Apache's conf directory, open the httpd.conf file, and add at the end of the file:    

 

ProxyPass   /  balancer ://proxy/         

 

#Note that it ends with "/"    

<Proxy  balancer ://proxy>           

Balancer Member http://192.168.6.37:6888/           

Balancer Member http://192.168.6.38:6888/    

</Proxy>          

Let's observe the above parameters "ProxyPass / balancer ://proxy/", where "ProxyPass" is the command to configure the virtual server, and "/" represents the URL prefix for sending web requests, such as: http://myserver/ or http ://myserver/aaa, these URLs will meet the above filter conditions; "balancer ://proxy/" means to configure load balancing, proxy represents the name of the load balancing; Balancer Member and the URL behind it represent the background server to be configured, The URL is the URL of the background server request.

 

Taking the above configuration as an example, the principle of implementing load balancing is as follows:          

Assuming that Apache receives the http://localhost/aaa request, since the request meets the ProxyPass condition (its URL prefix is ​​"/"), the request will be distributed to a Balancer Member in the background. For example, the request may be forwarded to http ://192.168.6.37:6888/aaa for processing. When the second URL that meets the conditions is requested, the request may be distributed to another Balancer Member, for example, it may be forwarded to http://192.168.6.38:6888/. This cycle is repeated, and the load balancing mechanism is realized. 

 

2) Configuration of balanced strategy by weight distribution      

ProxyPass / balancer ://proxy/ #Note that it ends with "/"    

 

<Proxy  balancer ://proxy>             

Balancer Member http://192.168.6.37:6888/  loadfactor=3            

Balancer Member http://192.168.6.38:6888/  loadfactor=1    

</Proxy> The parameter "loadfactor" represents the weight of the background server load to the request sent by Apache. The value defaults to 1, and the value can be set to any value between 1 and 100. Take the above configuration as an example to introduce how to implement load balancing based on weight distribution. Now suppose that Apache receives such requests as http://myserver/aaa 4 times, and the requests are loaded to the background server respectively, and there are 3 consecutive requests. In this way, the request is loaded to the server whose Balancer Member is http://192.168.6.37:6888, and one such request is loaded to the background server whose Balancer Member is http://192.168.6.38:6888. The balanced strategy of continuous distribution according to the weight is realized.  

 

3) Weight request response load balancing strategy configuration      

ProxyPass / balancer ://proxy/ lbmethod=bytraffic #Note that it ends with "/"    

<Proxy  balancer ://proxy>              

Balancer Member http://192.168.6.37:6888/  loadfactor=3             

Balancer Member http://192.168.6.38:6888/  loadfactor=1    

</Proxy>   

        

The parameter "lbmethod=bytraffic" indicates the number of bytes of the load request and response of the background server, and the number of bytes processed is expressed in the form of weight. "loadfactor" represents the weight of the background server processing load request and response bytes. This value defaults to 1, and can be set to any value from 1 to 100. According to the above configuration, the load is balanced in this way. Suppose Apache receives the http://myserver/aaa request and forwards the request to the background server. If the Balancer Member is http://192.168.6.37:6888, the background server loads the request. Then the number of bytes it processes requests and responses is 3 times that of the server whose Balancer Member is http://192.168.6.38:6888 (recall (2) balanced configuration, (2) the number of requests is used as weight load balancing, (3 ) is load balanced with traffic as the weight, which is the biggest difference). See if you understand, according to different needs, you can configure it in these three ways. According to the third configuration, I feel that this load balancing is more comprehensive and reasonable. My configuration is very simple, as follows: First configure the equalizer:  

 

<Proxy balancer://proxy>         

BalancerMember ajp: //127.0.0.1: 8009 / loadfactor = 1        

BalancerMember http://192.168.10.6:8083/  loadfactor=1 

</Proxy>  

Among them, http://192.168.10.6:8083 is actually apache started by another port. For testing, it simply forwards all requests directly to tomcat. Make the following modifications to the last VirtualHost: 

 

Comment out the previous ajp forwarding and configure it to pass the balancer

<VirtualHost *:80>          
       ServerName www.test.com         
       DocumentRoot /www          
       DirectoryIndex index.html index.jsp         
       <Directory "/www">              
           Options Indexes FollowSymLinks             
           AllowOverride None             
           Order allow,deny             
           Allow from all         
       </Directory>
     <Directory "/control">              
           Options Indexes FollowSymLinks             
           AllowOverride None             
           Order allow,deny             
           Allow from all         
     </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>

 deal with. By observing the access log, it is true that some requests are sent to apache on port 8083, and some are directly forwarded to tomcat by ajp. 

 

<VirtualHost *:80>
        ProxyRequests off
        
        ServerName domain.com

        <Proxy balancer://mycluster>
                # WebHead1
                BalancerMember http://10.176.42.144:80
                # WebHead2
                BalancerMember http://10.176.42.148:80

                # Security "technically we aren't blocking
                # anyone but this the place to make those
                # chages
                Order Deny,Allow
                Deny from none
                Allow from all

                # Load Balancer Settings
                # We will be configuring a simple Round
                # Robin style load balancer.  This means
                # that all webheads take an equal share of
                # of the load.
                ProxySet lbmethod=byrequests

        </Proxy>

        # balancer-manager
        # This tool is built into the mod_proxy_balancer
        # module and will allow you to do some simple
        # modifications to the balanced group via a gui
        # web interface.
        <Location /balancer-manager>
                SetHandler balancer-manager

                # I recommend locking this one down to your
                # your office
                Order deny,allow
                Allow from all
        </Location>

        # Point of Balance
        # This setting will allow to explicitly name the
        # the location in the site that we want to be
        # balanced, in this example we will balance "/"
        # or everything in the site.
        ProxyPass /balancer-manager !
        ProxyPass / balancer://mycluster/

</VirtualHost>

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326693836&siteId=291194637