前言
Windows服務器下部署Wamp環境作爲PHP訪問環境,在出現50人左右共同訪問時,出現訪問速度過慢問題,網上查閱資料發現是由於日誌文件過大導致。查看日誌文件發現已有30M以上,移除日誌文件,發現速度迴歸正常。查閱資料修改Apache配置,已使這種情況不在發生。
解決步驟如下
windows下刪除apache_access.log和error.log文件,刪除C:\wamp\logs目錄下的apache_access.log和access.log文件
打開Apache的httpd.conf配置文件並找到下面兩條配置
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 級別的設置,這樣只記錄致命級別以上的日誌,有效減少日誌數量。