今天上午9点的时候收到报警邮件,提示网站502bad gateway,

未命名

输入网站url后果然无法打开:

未命名

登录服务器查看nginx进程正常:

p_w_picpath

查看fastcGI进程已经停止运行了:

p_w_picpath

问题找到后就该查找是什么原因产生的问题,先把fastcGI进程启动后网站能够访问了再细找原因。

查看php日志 tail –n 1000 /usr/local/php/logs/php-fpm.log

 p_w_picpath

找到报警时间点时的日志信息,其中高亮部分为问题所在,提示系统最大文件数为1024,而当前打开的文件数为1024,查看php-fpm.conf:

<value name="rlimit_files">65535</value>

所以是系统文件打开数成为了瓶颈,导致php打开文件数达到了系统默认的最大值而停止进程。

那么就增大系统文件数吧

#ulimit –HSn 65535

#echo ‘ulimit –HSn 65535’ &gt;&gt;/etc/profile

#echo ‘ulimit –HSn 65535’ &gt;&gt;/etc/rc.local

# vim /etc/security/limits.conf

* soft nofile 65535
* hard nofile 65535

对于能够重启系统的服务器最好进行重新启动,以便更改的参数全局生效。

顺便监控php并能够自动重启的脚本:

#cat /usr/local/bin/fastcgi_monitor.sh

#!/bin/sh
#xxx监控
#!/bin/bash
STATE=`curl --head http://sns.xxx.net | awk 'NR==1' | awk '{print $2}'`
if [ "$STATE" -eq "502" ]; then
        /etc/init.d/fastcgi restart

echo "FastCGI 已重启" | mutt  -s "x.x.x.x网站服务器FastCGI 已重启"  zhaohh@xxx.com
elif [ "$STATE" -ne "502" ] && [ "$STATE" -ne "200" ]; then
        /etc/init.d/nginx restart
        /etc/init.d/fastcgi restart

echo "FastCGI和Nginx 已重启" | mutt  -s "x.x.x.x网站服务器FastCGI 和Nginx已重启"  zhaohh@xxx.com

fi

*/10 * * * * sh /usr/local/bin/fastcgi_monitor.sh &gt;/tmp/fastcgi_monitor.log 2&gt;&1 &