设为首页 收藏本站
查看: 623|回复: 0

[经验分享] Nginx: upstream parameters 参数

[复制链接]

尚未签到

发表于 2016-12-25 09:02:10 | 显示全部楼层 |阅读模式
  Nginx: upstream parameters 参数, 配置负载均衡时如下例:

upstream backend {
server backend1.example.com weight=5;
server 127.0.0.1:8080       max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
}
  其中可选参数为: weight=number, max_fails=number, fail_timeout=time, backup, down;
  官网文档原文:
  Defines an address and other parameters of the server. An address can be specified as a domain name or IP address, and an optional port, or as a UNIX-domain socket path specified after the “unix:” prefix. If port is not specified, the port 80 is used. A domain name that resolves to several IP addresses essentially defines multiple servers.
  The following parameters can be defined:
  weight=number

sets a weight of the server, by default 1.

max_fails=number

sets a number of unsuccessful attempts to communicate with the server during a time set by the fail_timeout parameter after which it will be considered down for a period of time also set by the fail_timeout parameter. By default, the number of unsuccessful attempts is set to 1. A value of zero disables accounting of attempts. What is considered to be an unsuccessful attempt is configured by the proxy_next_upstream, fastcgi_next_upstream, and memcached_next_upstream directives. The http_404 state is not considered an unsuccessful attempt.

fail_timeout=time

sets

  • a time during which the specified number of unsuccessful attempts to communicate with the server should happen for the server to be considered down;
  • and a period of time the server will be considered down.

By default, timeout is set to 10 seconds.
backup
marks the server as a backup server. It will be passed requests when the primary servers are down.
down
marks the server as permanently down; used along with the ip_hash directive.  Example:


upstream backend {
server backend1.example.com     weight=5;
server 127.0.0.1:8080           max_fails=3 fail_timeout=30s;
server unix:/tmp/backend3;
server backup1.example.com:8080 backup;
}

syntax:
ip_hash;

default:
context:
upstream



  Specifies that a group should use a load balancing method where requests are distributed between servers based on client IP addresses. The first three octets of the client IPv4 address, or the entire IPv6 address, are used as a hashing key. The method ensures that requests of the same client will always be passed to the same server except when this server is considered down in which case client requests will be passed to another server and most probably it will also be the same server.
  IPv6 addresses are supported starting from versions 1.3.2 and 1.2.2.
  If one of the servers needs to be temporarily removed, it should be marked with the down parameter in order to preserve the current hashing of client IP addresses.
  Example:


upstream backend {
ip_hash;
server backend1.example.com;
server backend2.example.com;
server backend3.example.com down;
server backend4.example.com;
}


Until versions 1.3.1 and 1.2.2 it was not possible to specify a weight for servers using the ip_hash load balancing method.

syntax:
keepalive connections;

default:
context:
upstream

  This directive appeared in version 1.1.4.


  Activates cache of connections to upstream servers.
  个人总结上面几点:
  1. IPV6 从Nginx1.2.2(稳定版本)支持;
  2. ip_hash 可以支持 weight参数,从Nginx1.2.2(稳定版本)支持;
  3. down 只在配置ip_hash中使用;
  4. max_fails和fail_timeout参数要结合使用;
  5. 当一个做balance的servers配置max_fails和fail_timeout时:
  当在fail_timeout的时间内,某个server连接失败了max_fails次,则nginx会认为该server不工作了.
  同时,在接下来的 fail_timeout时间内,nginx不再将请求分发给失效的server.
  如果超出fail_timeout后,nginx则继续把request发往该server上.
  后面依次再做上面循环.

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-319005-1-1.html 上篇帖子: nginx module 开发谈(4) 下篇帖子: php脚本解析nginx日志
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表