快捷搜索:   nginx

APACHE和MYSQL高负载状态自动重启服务的脚本

脚本是判断进程数,超过一定数值自动重启,也就是设置
MaxApacheThread=300
MaxMysqlThread=250
这个根据自己服务器配置修改

脚本用法可以参考同类:https://www.bnxb.com/shell/27318.html



#!/bin/bash
#check apache,mysql thread and auto reboot
#config
MaxApacheThread=300
MaxMysqlThread=250
NeedReboot=0
ApacheThread=`ps -A|grep http|wc -l`
MysqlThread=`ps -A|grep mysql|wc -l`
if [ $ApacheThread -gt $MaxApacheThread ]
then
NeedReboot=1
/usr/sbin/apachectl stop
sleep 8
pkill httpd  
sleep 8  
/usr/sbin/apachectl start 
fi
if [ $MysqlThread -gt $MaxMysqlThread ]
then
NeedReboot=2
/etc/init.d/mysqld stop
sleep 8
/etc/init.d/mysqld start
fi
if [ $NeedReboot -eq 1 ]
then
echo $(date +"%y-%m-%d %H:%M:%S") "Apache:$ApacheThread;Mysql:$MysqlThread.;Apache is busy,reboot"
fi
if [ $NeedReboot -eq 2 ]
then
echo $(date +"%y-%m-%d %H:%M:%S") "Apache:$ApacheThread;Mysql:$MysqlThread.;Mysql is busy,reboot"
else
echo $(date +"%y-%m-%d %H:%M:%S") "Apache:$ApacheThread;Mysql:$MysqlThread.;System is normal"
fi


顶(2)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论