In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
What this article shares with you is about the scheduling algorithms in nginx. The editor thinks it is very practical, so I share it with you to learn. I hope you can get something after reading this article.
Upstream supports four load balancing scheduling algorithms:
A) polling (default): each request is assigned to different back-end servers one by one in chronological order
B) ip_hash: each request is allocated according to the hash result of accessing the IP, and the same IP client accesses a back-end server on a fixed basis
C) url_hash: allocate requests according to the hash result of accessing url, so that each url is directed to the same back-end server
D) fair: this is a more intelligent load balancing algorithm than the above two. This algorithm can intelligently balance the load according to the page size and loading time, that is, the request can be allocated according to the response time of the back-end server, and the priority allocation of short response time. Nginx itself does not support fair, and if you need to use this scheduling algorithm, you must download the upstream_fair module of Nginx.
1) default rotation training
[root@proxy ~] # vim / usr/local/nginx/conf/nginx.conf...upstream roundrobin {/ / define scheduling algorithm server 192.168.31.33 weight=1; / / server1 server 192.168.31.237 weight=1; / / server2}... location / {proxy_set_header X-Real-IP $remote_addr; / / returns the real IP proxy_pass http://roundrobin; / / Agent points to scheduling roundrobin} [root@proxy ~] # killall-9 nginx [root@proxy ~] # nginx-t nginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@proxy ~] # nginx
Then access authentication ~
The client can normally take turns accessing the two WEB servers; view the logs of the two WEB servers.
2) based on hash
[root@proxy ~] # vim / usr/local/nginx/conf/nginx.conf...upstream roundrobin {ip_hash; / / Hash server 192.168.31.33 weight=1; server 192.168.31.237 weight=1 is supported by adding parameters } [root@proxy ~] # killall-9 nginx [root@proxy ~] # nginx-t nginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@proxy ~] # nginx
Then access authentication ~
Only one WEB server can be accessed; view the logs of both WEB servers.
3) set the status of the backend cloud load balancer server:
Down, which means that the current server does not participate in load balancing for the time being. Backup, reserved backup machine. The backup machine is requested only when all other non-backup machines are malfunctioning or busy, so this machine is the least stressful.
Note: backup and ip_hash cannot be configured at the same time. Because ip_hash can only access the same server, while backup has only all participants
The backup machine is requested only when the load balancer server fails. When all load balancing servers fail, ip_hash 's will no longer be able to request.
[root@proxy] # vim / usr/local/nginx/conf/nginx.conf upstream roundrobin {server 192.168.31.33 weight=1; server 192.168.31.35 weight=1; server 192.168.31.237 backup / / set backup machine} [root@proxy ~] # killall-9 nginx [root@proxy ~] # nginx-t nginx: the configuration file / usr/local/nginx/conf/nginx.conf syntax is oknginx: configuration file / usr/local/nginx/conf/nginx.conf test is successful [root@proxy ~] # nginx
If you shut down two WEB servers, you can access the backup machine. Note: only when all the servers participating in load balancing fail, will the backup machine be requested.
These are the scheduling algorithms in nginx, and the editor believes that there are some knowledge points that we may see or use in our daily work. I hope you can learn more from this article. For more details, please follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.