nginx upstream load balancing

The core is upstream

1. Polling (default)
Each request is assigned to a different back-end server in chronological order and can be automatically culled if the back-end server is down.

2, weight
Specifies the

1
2
3
4
polling odds, weight, and access ratios, which are used for back-end server performance in une.d.
For example:
upstream bakend . . .
    server 192.168.159.10 weight=1

0;
server 192.168.159.11 weight=10;
}

3, ip_hash
Each request is assigned by the hash result of accessing the ip, so that

1
2
3
4
5
6
each guest has fixed access to a back-end server, which solves the problem of session.
For example:
upstream resinserver
    ip_hash;
    server 192.168.159.10:8080;
    server 19

2.168.159.11:8080;
}

4, fair (third party)
Requests are allocated by the res

1
2
3
4
5
ponse time of the back-end server, with a short response time as a priority.
upstream resinserver
    server1;
    server2;
    fai

r;
}

5, url_hash (third party)
The request is assigned by accessing the url's hash results, so that each url is directed to the same back-end server, which is more efficient when it is cached.
Example: Add a hash statement to upstream, server stateme

1
2
3
4
5
6
7
8
9
10
11
12
nt can not write weight and other parameters, hash_method is used hash algorithm

upstream resinserver
    server squid1:3128;
    server squid2:3128;
    hash $request suri;
    hash_method crc32;
}

Tips:
 
u

pstream resinserver s #定义

1
2
3
4
5
6
7
8
9
10
11
12
负载均衡设备的Ip及设备状态
    ip_hash;
    server 127.0.0.1:8000 down;
    server 127.0.0.1:8080 weight=2;
    server 127.0.0.1:6801;
    server 127.0.0.1:6802 backup;
}
Increase in servers that require load balancing
proxy_pass http://resinserver/;

The status of each device is set to:
1.down indicates that the server in front of the order

is temporarily not involved in the lo

1
2
ad
2.weight The default is 1.weight, the greater the wei

ght of the load.
3.max_fails: The default number of requests allowed to fail is 1. When the maximum number of times is exceeded, an error proxy_next_upstream the module is returned
4.fail_timeout: max_fails paused after two failures.
5.backup: All other non-backup machines down or busy, request backup machines. So this machine will have the least pressure.
nginx supports setting up multiple sets of load balancing at the same time for unused servers.
client_body_in_file_only set to On can speak the post over the data recorded in the file used to do debug
client_body_temp_path setting up the directory of the record file you can set up to 3 layers of directory
Location matches the URL. You can redirect or perform a new proxy load balancing

共有 0 条评论

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.