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. <cstring>中常用的两个函数memset()和memcpy()

    <cstring>是c++对c中的<string.h>进行了重写,这两个头文件中的函数用法是一样的,所以在用的时候包含哪个头文件都行.下面介绍一下 <cstring> ...

  2. php算--------法

    <?php //冒泡排序:两两交换数值,最小的值在最左边,就如最轻的气泡在最上边.对整列数两两交换一次//最小的数在最左边,每次都能得一个在剩下的数中的最小 的数//“冒”出来的数组成一个有序区 ...

  3. 日志分析工具ELK(二)

    五.Logstash日志收集实践 在学习Logstash之前,我们需要先了解以下几个基本概念: logstash收集日志基本流程: input-->codec-->filter--> ...

  4. Git 简明手册

    0,Git 是什么 Git 是一个VCS(Version Control System),即版本控制系统. 版本控制系统从字面意思来看,它的用途就是管理/控制文件的版本.使用它,可以方便的知道一个文件 ...

  5. MySQL 入门(1):查询和更新的内部实现

    摘要 在MySQL中,简单的CURD是很容易上手的. 但是,理解CURD的背后发生了什么,却是一件特别困难的事情. 在这一篇的内容中,我将简单介绍一下MySQL的架构是什么样的,分别有什么样的功能.然 ...

  6. java.util.concurrent简介

    文章目录 主要的组件 Executor ExecutorService ScheduledExecutorService Future CountDownLatch CyclicBarrier Sem ...

  7. 基于docker-compose部署LNMP

    一.配置环境 [root@docker ~]# systemctl stop firewalld[root@docker ~]# iptables -F[root@docker ~]# setenfo ...

  8. Python语言类型

    Python是一门动态解释型的强类型语言. 对这句话进行解析,语言分为动态的和静态的,编译型和解释型的,强类型的和弱类型的语言之分. 下面对三种不同维度的类型的语言进行解释: 1.编译型和解释型 差别 ...

  9. PostgreSQL 10.0 preview 性能增强 - 分区表性能增强(plan阶段加速)

    标签 PostgreSQL , 10.0 , 分区表 , 子表 , 元信息搜索性能增强 背景 PostgreSQL 10.0 增强了分区表的子表搜索性能,对于涉及分区表包含子表特别多的QUERY,可以 ...

  10. 电子书下载:C# Database Basics

    下载: http://download.csdn.net/detail/maxwoods/4089269