原理

1 HAProxy将客户端ip进行Hash计算并保存,由此确保相同IP访问时被转发到同一真实服务器上。

2 HAProxy依靠真实服务器发送给客户端的cookie信息进行回话保持。

3 HAProxy保存真实服务器的session及服务器标识,实现会话保持功能。

 

Frontend 负责client,Backend 负责server

 

 

Dash board

rate分了:

  1. connection rate per second :clients连接至HAProxy的频率(还没有创建完整的sessions)
  2. session rate per second:session 作为一个持有端到端连接(client到HAProxy,HAProxy到后端服务器)状态的实体,被创建的速率
  3. request rate per second:在建立的连接上,HTTP请求被接收的频率

 

Session rate

描述client连接到HAProxy的速率。

  • Cur: session 作为一个持有端到端连接(client到HAProxy,HAProxy到后端服务器)状态的实体,被创建的速率
  • Max: 同一时刻,使用中的最多session数
  • Limit: 前端每秒可接收的最大session数。设置在 rate-limit sessions. 如果这个限制被超过,多出来的连接将被pending在socket的backlog中(在系统buffer里)

 

Sessions

haproxy使用场景 haproxy原理详解_Server

负载均衡器上,使用中的sessions完整client-to-server连接的数量。

  • Cur: 当前建完sessions 数量
  • Max: 最多同时建过的sessions数
  • Limit:最大并发的sessions数,定义在 frontend中的maxconn。达到这个限制后,前端将停止接收新的连接。如果maxconn 没有设置,Limit将和您的配置中global那一节的maxconn 值相同。若这个也没设,那么Limit将基于您的系统(tnnd,在公司呆久了,都变您了)

 

Denied

基于安全考虑,拒掉的request or response 数量

 

Errors

haproxy使用场景 haproxy原理详解_haproxy使用场景_02

  • Req:遇到错误的request数量
  • Conn:遇到错误的connection数量
  • Resp:遇到错误的responds数量

Server

对frontend而言,只有Status有值

haproxy使用场景 haproxy原理详解_HTTP_03

  • Status:当Status为OPEN时,frontend处于正常运行状态,并且可以接收traffic。当你执行Runtime API 命令 disable frontend ,你可以disable frontend,这时status将变为STOP。

对backend而言,Server 展示了关于 状态、健康程度、各server的权重。

haproxy使用场景 haproxy原理详解_Server_04

  • Status:有如下的值

 

Status

What it means

UP

The server is reporting as healthy.

DOWN

The server is reporting as unhealthy and unable to receive requests.

NOLB

You’ve added http-check disable-on-404 to the backend and the health checked URL has returned an HTTP 404 response.

MAINT

The server has been disabled or put into maintenance mode.

DRAIN

The server has been put into drain mode.

no check

Health checks are not enabled for this server.

  • LastChk :会有一个值 like L7OK/200 in 1ms。 表示已经执行了一个Layer 7的健康检查,并返回了一个HTTP 200 OK的response,且这一系列动作耗时<=1ms。      若您看到L4OK in 0ms,意味着Haproxy可以和server建立一个 Layer 4 connection
  • Wght: traffic被接受的比例,as set by the weight parameter on the server line. 
  • Act:该server为active(标为Y)还是backup(标为 a -)
  • Bck:该server为backup(标为Y) 还是 active(标为 a -)
  • Chk: 失败的健康检查数
  • Dwn:从UP到DOWN的transitions数量
  • Dwntme:server 下线多久了

 

 

参考文献:

https://blog.51cto.com/superleedo/1895570