大旗谷资源网 Design By www.zqyou.com
1、轮询
轮询即Round Robin,根据Nginx配置文件中的顺序,依次把客户端的Web请求分发到不同的后端服务器。
配置的例子如下:
http{ upstream sampleapp { server <<dns entry or IP Address(optional with port); server <<another dns entry or IP Address(optional with port); } .... server{ listen 80; ... location / { proxy_pass http://sampleapp; } }
上面只有1个DNS入口被插入到upstream节,即sampleapp,同样也在后面的proxy_pass节重新提到。
2、最少连接
Web请求会被转发到连接数最少的服务器上。
配置的例子如下:
http{ upstream sampleapp { least_conn; server <<dns entry or IP Address(optional with port); server <<another dns entry or IP Address(optional with port); } .... server{ listen 80; ... location / { proxy_pass http://sampleapp; } }
上面的例子只是在upstream节添加了least_conn配置。其它的配置同轮询配置。
3、IP地址哈希
前述的两种负载均衡方案中,同一客户端连续的Web请求可能会被分发到不同的后端服务器进行处理,因此如果涉及到会话Session,那么会话会比较复杂。常见的是基于数据库的会话持久化。要克服上面的难题,可以使用基于IP地址哈希的负载均衡方案。这样的话,同一客户端连续的Web请求都会被分发到同一服务器进行处理。
配置的例子如下:
http{ upstream sampleapp { ip_hash; server <<dns entry or IP Address(optional with port); server <<another dns entry or IP Address(optional with port); } .... server{ listen 80; ... location / { proxy_pass http://sampleapp; } }
上面的例子只是在upstream节添加了ip_hash配置。其它的配置同轮询配置。
4、基于权重的负载均衡
基于权重的负载均衡即Weighted Load Balancing,这种方式下,我们可以配置Nginx把请求更多地分发到高配置的后端服务器上,把相对较少的请求分发到低配服务器。
配置的例子如下:
http{ upstream sampleapp { server <<dns entry or IP Address(optional with port) weight=2; server <<another dns entry or IP Address(optional with port); } .... server{ listen 80; ... location / { proxy_pass http://sampleapp; } }
上面的例子在服务器地址和端口后weight=2的配置,这意味着,每接收到3个请求,前2个请求会被分发到第一个服务器,第3个请求会分发到第二个服务器,其它的配置同轮询配置。
还要说明一点,基于权重的负载均衡和基于IP地址哈希的负载均衡可以组合在一起使用。
标签:
Nginx,负载均衡
大旗谷资源网 Design By www.zqyou.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
大旗谷资源网 Design By www.zqyou.com
暂无Nginx负载均衡的4种方案配置实例的评论...
更新日志
2024年09月25日
2024年09月25日
- 纯音入心系列纯音乐《天籁古筝》1CD[MP3][331MB]
- 男女对唱典藏天碟《发烧对唱·那个季节里的歌DSD》10CD[WAV]
- 群星2010-歌林精选辑[歌林][WAV+CUE]
- TrioZimbalist-PianoTriosofWeinberg,Auerbach,Dvorak(2024)[24-44,1]wav
- 群星.1992-滚石第一流台湾歌·12王牌大车拼【滚石】【WAV+CUE】
- 林子祥.1984-创作歌集【华纳】【WAV+CUE】
- 周汤豪.2010-周汤豪【华纳】【FLAC分轨】
- Mozart-TheStringQuintets-AmadeusQuartet,CecilAronowitz(2017)[24-44,1][WAV+CUE]
- JamesWilliamsDennisIrwin-Focus(2024,Red)[24-48]FLAC
- 藤泽麻衣《空みあげて》[WAV]
- 纯音入心系列纯音乐《中国古筝经典名曲》1CD[MP3][1.3GB]
- 纯音入心系列纯音乐《古筝新奏:岁月静好与筝语,细水流年与筝同》1CD[MP3][846.9MB]
- 670《脆弱敏感小女生》[320K/MP3][27.53MB]
- 曾琳.2011-好好爱我【南方】【WAV+CUE】
- 范晓萱.1995-RAIN【福茂】【WAV+CUE】