#!/bin/sh
# crontab: */3 * * * * /www/wdlinux/tools/loadavg_restart_apache.sh >> /var/log/restart_apache.log
/usr/sbin/ntpdate cn.pool.ntp.org >> /var/log/upClock.log 2>&1 && /sbin/hwclock -w
sync
sync
echo 3 > /proc/sys/vm/drop_caches
TOP_SYS_LOAD_NUM=5
SYS_LOAD_NUM=`uptime | awk '{print $(NF-2)}' | sed 's/,//'`
echo $(date +"%y-%m-%d") `uptime`
if [ `echo "$TOP_SYS_LOAD_NUM < $SYS_LOAD_NUM"|bc` -eq 1 ]
then
sync
echo "#0#" $(date +"%y-%m-%d %H:%M:%S") "pkill httpd" `ps -ef | grep httpd | wc -l`
echo "#0#" $(date +"%y-%m-%d %H:%M:%S") "pkill mysqld" `ps -ef | grep mysqld | wc -l`
service httpd stop
service mysqld stop
sleep 8
pkill httpd
pkill mysqld
sleep 8
for i in 1 2 3
do
if [ `pgrep mysqld | wc -l` -le 0 ]
then
/sbin/service mysqld start
sleep 30
echo "#1#" $(date +"%y-%m-%d %H:%M:%S") "start mysqld" `ps -ef | grep mysqld | wc -l`
fi
if [ `pgrep httpd | wc -l` -le 0 ]
then
service httpd start
service wdapache start
sleep 30
echo "#1#" $(date +"%y-%m-%d %H:%M:%S") "start httpd" `ps -ef | grep httpd | wc -l`
fi
done
else
if [ `pgrep mysqld | wc -l` -le 0 ]
then
/sbin/service mysqld start
sleep 30
echo "#2#" $(date +"%y-%m-%d %H:%M:%S") "start mysqld" `ps -ef | grep mysqld | wc -l`
fi
if [ `pgrep httpd | wc -l` -le 0 ]
then
service httpd start
service wdapache start
sleep 30
echo "#2#" $(date +"%y-%m-%d %H:%M:%S") "start httpd" `ps -ef | grep httpd | wc -l`
fi
fi
将以上文件,保存在 /www/wdlinux/tools/loadavg_restart_apa_my.sh
然后在
crontab -e
添加
*/3 * * * * /www/wdlinux/tools/loadavg_restart_apa_my.sh >> /var/log/restart_apa_my.log
*/3 ***** 表示3分钟,/www/wdlinux/tools/loadavg_restart_apa_my 你可以自定义。
下面是新数据网络整理的简洁教程
可以ssh登陆之后切换 /www/wdlinux/tools/ 目录
运行下载 wget http://soft.sindns.net/linux/loadavg_restart_apa_my.sh
然后etc里面 找到crontab
最后一行加入 */3 * * * * /www/wdlinux/tools/loadavg_restart_apa_my.sh >> /var/log/restart_apa_my.log
保存即可