zoukankan      html  css  js  c++  java
  • 今天收到报警邮件,提示网站502 bad gateway,

    今天收到报警邮件,提示网站502 bad gateway,

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

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

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

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

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

    【Linux公社 http://www.linuxidc.com 】

    找到报警时间点时的日志信息,其中高亮部分为问题所在,提示系统最大文件数为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://www.linuxidc.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 &

    linux

  • 相关阅读:
    前端 -- html
    MySQL索引
    Python操作MySQL
    MySQL表操作进阶
    MySQL表操作基础
    Github使用教程
    Android开发面试题
    MYSQL学习记录
    Java开发从零到现在
    JavaWeb(JSP/Servlet/上传/下载/分页/MVC/三层架构/Ajax)
  • 原文地址:https://www.cnblogs.com/upshania/p/3878403.html
Copyright © 2011-2022 走看看