Home >Backend Development >PHP Tutorial >nginx cluster client allocation strategy

nginx cluster client allocation strategy

WBOY
WBOYOriginal
2016-08-08 09:19:52970browse

1. Polling (default)
Each request is assigned to a different backend server one by one in chronological order. If the backend server goes down, it can be automatically eliminated.

upstream backserver {
server 192.168.0.14;
server 192.168.0.15;
}
2. Specify the weight
Specify the polling probability, the weight is proportional to the access ratio, and is used when the backend server performance is uneven.

upstream backserver {
server 192.168.0.14 weight=10;
server 192.168.0.15 weight=10;
}
3. IP binding ip_hash
Each request is allocated according to the hash result of the access ip, so that each visitor has fixed access A backend server can solve session problems.

upstream backserver {
ip_hash;
server 192.168.0.14:88;
server 192.168.0.15:80;
}
4. fair (third party)
Allocate requests according to the response time of the backend server, the response time is short Priority allocation.

upstream backserver {
server server1;
server server2;
fair;
}
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 end server is cached.

upstream backserver {
server squid1:3128;
server squid2:3128;
hash $request_uri;
hash_method crc32;
}
In the server that needs to use load balancing, add

proxy_pass http://backserver/;
upstream backserver{
ip_hash;
server 127.0.0.1:9090 down; (down means that the previous server will not participate in the load temporarily)
server 127.0.0.1:8080 weight=2; (weight defaults to 1. The greater the weight, the weight of the load The bigger it is)
server 127.0.0.1:6060;
server 127.0.0.1:7070 backup; (When all other non-backup machines are down or busy, the backup machine is requested)
}
max_fails: The number of allowed request failures is by default 1. When the maximum number of times is exceeded, the error defined by the proxy_next_upstream module is returned
fail_timeout: the pause time after max_fails failures

The above introduces the nginx cluster client allocation strategy, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
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