Linux 如何在haproxy中保持活力?

Linux 如何在haproxy中保持活力?,linux,http,curl,web,haproxy,Linux,Http,Curl,Web,Haproxy,这是我的haproxy.conf(haproxy 1.7.9) 源服务器的curl结果: $ curl -vv http://192.168.56.150:8000/test --keepalive-time 700 * About to connect() to 192.168.56.150 port 8000 (#0) * Trying 192.168.56.150... * Connected to 192.168.56.150 (192.168.56.150) port 8000 (

这是我的haproxy.conf(haproxy 1.7.9)

源服务器的curl结果:

$ curl -vv http://192.168.56.150:8000/test --keepalive-time 700
* About to connect() to 192.168.56.150 port 8000 (#0)
*   Trying 192.168.56.150...
* Connected to 192.168.56.150 (192.168.56.150) port 8000 (#0)
> GET /test HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.56.150:8000
> Accept: */*
> 
< HTTP/1.1 200 OK 
< Etag: 720-6-59eeda80
< Content-Type: application/octet-stream
< Content-Length: 6
< Last-Modified: Tue, 24 Oct 2017 06:15:28 GMT
< Server: WEBrick/1.3.1 (Ruby/2.0.0/2015-12-16)
< Date: Fri, 27 Oct 2017 02:38:14 GMT
< Connection: Keep-Alive
< 
tests
* Connection #0 to host 192.168.56.150 left intact
$curl-vvhttp://192.168.56.150:8000/test --保持时间700
*即将连接()到192.168.56.150端口8000(#0)
*正在尝试192.168.56.150。。。
*连接到192.168.56.150(192.168.56.150)端口8000(#0)
>获取/测试HTTP/1.1
>用户代理:curl/7.29.0
>主持人:192.168.56.150:8000
>接受:*/*
> 
haproxy服务器的curl结果

$ curl -vv http://192.168.56.150:8080/test --keepalive-time 700
* About to connect() to 192.168.56.150 port 8080 (#0)
*   Trying 192.168.56.150...
* Connected to 192.168.56.150 (192.168.56.150) port 8080 (#0)
> GET /test HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.56.150:8080
> Accept: */*
> 
< HTTP/1.1 200 OK 
< Etag: 720-6-59eeda80
< Content-Type: application/octet-stream
< Content-Length: 6
< Last-Modified: Tue, 24 Oct 2017 06:15:28 GMT
< Server: WEBrick/1.3.1 (Ruby/2.0.0/2015-12-16)
< Date: Fri, 27 Oct 2017 02:38:05 GMT
< 
tests
* Connection #0 to host 192.168.56.150 left intact
$curl-vvhttp://192.168.56.150:8080/test --保持时间700
*即将连接()到192.168.56.150端口8080(#0)
*正在尝试192.168.56.150。。。
*连接到192.168.56.150(192.168.56.150)端口8080(#0)
>获取/测试HTTP/1.1
>用户代理:curl/7.29.0
>主持人:192.168.56.150:8080
>接受:*/*
> 
我通过
tcpdump
确认,从origin到haproxy的响应中存在
连接:Keep Alive


如您所见,haproxy响应中没有连接:Keep Alive
,如何使haproxy Keep Alive???

HTTP 1.1默认在Keep Alive模式下运行,请参阅。因此,为了使用持久连接(保持活动模式),您无需明确设置连接头。
只有在使用HTTP 1.0时才需要连接头,因为它被设计为在每次请求后关闭连接

因此,要验证HAProxy是否在保持活动模式下运行,您需要使用curl发送多个HTTP请求(而不仅仅是一个),并检查是否只建立和使用了一个连接。
这说明了如何做到这一点。(注意“连接到…”和“关闭连接”行)

$ curl -vv http://192.168.56.150:8080/test --keepalive-time 700
* About to connect() to 192.168.56.150 port 8080 (#0)
*   Trying 192.168.56.150...
* Connected to 192.168.56.150 (192.168.56.150) port 8080 (#0)
> GET /test HTTP/1.1
> User-Agent: curl/7.29.0
> Host: 192.168.56.150:8080
> Accept: */*
> 
< HTTP/1.1 200 OK 
< Etag: 720-6-59eeda80
< Content-Type: application/octet-stream
< Content-Length: 6
< Last-Modified: Tue, 24 Oct 2017 06:15:28 GMT
< Server: WEBrick/1.3.1 (Ruby/2.0.0/2015-12-16)
< Date: Fri, 27 Oct 2017 02:38:05 GMT
< 
tests
* Connection #0 to host 192.168.56.150 left intact