Home > Backend Development > PHP Tutorial > NGinx load balancing strategy

NGinx load balancing strategy

WBOY
Release: 2016-07-29 09:05:49
Original
1116 people have browsed it

Original text reproduced from: http://tomyz0223.iteye.com/blog/1046992

nginx’s upstream currently supports 5 methods of allocation
1. Polling (default)
Each request is in chronological order Allocate to different backend servers one by one. If the backend server goes down, it can be automatically eliminated.

upstream backserver {
server 192.168.0.14;
server 192.168.0.15;
}
Copy after login
2. Weight
specifies the polling probability. The weight is proportional to the access ratio and is used when the back-end server performance is uneven.
upstream backserver {
server 192.168.0.14 weight=10;
server 192.168.0.15 weight=10;
}
Copy after login
3. ip_hash
Each request is allocated according to the hash result of the accessed IP, so that each visitor has fixed access to a back-end server, which can solve the session problem.
upstream backserver {
ip_hash;
server 192.168.0.14:88;
server 192.168.0.15:80;
}
Copy after login
4. fair (third party)
allocates requests according to the response time of the backend server, and those with short response times are prioritized.
upstream backserver {
server server1;
server server2;
fair;
}
Copy after login
5. url_hash (third party)
Distribute requests according to the hash result of the accessed URL, so that each URL is directed to the same backend server. It is more effective when the backend server is cached.
upstream backserver {
server squid1:3128;
server squid2:3128;
hash $request_uri;
hash_method crc32;
}
Copy after login
Increase
proxy_pass http://backserver/ ;
upstream backserver{
ip_hash;
server 127.0.0.1:9090 down; (down 表示单前的server暂时不参与负载)
server 127.0.0.1:8080 weight=2; (weight 默认为1.weight越大,负载的权重就越大)
server 127.0.0.1:6060;
server 127.0.0.1:7070 backup; (其它所有的非backup机器down或者忙的时候,请求backup机器)
}
Copy after login
max_fails in servers that need to use load balancing: The number of allowed request failures is 1 by default. When the maximum number of times is exceeded, the error defined by the proxy_next_upstream module is returned.

The above introduces the NGinx load balancing strategy, including various aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template