|
|
Posted on 6/14/2020 11:50:26 AM
|
|
|
|

I have been using Alibaba Cloud's load balancing for more than 6 years, and I have been using nginx for more than 6 years.
Load balancing builds on existing network structures and provides a cheap, effective, and transparent way to scale network equipment and servers bandwidth, increase throughput, enhance network data processing capabilities, and improve network flexibility and availability. Load balance means that it is distributed to multiple operating units, such as web servers, FTP servers, enterprise critical application servers, and other mission-critical servers, so as to jointly complete work tasks. Simply put, it distributes multiple requests to different servers on the backend to reduce the pressure on each server and achieve high availability, even if one server hangs up, it has no impact.
First of all
I installed node.js natively and installed http-server to emulate two web containers. (Use IIS, or implement the HTTP protocol with your own code)
After installing node.js, run the following command:
Simulate two backend sites
I created two new folders, site1 and site2, under the E:\wwwroot directory, each with a index.html file in it.
The contents are: index 1 by:itsvse.com and index 2 by:itsvse.com
Then, listen to the two HTTP ports with the following command to open the two sites.
Try accessing both stations separately:The hyperlink login is visible. The hyperlink login is visible.The renderings are as follows:
NGINX load balancing configuration
Download the Windows version of nginx at the following address:The hyperlink login is visible.
Once downloaded, extract it to the E:\wwwroot\nginx-1.18.0 directory. Modify the E:\wwwroot\nginx-1.18.0\conf\nginx.conf file as follows:
Start the nginx program with the following command:
nginx -s stop fast shutdown nginx -s quit graceful shutdown nginx -s reload changing configuration, starting new worker processes with a new configuration, graceful shutdown of old worker processes nginx -s reopen re-opening log files Accessing the nginx load balancing site via a browser:The hyperlink login is visible.
We refresh and revisit many times, and find that the content returned is different each time, and you can see that nginx distributes different requests to different http services on the backend,Trying to stop the site1 site, we can see that it does not affect our normal access, and nginx forwards all requests to the site2 site。
Nginx load balancing configuration status
| state | Overview | | down | The current server does not participate in load balancing for the time being | | backup | Reserved backup servers are enabled when all other servers are hung up | | max_fails | The number of failed requests allowed, if the number of failed requests exceeds the limit, kill the server from the virtual service pool after fail_timeout time | | fail_timeout | After a max_fails failure, the service pauses time, max_fails the fail_timeout value must be set | | max_conns | Limit the maximum number of connections for different server hardware configurations |
Nginx load balancing scheduling policy
| Scheduling algorithms | Overview | | Pollot | Poll one by one, the default method | | weight | Weighted polling, the higher the weight, the higher the chance of distribution | | ip_hash | The allocation of hash results from the accessing IP will cause requests from the same IP address to access a fixed background server | | url_hash | Assign according to the hash result of the visited URL | | least_conn | The minimum number of links, the server with fewer links will be assigned | | hash key value | hash custom key |
For more information about nginx configurations, see:The hyperlink login is visible.
|
Previous:Nginx log splitting and deletionNext:The concept and difference between ITO, BPO, KPO, and the three
|