I. Concepts of reverse proxy and Server Load balancer
Before understanding the concepts of reverse proxy and Server Load balancer, we must first understand the concept of a cluster. Simply put, a cluster is a server that does the same thing, such as a web cluster, database cluster, and storage cluster, the cluster has two main functions: Improving the website's ability to process user requests and improving the stability of website operations. Generally, clusters can be divided into high-availability clusters (HA) and load balancing clusters (LB) the server Load balancer cluster can be implemented by using F5, A10, and other hardware devices. It can also be implemented by using software such as LVS (quad-component) and nginx (layer-7 and layer-4 after 1.9 ).
Hostname |
Server Type |
IP ADDR |
Web01 |
Web |
10.0.0.7 |
Web02 |
Web |
10.0.0.8 |
Web03 |
Web |
10.0.0.9 |
Lb01 |
LB |
10.0.0.5 |
(2) module description 1. Upstream Module
- Common functions
1. Define the information of the backend schedulable nodes in the HTTP block.
Example:
Upstream Jiang {
Server 10.0.0.7: 80;
Server 10.0.0.8: 80;
Server 10.0.0.9: 80;
}
②. Implement load access with Weight Values-weight
Upstream Jiang {
Server 10.0.0.7: 80 Weight = 3;
Server 10.0.0.8: 80 Weight = 1;
Server 10.0.0.9: 80 weigth = 1;
}
③ Define the number of backend access failures-max_fails
Upstream Jiang {
Server 10.0.0.7: 80 max_fails = 3;
Server 10.0.0.8: 80 max_fails = 3;
Server 10.0.0.9: 80 max_fails = 3;
}
④ Define the backend failure Retry Interval-fail_timeout
Upstream jiag {
Server 10.0.0.7: 80 max_fails = 3 fail_timeout = 10 s;
Server 10.0.0.8: 80 max_fails = 3;
Server 10.0.0.9: 80 max_fails = 3;
}
Note: after multiple failed attempts, the corresponding node will be given another opportunity after the specified Timeout time expires.
⑤ Define the backend Service's Hot Standby node-Backup (the Server Load balancer node is down and backup is used)
Upstream Jiang {
Server 10.0.0.7: 80 max_fails = 3 fail_timeout = 10 s;
Server 10.0.0.8: 80 max_fails = 3;
Server 10.0.0.9: 80 max_fails = 3 backup;
}
Module Scheduling Algorithm
1. Define the polling scheduling algorithm-rr-default Scheduling Algorithm
Adopt the average allocation principle
②. Define the weight scheduling algorithm-WRR
More energy
③ Define a static scheduling algorithm-ip_hash
Use a hash value to record access records. The next time the client accesses the server, it will still allocate the request to the previous server, and the visitor will log on repeatedly;
Upstream Jiang {
Ip_hash;
Server 10.0.0.7: 80 max_fails = 3 fail_timeout = 10 s;
Server 10.0.0.8: 80 max_fails = 3;
Server 10.0.0.9: 80 max_fails = 3;
}
④ Define the minimum number of connections-least_conn
If the user is idle, the request is allocated to the user.
Upstream oldboy {
Least_conn;
Server 10.0.0.7: 80 max_fails = 3 fail_timeout = 10 s;
Server 10.0.0.8: 80 max_fails = 3;
Server 10.0.0.9: 80 max_fails = 3;
}
2. ngx_http_proxy_module
①. Proxy_pass sends the client segment request to the corresponding address pool in the upstream Module
Location /{
Proxy_pass http: // Jiang;
}
②. Modify the reverse proxy to the backend request header information-proxy_set_header
Location /{
Proxy_pass http: // oldboy;
Proxy_set_header host $ host;
}
Proxy_set_header X-forwarded-for $ remote_addr; --- write the IP address of the real client to the backend Service Log;
(3) Deployment Implementation 1. Deploy the corresponding environment as planned, and create the corresponding virtual host (temporarily ignored) 2. Configure nginx Reverse Proxy Server Load balancer
[[Email protected] conf] # Vim nginx. conf
Worker_processes 1;
Events {
Worker_connections 1024;
}
HTTP {
Include mime. types;
Default_type application/octet-stream;
Sendfile on;
Keepalive_timeout 65;
Upstream Jiang {
Server 10.0.0.7: 80;
Server 10.0.0.8: 80;
Server 10.0.0.9: 80;
}
Server {
Listen 80;
SERVER_NAME blog.etiantian.org;
Root HTML;
Index index.html index.htm;
Location /{
Proxy_pass http: // Jiang;
}
}
}
Check the syntax and restart nginx.
3. Access Test
Enter a domain name in the browser to refresh the Test Structure
Nginx Reverse Proxy Server Load balancer