lb的keepalive问题

0. keepalive

大家都很清楚他的用意了,就是为了减少3次握手,设置一个timeout,比如说20s ,在20s内不请求,连接还是保持着,这时候请求过来,不需要重新经过tcp的三次握手,如果超过了就会断掉,重连的话就要3次握手。

一个正常的keepalive回复头有2个参数:

  1. timeout 超时
  2. max 最多能处理的请求

    max的详细解释如下:
Sets the maximum number of requests that can be served through one keepalive connection. After the maximum number of requests is made, the connection is closed.

就是一个连接上面的请求数,如果超了连接也会断。

一个例子如下:

请求头:

Connection: keep-alive
Connection: close

回复头:

HTTP/1.1 200 OK
Connection: Keep-Alive
Content-Encoding: gzip
Content-Type: text/html; charset=utf-8
Date: Thu, 11 Aug 2016 15:23:13 GMT
Keep-Alive: timeout=5, max=1000
Last-Modified: Mon, 25 Jul 2016 04:32:39 GMT
Server: Apache (body)

1. web server实现

nginx

apache httpd

request:

Host: 119.3.62.49
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:69.0) Gecko/20100101 Firefox/69.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Cache-Control: max-age=0

response:

HTTP/1.1 200 OK
Date: Sat, 21 Sep 2019 11:09:02 GMT
Server: Apache/2.4.6 (CentOS)
Last-Modified: Sat, 21 Sep 2019 11:07:58 GMT
ETag: "f-5930e3301e037"
Accept-Ranges: bytes
Content-Length: 15
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

httpd 2.4为例,分别有3个参数可以指定keepalive的行为:

KeepAlive 默认是打开的:

Description:	Enables HTTP persistent connections
Syntax: KeepAlive On|Off
Default: KeepAlive On
Context: server config, virtual host
Status: Core
Module: core

默认超时是5s:

Description:	Amount of time the server will wait for subsequent requests on a persistent connection
Syntax: KeepAliveTimeout num[ms]
Default: KeepAliveTimeout 5
Context: server config, virtual host
Status: Core
Module: core

MaxKeepAliveRequests 默认是100个,对应http协议是 max=100

Description:	Number of requests allowed on a persistent connection
Syntax: MaxKeepAliveRequests number
Default: MaxKeepAliveRequests 100
Context: server config, virtual host
Status: Core
Module: core

详细参考官网 https://httpd.apache.org/docs/2.4/mod/core.html

nginx

对某些浏览器关闭keepalive,默认是对老的ie浏览器disable,如果设置成none的话就全开:

Syntax: 	keepalive_disable none | browser ...;
Default: keepalive_disable msie6; Context: http, server, location Disables keep-alive connections with misbehaving browsers. The browser parameters specify which browsers will be affected. The value msie6 disables keep-alive connections with old versions of MSIE, once a POST request is received. The value safari disables keep-alive connections with Safari and Safari-like browsers on macOS and macOS-like operating systems. The value none enables keep-alive connections with all browsers.
 Syntax: 	keepalive_requests number;
Default: keepalive_requests 100; Context: http, server, location This directive appeared in version 0.8.0. Sets the maximum number of requests that can be served through one keep-alive connection. After the maximum number of requests are made, the connection is closed.
Syntax: 	keepalive_timeout timeout [header_timeout];
Default: keepalive_timeout 75s; Context: http, server, location The first parameter sets a timeout during which a keep-alive client connection will stay open on the server side. The zero value disables keep-alive client connections. The optional second parameter sets a value in the “Keep-Alive: timeout=time” response header field. Two parameters may differ. The “Keep-Alive: timeout=time” header field is recognized by Mozilla and Konqueror. MSIE closes keep-alive connections by itself in about 60 seconds.

基本上跟httpd的差不多

详细参考官网 https://nginx.org/en/docs/http/ngx_http_core_module.html#keepalive_disable

2. 云厂商的7层负载均衡设置

云厂商的lb参数一般没法调,keepalive的值我确认了一下,举国内厂商为例:

  1. 阿里云,默认keepalive_timeout 15s ,无法关闭。
  2. 华为云,默认keepalive_timeout 300s,无法关闭。

均无法关闭,而且华为云的timeout值有点过大了。

3. keepalive_timeout过大造成的影响

就是用户端会长时间停留在该lb上面,如果你只有1个lb,一个机房,那其实没啥影响,但是如果你有多机房部署,会造成用户到不了其他地方的问题。

lb的keepalive问题的更多相关文章

  1. mysql高可用之LVS + KEEPALIVE + MYSQL

    1.架构图 注意 (一)   Mysql需要把bind-address的配置去掉,否则无法实现虚拟ip访问 (二)   关闭所有linux防火墙:/sbin/iptables –F(可能没用) (三) ...

  2. keepalive集群工作原理及应用

    author:JevonWei 版权声明:原创作品 集群工作原理 一.集群基础 1.系统的扩展方式 scale up向上扩展:提高单台服务器的性能 scale out向外扩展:多台服务器联合起来满足同 ...

  3. [svc]高并发场景 LVS DR +KeepAlive高可用实现及ka的persistence_timeout参数

    LVS-DR+keepalived模式是一种非常经典的常用生产组合 高可用场景及LVS架构 一般都用一(负载)拖多(Server Array)方式 使用LVS架设的服务器集群系统有三个部分组成: (1 ...

  4. LVS 负载均衡 keepalive

    为什么要学lvs 工作在网络模型的7层,可以针对http应用做一些分流的策略,比如针对域名.目录结构, Nginx单凭这点可利用的场合就远多于LVS了.最新版本的Nginx也支持4层TCP负载,曾经这 ...

  5. centos LB负载均衡集群 三种模式区别 LVS/NAT 配置 LVS/DR 配置 LVS/DR + keepalived配置 nginx ip_hash 实现长连接 LVS是四层LB 注意down掉网卡的方法 nginx效率没有LVS高 ipvsadm命令集 测试LVS方法 第三十三节课

    centos   LB负载均衡集群 三种模式区别 LVS/NAT 配置  LVS/DR 配置  LVS/DR + keepalived配置  nginx ip_hash 实现长连接  LVS是四层LB ...

  6. lb route 相关的一些问题

    lb route 相关的一些问题 ========================== 查看系统平台和版本 > show hardware Platform: NetScaler Virtual ...

  7. keepalive和脑裂问题

    keepalive keepalive起初专门为lvs负载均衡软件设计的,用来管理监控lvs集群系统中各个服务节点的状态,后来又加入了可以实现高可用的vrrp功能. keepalive软件通过vrrp ...

  8. nginx keepalive 双机

    Nginx+keepalived双机热备(主从模式)   负载均衡技术对于一个网站尤其是大型网站的web服务器集群来说是至关重要的!做好负载均衡架构,可以实现故障转移和高可用环境,避免单点故障,保证网 ...

  9. aliyun---经过LB到后端k8s压测超时的问题

    环境:阿里云 压测主机:阿里云ECS(非LB后的主机) 压测目标:阿里云k8s自己的某个服务 k8s配置在kube-system 按照之前的ingress-nginx 配置了一个内网的ingress- ...

随机推荐

  1. 对JavaScript中的this的理解

    什么是this: 解析器(就是浏览器)在调用函数时,每次都会向函数内部传递两个隐含的参数: 这两个隐含参数其中一个就是this(还有一个是arguments,用来接收函数的实参),this指向的是一个 ...

  2. koa+mysql实现增删改查-全栈之路(001)

    Date: 2020-4-23 以前很少写文章,从今天开始我要挑战一下自己,连续输出100篇技术类文章.这100篇文章我尽量以实战案例为主. 如果你觉得本文还不错,记得关注或者给个 star,你们的赞 ...

  3. 【Linux常见命令】tar命令

    [独立命令,只能用其中一个,和别的命令连用]这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个. -c: 建立压缩档案 -x:解压 -t:查看内容 -r:向压缩归档文件末 ...

  4. Aurora: 来自 Amazon 的高性能的企业级关系数据库,兼容 MySQL

    近日,在美国召开的AWS re:Invent云计算大会上,Amazon高级副总裁安迪·杰西发布了企业级关系数据库Aurora.Aurora是一个面向Amazon RDS(关系数据库服务).兼容MySQ ...

  5. Frame Relay Voice Traffic Shaping and Frament

    本文全称应该是:Frame Relay Voice-Adaptive Traffic Shaping and Fragmentation,标题限制字数,没办法了   帧中继的流量整型向来是个头疼的地方 ...

  6. 数学--数论--HDU 2136(素数筛选法)

    Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...

  7. muduo网络库源码学习————互斥锁

    muduo源码的互斥锁源码位于muduo/base,Mutex.h,进行了两个类的封装,在实际的使用中更常使用MutexLockGuard类,因为该类可以在析构函数中自动解锁,避免了某些情况忘记解锁. ...

  8. SpringBoot:整合Druid、MyBatis

    目录 简介 JDBC 导入依赖 连接数据库 CRUD操作 自定义数据源 DruidDataSource Druid 简介 配置数据源 配置 Druid 数据源监控 配置 Druid web 监控 fi ...

  9. Spring源码阅读 之 配置的读取,解析

    在上文中我们已经知道了Spring如何从我们给定的位置加载到配置文件,并将文件包装成一个Resource对象.这篇文章我们将要探讨的就是,如何从这个Resouce对象中加载到我们的容器?加载到容器后又 ...

  10. MinorGC前检查