由Apache 500錯誤引出的臨時文件問題分析解決
2015-11-04 15:40:54
12498
查看apache日志,發覺是mod_fcgid模塊異常,提示"Connection reset by peer:mod_fcgid:error reading data from FastCGI server"、"Premature end of script headers:index.php"、"process /usr/... apache/cgi-bin exit(communication error, get unexpected signal 7",說白了就是php提前終止執行,沒有返回header就退出。
我依據這些錯誤在網上搜索了很久,始終沒有找到滿意答案,甚至還被人誤導,以為mod_fcgid模塊配置的問題。在沒有找到解決方法之前,我一直在想,php最近雖然慢了點,但至少能運行,說明配置是沒有問題;而且,如果現在執行phpinfo(),程序依然能夠執行。我再次梳理出錯規律,發覺include多的mvc框架就會提示500內部錯誤。其它簡單的程序就能夠運行。這說明什么?說明php已經不能include文件了,為什么?只能是請求這些資源時動了臨時文件,而臨時文件沒有多余空間了。
運行
df -h
發覺果然如此
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 6.8G 6.5G 17M 100% /
系統主目錄/下已經爆掉了。于是,查找大文件
find / -type f -size +300M
發覺php插件Xdebug產生了很多性能分析文件,而且都是以100M記。
/tmp/profiler/cachegrind.out.1336
/tmp/profiler/cachegrind.out.1329
于是修改php.ini,將分析文件存放在其它地方,或者
# close xdebug profiler in php.ini
xdebug.profiler_enable = off
再刪除xdebug性能分析目錄和php var跟蹤目錄
rm -rf /tmp/profilter
rm -rf /tmp/trace
再次查看硬盤情況,發覺已使用為26%,剩余4.9G。
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 6.8G 1.7G 4.9M 26% /
甚至不用重啟httpd服務器,刷新web,又正常運行了!!!
為免除后患,我們需要安裝一個定時清理軟件--tmpwatch,設置/etc/cron.daily/tmpwatch配置里面的定時時間
usr/sbin/tmpwatch"$flags"30d/var/tmp
改為7d(必須以天為單位)
usr/sbin/tmpwatch"$flags"7d/var/tmp
一個星期定時清理一次。