限制 Apache日志文件大小的方法
更新時間:2009年04月28日 20:23:53 作者:
access.log,件在 WEB 服務器運行一段時間之后會達到幾十兆甚至上百兆,如果Apache運行有錯誤,error.log也會增大到幾十兆,我們知道系統(tǒng)讀寫一個大的文本文件是非常耗內(nèi)存的,因此限定日志文件大小十分必要。
通常我們是在{$apache}/conf/httpd.conf中設置Apache的參數(shù),然而我們并沒有發(fā)現(xiàn)可以設置日志文件大小的配置指令,通過參考http://httpd.apache.org/docs/2.0/programs/rotatelogs.html,可以用apache 自己的程序 rotatelogs.exe(位于 {$apache}/bin/目錄下),來限制日志文件的大小。
Usage: rotatelogs [-l] [offset minutes from UTC] or
Add this:
TransferLog "|rotatelogs /some/where 86400"
or
TransferLog "|rotatelogs /some/where 5M"
to httpd.conf. The generated name will be /some/where.nnnn where nnnn is the system time at which the log nominally starts (N.B. if using a rotation time, the time will always be a multiple of the rotation time, so you can synchronizecron scripts with it). At the end of each rotation time or when the file size is reached a new log is started.
在 Windows 下的設置例子如下:
# 限制錯誤日志文件為 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
linux/Unix下 應該類似。
Usage: rotatelogs [-l] [offset minutes from UTC] or
Add this:
TransferLog "|rotatelogs /some/where 86400"
or
TransferLog "|rotatelogs /some/where 5M"
to httpd.conf. The generated name will be /some/where.nnnn where nnnn is the system time at which the log nominally starts (N.B. if using a rotation time, the time will always be a multiple of the rotation time, so you can synchronizecron scripts with it). At the end of each rotation time or when the file size is reached a new log is started.
在 Windows 下的設置例子如下:
# 限制錯誤日志文件為 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
linux/Unix下 應該類似。
相關(guān)文章
Ubuntu Server 14.04升級Ubuntu Server 16.04
這篇文章主要介紹了 Ubuntu Server 14.04升級Ubuntu Server 16.04,具有一定的參考價值,感興趣的小伙伴們可以參考一下。2016-12-12
CentOS 5.11服務器安裝配置LAMP服務器(Apache+PHP5+MySQL)
這篇文章主要介紹了CentOS 5.11服務器安裝配置LAMP服務器(Apache+PHP5+MySQL),需要的朋友可以參考下2016-10-10
淺析Linux中使用nohup及screen運行后臺任務的示例和區(qū)別
這篇文章主要介紹了Linux中使用nohup及screen運行后臺任務的示例和區(qū)別,本文給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-07-07
在CentOS7上搭建Jenkins+Maven+Git持續(xù)集成環(huán)境的方法
這篇文章主要介紹了在CentOS7上搭建Jenkins+Maven+Git持續(xù)集成環(huán)境的方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2019-01-01
VMware Workstation Pro下CentOS 7 64位服務器安裝教程
這篇文章主要介紹了VMware Workstation Pro下CentOS 7 64位服務器安裝教程,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-08-08

