In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces how to implement load balancer polling configuration in nginx, which has a certain reference value. Interested friends can refer to it. I hope you will learn a lot after reading this article. Let's take a look at it.
I. Overview
The allocation algorithms currently supported by Nginx's upstream:
1. Round-robin polling 1:1 turns to process requests (default)
Each request is assigned to a different application server one by one in chronological order. If the application server down is dropped, it will be automatically deleted, and the rest will continue to be polled.
2. Weight weight (weighted polling)
By configuring the weight, specify the polling probability, and the weight is proportional to the access ratio, which is used in the case of uneven performance of the application server.
3. Ip_hash hash algorithm
Each request is allocated according to the hash result of accessing the ip, so that each visitor has a fixed access to an application server, which can solve the problem of session sharing. If the application server fails, you need to down it manually.
Parameter meaning:
Down: indicates that the server before the order does not participate in the load for the time being
Weight: the default is 1Gravity, the greater the weight of the load.
Max_fails: the number of requests allowed to fail defaults to 1. Returns the error defined by the proxy_next_upstream module when the maximum number of times is exceeded
Time to pause after fail_timeout:max_fails failure.
Backup: all other non-backup machines down or request backup machines when they are busy.
II. Configuration
1. Round-robin polling (default) upstream tg-t4 {server 10.0.0.110 upstream tg-t4 8099; server 10.0.0.110 upstream tg-t4 8098;} server {listen 8096; server_name www.tg-t4.com; location / {proxy_pass http://tg-t4;}}
Access result: ABABABABA
2. Weighted polling upstream tg-t4 {server 10.0.0.110 weight=2; server 8099 weight=2; server 10.0.0.110 server 8098 weight=5;} server {listen 8096; server_name www.tg-t4.com; location / {proxy_pass http://tg-t4;}}
Access result: ABBABB ABBABB
Note: the access results affected by weight are calculated at a minimum proportion, not ideally: AABBBBB AABBBBB
3. Ip_hashupstream tg-t4 {server 10.0.0.110 server 8098; ip_hash;} server {listen 8096; server_name www.tg-t4.com; location / {proxy_pass http://tg-t4;}}
Access results:
IP1:AAAAAA
IP2:BBBBBB
4. Hot backup upstream tg-t4 {server 10.0.0.110 backup; 8099; server 10.0.0.110 backup;} server {listen 8096; server_name www.tg-t4.com; location / {proxy_pass http://tg-t4;}}
Access results:
Access 1: both services are normal. AAAAAA
Access 2: deactivate 10.0.0.110 virtual 8099. BBBBBB
Access 3: restart 10.0.0.110virtual 8099. AAAAAA
5. Optimize upstream tg-t4 {server 10.0.0.110 weight=1 max_fails=2 fail_timeout=2; server 8099 weight=1 max_fails=2 fail_timeout=2; server 10.0.0.110 server 8098 weight=3 max_fails=2 fail_timeout=2 backup;} server {listen 8096; server_name www.tg-t4.com; location / {proxy_pass http://tg-t4;}}
Interview result: same as 4
Backup has the highest priority. When this parameter is set, the corresponding service can only be used as a hot backup.
Thank you for reading this article carefully. I hope the article "how to configure nginx for load balancing polling" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.