修改Apache配置日志输出,减轻访问压力,apache日志


前言

Windows服务器下部署Wamp环境作为PHP访问环境,在出现50人左右共同访问时,出现访问速度过慢问题,网上查阅资料发现是由于日志文件过大导致。查看日志文件发现已有30M以上,移除日志文件,发现速度回归正常。查阅资料修改Apache配置,已使这种情况不在发生。

解决步骤如下

ErrorLog "c:/wamp/logs/apache_error.log"  
CustomLog "c:/wamp/logs/access.log" common  

修改为

#ErrorLog "c:/wamp/logs/apache_error.log"  

#限制错误日志文件为 1M  
ErrorLog "|bin/rotatelogs.exe -l c:/wamp/logs/apache_error-%Y-%m-%d.log 1M"  
#每天生成一个错误日志文件  
ErrorLog "|bin/rotatelogs.exe -l c:/wamp/logs/apache_error-%Y-%m-%d.log 86400"  
#CustomLog "c:/wamp/logs/access.log" common 

#限制WEB日志文件为 1M  
CustomLog "|bin/rotatelogs.exe -l c:/wamp/logs/access-%Y-%m-%d.log 1M" common 
#每天生成一个WEB日志文件   
CustomLog "|bin/rotatelogs.exe -l c:/wamp/logs/access-%Y-%m-%d.log 86400" common

检查了一下WEB日志,一般访问一次产生一条记录,觉得无用且频率高,我最后选择了关闭日志输出。

3.修改错误级别

#
# 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   错误情况。“remature 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 级别的设置,这样只记录致命级别以上的日志,有效减少日志数量。

相关内容

    暂无相关文章