当前位置:web 服务器 > Apache >>

Linux下检测Apache进程数量并自动重启的脚本

在/etc/crontab里,定时执行检测脚本,检测系统的Apache,和Mysql进程是否超出标准,超标的话,自动重启,没有的话,记录进程数据.

  Crontab的内容(每30分钟执行一次,并将结果记录在/var/log/chksys.log)

  0,30 * * * * root /usr/local/chksys.sh >> /var/log/chksys.log

  /usr/local/chksys.sh代码:

  #!/bin/bash

  #check apache,mysql thread and auto reboot system

  #Powered by ipaddr(aspbiz)

  #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

  fi

  if [ $MysqlThread -gt $MaxMysqlThread ]

  then

  NeedReboot=1

  fi

  if [ $NeedReboot -eq 1 ]

  then

  echo "-----------------------------"

  echo $(date +"%y-%m-%d %H:%M:%S")

  echo "-----------------------------"

  echo "Apache:$ApacheThread;Mysql:$MysqlThread."

  echo "System is busy,reboot"

  reboot

  else

  echo "-----------------------------"

  echo $(date +"%y-%m-%d %H:%M:%S")

  echo "-----------------------------"

  echo "Apache:$ApacheThread;Mysql:$MysqlThread."

  echo "System is normal"

  fi本文来自:http://www.xiaoyaxiao.com/1814.html
发表您的高见!
Apache
IIS
Nginx
Tomcat
如果你遇到web 服务器难题:
访问www.zzzyk.com 试试
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,