nginx模块之ngx_http_upstream_module

来源:互联网 发布:数控龙门铣编程视频 编辑:程序博客网 时间:2024/06/15 04:33
说明:将多个后端主机定义为服务器组,而后可由proxy_pass,fastcgi_pass,uwsgi_pass,scgi_pass和memcached_pa​​ss进行调用

1.定义后端服务器组
Syntax: upstream name { ... }
Default:
Context: http
说明:
定义一组服务器。服务器可以在不同端口上侦听。


2.定义服务器的地址和相关的参数
Syntax: server address [parameters];
Default:
Context: upstream

地址格式:
IP[:port]
HOSTNAME[port]

参数:
weight=number:服务器权重
max_conns=number:最大连接次数
max_fails=number:最大失败重试次数
fail_timeout=time:设置服务器被识别为不可用超时时长
backup:备用主机
down:标记该服务器不可用

演示:
配置nginx负载均衡
编辑/etc/nginx/nginx.conf
upstream websrvs {
server 192.168.80.11:80 weight=1;
server 192.168.80.12:80 weight=1;
}

在server中指定:
proxy_pass http://websrvs

3.源地址哈希调度算法
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 from the same client
will always be passed to the same server except when this server is unavailable.
In the latter case client requests will be passed to another server. Most probably,
it will always be the same server as well.

4.最少连接调度算法
Syntax: least_conn;
Default:
Context: upstream


5.保持连接
Syntax: keepalive connections;
Default:
Context: upstream
作用:节约套接字
原创粉丝点击