CentOS下Apache error.log文件太大的處理
2016-07-23 20:13:15 1820次
清除error.log、access.log并限制Apache日志文件大小的方法
今天有臺linux服務器Mysql突然起不來了,檢查報錯發現是磁盤滿了,可用空間為0KB,進去后發現Apache的錯誤日志error.log非常的大,造成D盤被爆滿。
在網上搜了下相應的資料,并按照如下步驟做了一遍,網站恢復正常
第一步:停止Apache服務的所有進程service httpd stop,刪除 Apache2/logs/目錄下的 error.log、access.log文件
第二步:打開 Apache 的 httpd.conf配置文件并找到下面兩條配置
ErrorLog logs/error.log
CustomLog logs/access.log common
直接注釋掉,換成下面的配置文件。
限制錯誤日志文件為 1M
ErrorLog “|bin/rotatelogs.exe -l logs/error-%Y-%m-%d.log 1M”
每天生成一個錯誤日志文件
ErrorLog “|bin/rotatelogs.exe -l logs/error-%Y-%m-%d.log 86400″
限制訪問日志文件為 1M
CustomLog “|bin/rotatelogs.exe -l logs/access-%Y-%m-%d.log 1M” common
每天生成一個訪問日志文件
CustomLog “|bin/rotatelogs.exe -l logs/access-%Y-%m-%d.log 86400″ common
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指令)??梢赃x擇下列級別,依照重要性降序排列:
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即可。
轉載于:https://www.cnblogs.com/xiao-van/p/6913391.html