标签:for cal 节点 roc web href 官网 received 服务
Nginx负载均衡是通过upstream模块来实现,内置实现了三种负载策略。官网负载均衡配置说明:http://nginx.org/en/docs/http/load_balancing.html
Nginx根据请求次数,将每个请求均匀分配到每台服务
将请求分配给连接数最少的服务器。Nginx会统计哪些服务器的连接数最少。
绑定处理请求的服务器。第一次请求时,根据该客户端的IP算出一个HASH值,将请求分配到集群中的某一台服务器上。后面该客户端的所有请求,都将通过HASH算法,找到之前处理这台客户端请求的服务器,然后将请求交给它来处理。
# For more information on configuration, see:
# * Official English Documentation: http://nginx.org/en/docs/
# * Official Russian Documentation: http://nginx.org/ru/docs/
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
# Load dynamic modules. See /usr/share/nginx/README.dynamic.
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 65535;
}
stream {
log_format basic ‘$remote_addr [$time_local] ‘
‘$protocol $status $bytes_sent $bytes_received ‘
‘$session_time‘;
upstream test_cluster {
server 192.168.1.100:4010 weight=2 max_fails=3 fail_timeout=15;;
server 192.168.1.101:4011 weight=3;
server 192.168.1.102:4012 weight=1;
server 192.168.1.103:4013 weight=4;
}
server {
listen 50052;
proxy_connect_timeout 1s;
proxy_pass test_cluster;
access_log /var/log/nginx/test_cluster.log basic;
error_log /var/log/nginx/ptest_cluster-error.log debug;
}
}
weight
默认为1,将请求平均分配给每台server,配置 weight 值,即配置分配请求权重
max_fails
默认为1。某台Server允许请求失败的次数,超过最大次数后,在fail_timeout时间内,新的请求将不会分配给这台机器。如果设置为0,Nginx会将这台Server置为永久无效状态,然后将请求发给定义了proxy_next_upstream, fastcgi_next_upstream, uwsgi_next_upstream, scgi_next_upstream, and memcached_next_upstream指令来处理这次错误的请求
fail_timeout
默认为10秒。某台Server达到max_fails次失败请求后,在fail_timeout期间内,nginx会认为这台Server暂时不可 用,不会将请求分配给它。(192.168.0.100这台机器,如果有3次请求失败,nginx在15秒内,不会将新的请求分配给它。)
参考资料:
标签:for cal 节点 roc web href 官网 received 服务
原文地址:https://www.cnblogs.com/ronky/p/9792135.html