haproxy_keepalive高可用脚本

(从服务器使用)

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状态

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值