网 络 中 心
中心简介
网络技术

友 情 链 接
 
 
Linux

在linux中定时监控apache的运行状态
  日期:2011-12-28     【背景色 杏仁黄 秋叶褐 胭脂红 芥末绿 天蓝 雪青 灰 银河白(默认色) 】  【字体:
 

服务器多了,一直苦于apache经常的死掉,虽说WHM中有监控apache的进程,但反应时间超慢,通常要在死掉10分钟以上才会重启apache,而10分钟可要损失N多刀刀哈,昨天终于从google中找到了个好的解决方案,证明确实有效,有需要的朋友可以拿去用哈!

#!/bin/bash

# Apache Process Monitor

# Restart Apache Web Server When It Goes Down

# -------------------------------------------------------------------------

# Copyright (c) 2003 nixCraft project berciti.biz/fb/>

# This script is licensed under GNU GPL version 2.0 or above

# -------------------------------------------------------------------------

# This script is part of nixCraft shell script http://en.wikipedia.org/wiki/Shell_script collection (NSSC)

# Visit http://bash.cyberciti.biz/ for more information.

# -------------------------------------------------------------------------

# RHEL / CentOS / Fedora http://en.wikipedia.org/wiki/Fedora Linux restart command RESTART="/sbin/service httpd restart"

# uncomment if you are using Debian / Ubuntu Linux

#RESTART="/etc/init.d/apache2 restart"

#path to pgrep command PGREP="/usr/bin/pgrep"

# Httpd daemon name,

# Under RHEL/CentOS/Fedora it is httpd

# Under Debian 4.x it is apache2 HTTPD="httpd"

# find httpd pid $PGREP ${HTTPD} if [ $? -ne 0 ]

# if apache not running then

# restart apache $RESTART fi

用ssh登入到Server,

cd /home

vi restart.sh

复制上面的代码到restart.sh文件

chmod 777 restart.sh

改变文件权限为可执行

进入计划任务,定时运行监控脚本

cd /etc/cron.d

vi sa-update

copy下面的代码到计划任务中

* * * * * root /home/restart.sh >/dev/null 2>&1

如果想看到运行效果,你可以将/dev/null 2>&1 改为/home/restart.txt

保存文件

一分钟后你应该可以在/home文件中看到restart.txt文件了

现在你可以不再为httpd经常死掉而烦恼了。




0.096477031707764