qingkuangs 发表于 2017-4-18 10:37:26

LVS心跳监控脚本

  最近接触一个做LVS集群的部署方案,需要提供一个心跳监控脚本。
  要求:LVS每隔1分钟调用后台服务器指定页面,若连续三次超时或无法访问,则认为该后台服务器访问失败,LVS应切换到其他服务器进行后续服务。

#! /bin/sh
#
#desc:heartbeat monitor for lvs
#

hb_page="test.html"
hb_path="http://192.168.56.100/"$hb_page
log_path="bh.log"

if [ ! -f "$log_path" ]; then
touch $log_path
fi
# del all exist file
rm -f $hb_page*
hasFailCount=$(<$log_path)
#links 如果无法访问可能出现卡死的现象
#fileCount=$(links -dump $hb_path | grep "hb" | wc -l)

wget $hb_path -T 10
fileCount=$(ls -l | grep $hb_path | wc -l)
echo "file count:" $fileCount
if [ $fileCount -ge 1 ];then
echo "OK"
echo "0" > $log_path
else
let hasFailCount+=1
if [ $hasFailCount -eq 3 ];then
echo "error"
else
echo "OK"
echo "$hasFailCount" > $log_path
fi
fi
页: [1]
查看完整版本: LVS心跳监控脚本