注:该脚本在keepalived配置文件中调用
#!/bin/bash
#如果nginx挂掉,重启nginx如果起不来nginx,停止keepalived,保证高可用ip漂移给备用keepalived
nginx=`netstat -tanulp|grep :80|wc -l`
if [ $nginx -eq 0 ];then
systemctl restart nginx
nginx=`netstat -tanulp|grep 80|wc -l`
if [ $nginx -eq 0 ];then
systemctl stop keepalived
fi
fi