Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Nginx basic 4 load balancing

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

1. Configuration

Http segment configuration

Upstream jing {server 192.168.0.25 max_fails=3 fail_timeout=20s weight=2; 80 max_fails=3 fail_timeout=20s weight=1; server 192.168.0.28 max_fails=3 fail_timeout=20s weight=2; # the following parameter indicates that if the request fails three times in a row, it will be shut down for 20s and the request will not be accepted.

# means to create a virtual web group, name "jing"

Server segment

Location / {proxy_pass http://jing/;}

# location match to forward to "jing" virtual web group

two。 Scheduling algorithm

Polling (rr), the default scheduling algorithm, distributes requests equally to two backend hosts. If there are 10 requests on a page, the first web host responds to 1 3 5 7 9 and the second host responds, 2 4 6 8 10. Note that polling is loaded by request.

Weighted polling (wrr), like polling, is weighted. If web1 "weight=1", web2 "weight=2", there is a page with 9 requests, web1 will respond to 3 and web will respond to 6.

Ip_hash, each request is allocated according to the hash result of accessing the ip, so that each visitor accesses a back-end server regularly, which can solve the session problem.

Url_hash (third party) allocates to different backend servers according to the url resource path requested by the user, which can solve the problem that the backend is the cache server to improve the hit rate.

The minimum number of least_conn connections. According to the client situation responded by the current back-end server, the current access request is dispatched to the server with relatively few responses from the back-end server.

Fair (third party) allocates requests according to the response time of the back-end server, giving priority to those with short response time. More intelligent load balancing algorithm than weight and ip_hash, fair algorithm can intelligently balance the load according to the page size and loading time, that is, allocate requests according to the response time of the back-end server, and give priority to the short response time. Nginx itself does not support fair. If this scheduling algorithm is needed, the upstream_fair module must be installed.

3. Server statu

Down indicates that the server before the order does not participate in the load for the time being.

The default weight is that the larger the 1.weight, the greater the weight of the load.

Max_fails: the number of requests allowed to fail defaults to 1. When the maximum number of times is exceeded, the maximum number of failures is set within the time set by the fail_timeout parameter, during which time all requests for the server fail, then the server is considered to be down.

After a fail_timeout:max_fails failure, the pause time is 10 seconds by default.

Backup: all other non-backup machines down or request backup machines when they are busy. So this machine will be the least stressed.

4. Layer 4 proxy (just like firewall port mapping)

Vim / etc/nginx/nginx.conf

# modify the nignx main configuration file first and add the folder of the four-tier agent outside the http section

Mkdir-pv / etc/nginx/conf.4

Vim / etc/nginx/conf.4/ssh.conf # New forwarding profile

Stream {upstream ssh {server 192.168.0.28 listen 22;} server {listen 10022; proxy_connect_timeout 3s; # proxy timeout proxy_timeout 3s; # server returns timeout proxy_pass ssh;}}

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.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report