haprox external-check 健康检测可以自定义脚本来检测后端服务,这非常有利于那些经常出现假死,无法通过常规判断端口来检测后台是否正常的问题。
比如,RabbitMQ,业务程序自定义检查等。
HAProxy可以使用二进制或脚本运行外部命令来执行运行状况检查。 当这样做的时候,它需要将自己fork一个新进程。
如果您使用chroot,请确保该命令及其所有依赖项在chroot中可用。
以下指令可用:
In the global section:
external-check: Allows the use of the external check feature. It is disabled by default for security purposes.
In the defaults, backend, or listen section:
option external-check: Enables the use of an external command to perform health check
external-check command
下面的参数被传递给命令:
写了一个bash脚本测试,发现在backend那里传了4个参数,如下,只有后面两个可用
Quoted Values: NOT_USED NOT_USED 172.20.2.71 5672
Total Number of Parameters : 4
where:
只有在侦听部分配置了此伪指令时,才会设置
Their values are derived from the first listener (bind) that is either IPv4, IPv6 or a UNIX socket.
它们的值来源于IPv4,IPv6或UNIX套接字的第一个侦听器(绑定)。
In the case of a UNIX socket listener, the
In a back end section where there is no bind, both are set to NOT_USED.
Other information is provided through the environment variable
HAPROXY_PROXY_ADDR: first bind address, available when used in a listen section The In the external-check path
HAPROXY_PROXY_ID: back end UUID
HAPROXY_PROXY_NAME: back end name
HAPROXY_PROXY_PORT: first bind port, available when used in a listen section
HAPROXY_SERVER_ADDR: server address
HAPROXY_SERVER_CURCONN: current active connections on the server
HAPROXY_SERVER_ID: server UUID
HAPROXY_SERVER_MAXCONN: server’s maxconn
HAPROXY_SERVER_NAME: server name
HAPROXY_SERVER_PORT: server port (empty for a UNIX socket)
PATH: PATH environment variable set by external-check path
0: check is considered as positive
any other value is considered as a failure
0:检查被认为是正面的
任何其他值被视为失败
在外部检查路径
比如python的路径
Example
Run a bash script that needs simple commands like ping to perform health checking:
global
# chroot /var/empty # disable chroot
external-check
[...]
backend b_myapp
option external-check
external-check path "/usr/bin: /bin:/usr/bin/"
external-check command /etc/hapee-1.5/scripts/check.sh"
文章评论
哇,大神还在更新
朋友 交换链接吗