Nginx application of load balancing

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/qq_42191317/article/details/100527117

Load balancing Introduction

Load balancing is to spread the load across multiple operating units to perform that enhance the usability and responsiveness of service, give users a better experience.

Load balancing scheme:

  • Hardware Load Balancing: F5, etc.
  • Software load balancing:

1, DNS-based load balancing

Since the DNS server, you can configure the same name for a number of different addresses, the final query the name of the client will get one of the addresses when resolving the name, so this is by way of proxy random DNS name resolution service domain names and IP to achieve load balancing.

2, the reverse proxy load balancing (e.g., Apache + JK2 + Tomcat this combination)

This kind of way agents and general agents in different ways, the standard way customers use a proxy agent to access multiple external Web server, is known as a reverse proxy mode because this agent is way more customers use it to access internal Web server rather than access to external servers.

3, based on NAT (Network Address Translation) load balancing technology (such as Linux VirtualServer, referred to as LVS)

The technique of each external connection uniformly into a different internal server via a gateway address, the external computer in the network can communicate with each server's own address obtained by the conversion, so as to achieve load balancing purposes. Wherein the network address translation gateway located between an external address and internal address, can be achieved only when an external client accesses a gateway converts the external address can be forwarded to the address of one of the mapped internal address inside the computer may also be able to make access external networks.

Nginx load balancing configuration

Load balancing may be achieved through the upstream Nginx instruction In this instruction, the server load balancing can be arranged group. Currently there are four typical load balancing configurations, respectively, when the polling side, weights embodiment, ip_hash and the way the use of third-party modules.

  • Polling

Load balancing default setting mode, each request individually assigned to different back-end server for processing in order of time, if the server goes down, automatically remove

  • Weight way

The weight ratio of the right to use the specified weight polling access rate proportional to, for the case where the uneven performance backend server

  • ip_hash way

Each request by allocating IP hash result of the visit, so that each visitor can access a fixed back-end server, you can solve shared problems Session

  • Third party modules

Priority allocation module using a third party Fair, according to the response time of each server allocation request, the response time is short

When using third-party modules url_hash, in accordance with a hash value to allocate url

In the upstream group specified server, if the weight of each server weights are set to 1 (the default), the current load balancing is represented by the general polling mode. Further, Nginx itself does not contain a third-party implementation of the module, the module must download the corresponding upstream_fair hash during use or installation package.

   upstream server_group {
        server 59.110.171.154 weight=1;
        server 94.191.112.250 weight=2;
   }



    server {
        listen       80;
        server_name  localhost;

        #charset koi8-r;

        #
        #access_log  logs/host.access.log  main;

        location / {
             proxy_pass http://server_group;
        }

Modify the configuration file as described above, weights are set 1,2.

Access can be found corresponding to each forwarding the request to the server, the ratio is approximately 1: 2, if the weights are not configured, the default of 1: 1, i.e., polling.

In addition to weight parameters can also be equipped with the following parameters:

  • max_fails: the number of permitted request failed, the default is 1. When the maximum number of attempts, an error return instruction defined proxy_next_upstream
  • fail_timeout: After a max-fails failures, out of service time
  • backup: reserved backup machine, only bad all the other machines will provide services
  • down: Indicates the current server does not participate in load balancing

 

 

 

 

 

Guess you like

Origin blog.csdn.net/qq_42191317/article/details/100527117