Squid 运行一段时间会挂掉的问题处理

现象

squid 运行一段时间后会挂掉,从 access.log 中也没看到什么有用的信息。在 cache.log 和 var/log/messages 中能看到报错:

Apr 19 15:14:17 test squid[49114]: #011/home/squid_cache//00/140/00028086
Apr 19 15:14:17 test squid[49114]: DiskThreadsDiskFile::openDone: (2) No such file or directory
Apr 19 15:14:02 test squid[49114]: #011/home/squid_cache//00/108/000210A4
Apr 19 15:14:02 test squid[49114]: DiskThreadsDiskFile::openDone: (2) No such file or directory
Apr 19 15:14:02 test squid[49114]: #011/home/squid_cache//00/15E/0002BC8B
Apr 19 15:14:02 test squid[49114]: DiskThreadsDiskFile::openDone: (2) No such file or directory
Apr 19 15:14:02 test squid[49114]: #011/home/squid_cache//00/15E/0002BC89
Apr 19 15:14:02 test squid[49114]: DiskThreadsDiskFile::openDone: (2) No such file or directory

分析

还是没找到原因。但看报错是找不到配置的缓存的目录,所以觉得在启动的时候初始化一下缓存目录是不是能解决问题。

临时的解决办法

起一个守护进程,在 squid 挂掉的时候自动拉起,同时初始化缓存目录。脚本如下:

#!/bin/sh
msgip="192.168.1.1"
IP="192.168.1.1"
###`cat /etc/rc.conf | grep -E "ifconfig_[em1|bce1]" | awk '{print "IP:"$2}'| sed -n 1p `
check_squid()
{
rs_flag=`ps uaxww | grep squid|grep -v grep | wc -l`
if [ "$rs_flag" -gt 0 ]
then
        echo 'squid server is running..' >> /root/test.log
        exit;
else
        echo 'squid server is not running...' >> /root/test.log
        /usr/local/squid/sbin/squid -z
                /usr/local/squid/sbin/squid -s
        /usr/bin/logger -p local1.info -t $msgip "the services: $IP squid will to start by watch_squid.sh "
        sleep 1
        check_squid
fi
}
check_squid

然后定时执行,每一分钟执行一次

##squid watch

* * * * * /root/sq-watch.sh
2016-04-19 16:0120