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上.
后面依次再做上面循环.
分享到:
相关推荐
此资源有两个文件,含 nginx-upstream-jvm-route 和 nginx 对应版本,都是tar.gz文件。 安装方法网上很多就不写了,亲测可用。 不用担心版本不匹配造成安装失败,再浪费积分去到处下载尝试的烦恼。 此资源有两个文件...
nginx-upstream-jvm-route 支持nginx版本1.15 解决nginx: [emerg] invalid parameter "srun_id=tomcat1" 问题
官方nginx 镜像不带主动健康,本镜像将 nginx_upstream_check健康检查 打包到了镜像中。
nginx:alpine离线镜像包,使用docker load -i nginxalpine.tar
实战Nginx:取代Apache的高性能Web服务器+张宴.扫描版、完整版,有需要的学习下!
NGINX第三方模块:nginx_upstream_hash-0.3.1.tar.gz。
报错内容:sbin/nginx: error while loading shared libraries: libpcre.so.1: cannot open shared object file: No such file or directory 启动时如果报异常error while loading shared libraries: libpcre.so....
nginx_upstream_jvm_route 是一个 Nginx 的扩展模块,用来实现基于 Cookie 的 Session Sticky 的功能。 安装方法(进入Nginx源码目录): #patch -p0 # ./configure --prefix=/usr/nginx-0.8.1 --with-...
nginx_upstream_jvm_route 是一个 Nginx 的扩展模块,用来实现基于 Cookie 的 Session Sticky 的功能。 安装方法(进入Nginx源码目录): #patch -p0 # ./configure --prefix=/usr/nginx-0.8.1 --with-...
实战Nginx:取代Apache的高性能Web服务器.
Nginx是由伊戈尔·赛索耶夫为俄罗斯访问量第二的Rambler.ru站点(俄文:Рамблер)开发的,第一个公开版本0.1.0发布于2004年10月4日。 其将源代码以类BSD许可证的形式发布,因它的稳定性、丰富的功能集、示例...
《深入理解Nginx:模块开发与架构解析》是阿里巴巴资深Nginx技术专家呕心沥血之作,是作者多年的经验结晶,也是目前市场上唯一一本通过还原Nginx设计思想,剖析Nginx架构来帮助读者快速高效开发HTTP模块的图书。...
这是一个很小的脚本文件用来管理 Nginx 的 upstream 配置。 使用方法:upstream_manager.py <cluster> <action> [...]
借助淘宝技术团队开发的nginx模快nginx_upstream_check_module来检测后方realserver的健康状态,如果后端服务器不可用,则会将其踢出upstream,所有的请求不转发到这台服务器。当期恢复正常时,将其加入upstream。 ...
实战Nginx:取代Apache的高性能Web服务器
深入理解Nginx:模块开发与架构解析(第2版)+(Linux_Unix技术丛书)+-+陶辉+著
实战Nginx:取代Apache的高性能Web服务器.pdf
实战_Nginx:取代Apache的高性能Web服务器
NGINX第三方模块:nginx_upstream_hash-0.3.2版本。。。
决战Nginx: 系统卷 - 高性能Web服务器详解与运维