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
 
二、爲了防止頻繁寫入一些不重要的錯誤日誌,提升系統性能,最好還要設置一下錯誤日誌級別
找到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便可。
相關文章
相關標籤/搜索