[摘要] keepalived 对后端webserver健康检查一般使用TCP_CHECK或者HTTP_GET方式,如果要使用自定义脚本做健康检查就需要使用CHECK方式了。
keepalived配置,两台代理服务器做成了LVS,防止单点故障 🙂
real_server 10.90.250.5 3128 { weight 10 MISC_CHECK { misc_path "/usr/local/bin/check_squidproxy.sh 172.31.10.21 3128 https://about.twitter.com/?from=t" misc_timeout 10 misc_dynamic }
下面是自定义的健康检查脚本:
cat /usr/local/bin/check_squidproxy.sh #!/bin/bash # Author: Fisher at sudops.com # Script: check_squidproxy.sh # Version: 1.0 # if [ $# -ne 3 ];then echo "Warning: check_command error." exit 1 else PROXY_IP=$1 PROXY_PORT=$2 CHECK_URL=$3 CMD=`/usr/bin/curl -I -x ${PROXY_IP}:${PROXY_PORT} "${CHECK_URL}" 2>/dev/null | grep "200 OK" | wc -l` if [ ${CMD} -ne 1 ];then echo "CRITCAL: check proxy ${PROXY_IP} failed." exit 1 else echo "OK: check proxy ${PROXY_IP} OK." echo 0 fi fi