技术交流QQ群:①185473046   ②190706903   ③203744115   网站地图
登录

下次自动登录
现在的位置: 首页LNMP>正文
VPS小内存LNMP服务器Nginx 502 Bad Gateway故障一分钟内自动恢复解决办法
2013年08月17日 LNMP 暂无评论 ⁄ 被围观 17,782次+

遇到问题:

VPS小内存LNMP服务器,网站访问量偶尔突然增加,会导致php进程卡死,出现Nginx 502 Bad Gateway故障,

这个时候只要重启php进程,网站马上恢复正常。

解决办法:

在不增加硬件投入的情况下,当网站出现Nginx 502 Bad Gateway故障时,在1分钟内让php进程自动重启,

从而解决问题。

具体步骤:

说明:

php进程启动命令:service php-fpm start

php进程服务名:php-cgi     #php 5.3以上版本中进程服务名为:php-fpm

/home/wwwlogs/502  #判断php进程是否卡死中间过程文件

/home/wwwlogs/502_error.log  #php进程重启日志记录文件

/home/php-restart.sh  #脚本文件

1、nano  /home/php-restart.sh   #编辑输入以下代码

系统运维  www.osyunwei.com  温馨提醒:qihang01原创内容 版权所有,转载请注明出处及原文链接

#!/bin/sh

if [ -e /home/wwwlogs/502 ]
then
    killall -9 curl 2>/dev/null
    killall -9 php-cgi 2>/dev/null
    service php-fpm start >/dev/null

    echo "[ `date +'%D %T %A'` ] PHP-FPM died with no response, all processes restarted">>/home/wwwlogs/502_error.log
else
    touch  /home/wwwlogs/502
    if [ `curl --connect-timeout 5 -I http://www.osyunwei.com/ 2>/dev/null | grep '502 Bad Gateway' -c` != '0' ]
    then
        killall -9 php-cgi 2>/dev/null
        service php-fpm start >/dev/null
        echo  "[ `date +'%D %T %A'` ] PHP-FPM died with 502 bad gateway, all processes

restarted">>/home/wwwlogs/502_error.log
    fi
    rm -rf /home/wwwlogs/502
fi

ctrl+o   #保存配置

ctrl+x   #退出

2、chmod +x  /home/php-restart.sh   #添加脚本执行权限

3、修改/etc/crontab

nano /etc/crontab   #在下面添加

*/1 * * * * root  /home/php-restart.sh   #表示每分钟执行一次脚本

4、重新启动crond使设置生效

service cron stop  #停止

service cron start #启动

/etc/init.d/cron restart #重启

chkconfig cron on #设为开机启动  先要安装chkconfig(apt-get install chkconfig)

至此,VPS小内存LNMP服务器Nginx 502 Bad Gateway故障一分钟内自动恢复解决办法教程完成

     

  系统运维技术交流QQ群:①185473046 系统运维技术交流□Ⅰ ②190706903 系统运维技术交流™Ⅱ ③203744115 系统运维技术交流™Ⅲ

给我留言

您必须 [ 登录 ] 才能发表留言!



Copyright© 2011-2024 系统运维 All rights reserved
版权声明:本站所有文章均为作者原创内容,如需转载,请注明出处及原文链接
陕ICP备11001040号-3