由于Nginx的出色表现,越来越多的web服务器采用Nginx。虽然nginx很棒,但万一挂了呢?我们最好写个小脚本来监控。如果nginx挂了,系统自动重启。
当然,在给出脚本之前,先做几个假设,nginx的目录是/usr/local/nginx/,其pid conf 分别为在相应默认目录之下。实例脚本如下:
[plain]
- #! /bin/bash
- pidFile=/usr/local/nginx/logs/nginx.pid
- nginxBin=/usr/local/nginx/sbin/nginx
- confFile=/usr/local/nginx/conf/nginx.conf
- if [ ! -f $pidFile ]; then
- $nginxBin -c $confFile
- fi
- * * * * * sleep 5; /bin/bash /root/.bin/webmonitor.sh > /dev/null
通过上面的操作,该监控脚本基本可以运行了。当然你也可以继续拓展,怎么监控php之类的
crontab的详细用法,可以参阅:crontab命令小结 见 http://www.linuxidc.com/Linux/2012-02/52985.htm
