Chinaunix首页 | 论坛 | 博客
  • 博客访问: 378464
  • 博文数量: 190
  • 博客积分: 50
  • 博客等级: 民兵
  • 技术积分: 125
  • 用 户 组: 普通用户
  • 注册时间: 2013-01-12 14:05
文章分类

全部博文(190)

文章存档

2013年(190)

我的朋友

分类: LINUX

2013-05-14 10:20:05

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://blog.chinaunix.net/space.php?uid=9419692&do=blog&id=3184076

因squid对多核服务器支持不够理想,所以在每台freebsd服务器上(4核)开启了3个squid
平稳的运行了一段时间,有一天客服反映网页无法打开,然后就对每台squid服务器进行检查,发现有台服务器其中的一个squid进程死掉了,重新启动该squid,一切正常,为了及时发现squid进程故障并重启squid,特写了以下脚本
定时器,每过10分钟检查一次,无限循环
vi /root/restart_squid.sh
#!/bin/sh
while true
do
Squid1_IP=`awk '/ifconfig_lo0_alias0/{print $2}' /etc/rc.conf`
Squid1Num=`netstat -an | grep -c $Squid1_IP`
if [ $Squid1Num -lt 10 ] ; then
/usr/local/etc/rc.d/squid1 start
/usr/local/etc/rc.d/squid1 restart
adddate=`date +%Y-%m-%d`" "`date +%H:%M:%S`
echo "$adddate squid_1 started" >> /var/restart_squid.log
fi
Squid2_IP=`awk '/ifconfig_lo0_alias1/{print $2}' /etc/rc.conf`
Squid2Num=`netstat -an | grep -c $Squid2_IP`
if [ $Squid2Num -lt 10 ] ; then
/usr/local/etc/rc.d/squid2 start
/usr/local/etc/rc.d/squid2 restart
adddate=`date +%Y-%m-%d`" "`date +%H:%M:%S`
echo "$adddate squid_2 started" >> /var/restart_squid.log
fi
Squid3_IP=`awk '/ifconfig_lo0_alias2/{print $2}' /etc/rc.conf`
Squid3Num=`netstat -an | grep -c $Squid3_IP`
if [ $Squid3Num -lt 10 ] ; then
/usr/local/etc/rc.d/squid3 start
/usr/local/etc/rc.d/squid3 restart
adddate=`date +%Y-%m-%d`" "`date +%H:%M:%S`
echo "$adddate squid_3 started" >> /var/restart_squid.log
fi
sleep 10m
done
chmod +x /root/restart_squid.sh
/root/restart_squid.sh
也可以用计划任务来实现
vi /root/restart_squid.sh
#!/bin/sh
Squid1_IP=`awk '/ifconfig_lo0_alias0/{print $2}' /etc/rc.conf`
Squid1Num=`netstat -an | grep -c $Squid1_IP`
if [ $Squid1Num -lt 10 ] ; then
/usr/local/etc/rc.d/squid1 start
/usr/local/etc/rc.d/squid1 restart
adddate=`date +%Y-%m-%d`" "`date +%H:%M:%S`
echo "$adddate squid_1 started" >> /var/restart_squid.log
fi
Squid2_IP=`awk '/ifconfig_lo0_alias1/{print $2}' /etc/rc.conf`
Squid2Num=`netstat -an | grep -c $Squid2_IP`
if [ $Squid2Num -lt 10 ] ; then
/usr/local/etc/rc.d/squid2 start
/usr/local/etc/rc.d/squid2 restart
adddate=`date +%Y-%m-%d`" "`date +%H:%M:%S`
echo "$adddate squid_2 started" >> /var/restart_squid.log
fi
Squid3_IP=`awk '/ifconfig_lo0_alias2/{print $2}' /etc/rc.conf`
Squid3Num=`netstat -an | grep -c $Squid3_IP`
if [ $Squid3Num -lt 10 ] ; then
/usr/local/etc/rc.d/squid3 start
/usr/local/etc/rc.d/squid3 restart
adddate=`date +%Y-%m-%d`" "`date +%H:%M:%S`
echo "$adddate squid_3 started" >> /var/restart_squid.log
fi
chmod +x /root/restart_squid.sh
crontab -e
*/10 * * * * root /root/restart_squid.sh

本文出自 “聆听未来” 博客,请务必保留此出处http://blog.chinaunix.net/space.php?uid=9419692&do=blog&id=3184076

阅读(600) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~