(从服务器使用)
vim /root/haproxy.sh
//编写实现高可用脚本
#!/bin/bash
ip a | grep 192.168.1.254 &>/dev/null
//判断如调度器漂移地址存在时(仅IP会一直重启)
A=$(netstat -utpln | grep 80 | wc -l)
//判断如端口80存在时(最好也判断端口)
if [ $? -eq 0 ] && [ $A -eq 0 ]
//判断条件成立
then
/etc/init.d/haproxy restart 2>/var/log/haproxy.err
//则执行启动服务
fi
赋予脚本执行权限
chmod +x /root/haproxy.sh
制定计划任务
crontab -e
*/1 * * * * /root/haproxy.sh
(主服务器使用)
vim /root/haproxy.sh
//编写实现高可用脚本
#!/bin/bash
ip a | grep 192.168.1.254 &>/dev/null
//判断如调度器漂移地址存在时(仅IP会一直重启)
A=$(netstat -utpln | grep 80 | wc -l)
//判断如端口80存在时(最好也判断端口)
if [ $? -eq 0 ] && [ $A -eq 0 ]
//判断条件成立
then
/etc/init.d/haproxy restart
//则执行启动服务
echo “haproxy start”
else
/etc/init.d/haproxy stop
//VIP不存在时关闭80端口
fi
赋予脚本执行权限
chmod +x /root/haproxy.sh
制定计划任务
crontab -e
*/1 * * * * /root/haproxy.sh
注:脚本必须现有调度器都部署,会自动检测漂移地址ip状态
最后
以上就是酷炫自行车最近收集整理的关于haproxy_keepalive高可用脚本的全部内容,更多相关haproxy_keepalive高可用脚本内容请搜索靠谱客的其他文章。
发表评论 取消回复