First, introduce
Nginx upstream can achieve load balancing.
Third-party module Ngx_http_consistent_hash selects the appropriate back-end nodes through a consistent hashing algorithm.
Second, download, compile to Nginx
2.1 Download
FileName: ngx_http_consistent_hash-master.zip
GitHub Download: Https://github.com/replay/ngx_http_consistent_hash
Unzip Ngx_http_consistent_hash-master.zip
2.2 Compile to Nginx
./configure--add-module=/home/guowenyan/ngx_http_consistent_hash-master
Make
Make install
Third, nginx.conf configuration
Worker_processes 1;
Events {
worker_connections 1024;
}
HTTP {
upstream www.guowenyan.cn {
consistent_hash $request _uri;
Server 106.38.193.183:80;
Server 106.38.193.182:80;
}
server {
listen ;
server_name localhost;
Location/{
proxy_pass http://www.guowenyan.cn;
}
}
}
Iv. Verification Methods
4.1 Send URL Request
Send a different URL request multiple times.
Curl-x 127.0.0.1:80 Http://www.guowenyan.cn/1.txt-v
4.2 Grab the bag. View upstream to address
sudo tcpdump-i any TCP port and host \ (106.38.193.183 or 106.38.193.182\)-s0
Will find the same URL, always back to the same upstream IP address.
Resources:
Nginx third-party module: https://www.nginx.com/resources/wiki/modules/
Nginx's Ngx_http_consistent_hash module's official website uses the document: https://www.nginx.com/resources/wiki/modules/consistent_hash/