標籤: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’ >>/etc/profile
#echo ‘ulimit –HSn 65535’ >>/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 >/tmp/fastcgi_monitor.log 2>&1 &