今天收到警示郵件,提示網站502 bad gateway,

來源:互聯網
上載者:User

標籤:http   檔案   art   問題   ar   linux   時間   amp   

今天收到警示郵件,提示網站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 已重啟"  [email protected] 
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已重啟"  [email protected]

fi

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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.