報錯問題一般如下兩點
1、php-fpm相關配置問題
2、資源耗盡問題
在此
編寫如下腳本進行巡檢,當有問題自動檢查并重新開機php-fpm假死狀态釋放資源
# vim php-fpm_restart.sh
#!/bin/sh
#變量初始化
process="php-fpm"
startservice="systemctl start php-fpm.service"
down=0
#判斷語句
while true
do
#擷取http狀态碼
code=$(curl -H "Host:www.jiangjj.com" -m 5 -L -s -w %{http_code} http://127.0.0.1 -o /dev/null)
#判斷狀态碼傳回000或大于等于500時,計數故障到down變量
if [ $code -eq 000 -o $code -ge 500 ];then
((down++));
else
break
fi
#等待5s
sleep 5
#判斷是否檢查三次都标記為故障
if [ $down -ge 3 ];then
if [ "$(find /tmp/${process}_restart -mmin -3)" == ""];then
#擷取程序名對應的所有pid
pids=$(ps -aux | grep ${process} | grep -v "grep" | awk '{print $2}')
#依次對所有pid執行kill指令
for jiangjj in $pids;do
kill -9 $jiangjj
kill -9 $jiangjj
done
#kill完pid後啟動服務
$startservice
echo "$(date) Return code $code,${process} had been restarted" >> /tmp/${process}_restart
else
echo "$(date) ${process} not yet recobery,As it hsd been restarted in 2 minutes.so this time ignore."
fi
break
fi
done
#授權
# chmod u+x php-fpm_restart.sh
#執行crontab定時任務即可