centos7下,解決Apache錯誤日志文件過大問題


1,日志文件太大問題
 
第一步:停止Apache服務的所有進程,刪除 /var/log/httpd目錄下的 error.log、access.log文件
第二步:打開 /etc/httpd/conf 的 httpd.conf配置文件
並找到下面配置
ErrorLog logs/error.log
把上面的注釋掉,換成
# 每天生成一個錯誤日志文件
ErrorLog "|/usr/sbin/rotatelogs /var/log/httpd/error_log%Y%m%d.log 86400 480"
或者
# 限制錯誤日志文件為 1M
ErrorLog "|/usr/sbin/rotatelogs /var/log/httpd/error_log%Y%m%d.log 1M"
找到下面配置
CustomLog logs/access.log combined
把上面的注釋掉,換成
# 每天生成一個訪問日志文件
CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/access_log%Y%m%d.log 86400 480" common
或者
# 限制訪問日志文件為 1M
CustomLog "|/usr/sbin/rotatelogs /var/log/httpd/access_log%Y%m%d.log 1M" common
 
2、為了防止頻繁寫入一些不重要的錯誤日志,提高系統性能,最好還要設置一下錯誤日志級別
找到httpd.conf配置文件下
# LogLevel: Control the number of messages logged to the error_log. 
# Possible values include: debug, info, notice, warn, error, crit, 
# alert, emerg. 
LogLevel warn 
其中LogLevel用於調整記於錯誤日志中的信息的詳細程度。(參閱ErrorLog指令)。可以選擇下列級別,依照重要性降序排列:
Level Description Example  
emerg 緊急 - 系統無法使用。 "Child cannot open lock file. Exiting"  
alert 必須立即采取措施。 "getpwuid: couldn't determine user name from uid"  
crit 致命情況。 "socket: Failed to get a socket, exiting child"  
error 錯誤情況。 "Premature end of script headers"  
warn 警告情況。 "child process 1234 did not exit, sending another SIGHUP"  
notice 一般重要情況。 "httpd: caught SIGBUS, attempting to dump core in ..."  
info 普通信息。 "Server seems busy, (you may need to increase StartServers, or Min/MaxSpareServers)..."  
debug 出錯級別信息 "Opening config file ..."  
默認級別是warn,那么warn級別以上的日志都會記錄,會產生大量“文件不存在”的erro級別的錯誤日志。建議使用 crit 級別的設置,這樣只記錄致命級別以上的日志,有效減少日志數量。 把LogLevel warn更改為LogLevel crit  然后重啟apache即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM