[转载]appache的日志和关闭错误日志的方法

对于access.log我只是注销了#log_config_module模块就可以。

对于error.log貌似无论如何禁止不了,那只能通过提高LogLevel来减少错误日志的记录,我写值为crit。

======================================================================

Apache的日志功能

转发 评论
2006-08-23 13:31

门外汉又来献丑了啊~

 因需要将apache的日志功能打开。记得日志功能已经编辑进去了,但怎么打开,怎么关闭,就不是很清楚了啊~不懂啊~就得学。

   看程序都搞定了,我又去看了一下,才了解一下情况。也算有个初步知道吧~

编译apache加入--enable-log-config,完成之后,开启还是关闭日志就可以完全通过httpd.conf来控制了。具体如下

安装完成后,的conf文件关于日志的部分如下:

。。。。。

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
# container, error messages relating to that virtual host will be
# logged here. If you *do* define an error logfile for a <VirtualHost>
# container, that host's errors will be logged there and not here.
#
ErrorLog logs/error_log    #要打开的,错误日志

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel warn

#
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
#
LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined
LogFormat "%h %l %u %t "%r" %>s %b" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

#以上为日志的相关配置文件,具体记录哪些内容,比如"%h"表示访问者的来源ip等。具体可以参考apache2.0中文。

# You need to enable mod_logio.c to use %I and %O
#LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" %I %O" combinedio

#
# The location and format of the access logfile (Common Logfile Format).
# If you do not define any access logfiles within a <VirtualHost>
# container, they will be logged here. Contrariwise, if you *do*
# define per-<VirtualHost> access logfiles, transactions will be
# logged therein and *not* in this file.
#
CustomLog logs/access_log common   #记录日志的保存记录

#
# If you would like to have agent and referer logfiles, uncomment the
# following directives.
#
#CustomLog logs/referer_log referer
#CustomLog logs/agent_log agent

#
# If you prefer a single logfile with access, agent, and referer information
# (Combined Logfile Format) you can use the following directive.
#
#CustomLog logs/access_log combined  #详细保存日志,常用!

。。。。。

主要就是上面的加色的四部分。


全部注了的话,那就没有日志了。把

LogFormat "%h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i"" combined

CustomLog logs/access_log combined

这两项打开,就可以有日志了,且保存在apache目录下的logs文件下面。

有事要闪先了,还有补充

=============================================================

关闭Apache日志记录CustomLog ErrorLog 配置
出处:西西整理 作者:西西 人气:129 次 评论: 0 | 我要发表看法

这两个配置可能在两个地方出现,一个是apache全局的配置文件apache2.conf 或httpd.conf(一般在/etc/apache2/目录下),还有就是虚拟主机vhosts各自的配置文件中(一般在/etc/apache2/sites-enable目录下),其中各个vhosts的配置的优先级高于全局配置

那么如果要完全关闭的话就要在两个配置中都注释掉以 CustomLog 和 ErrorLog 开头的行

如果部分关闭那就在httpd.conf中注释掉,再在需要的vhosts配置文件中增加。

貌似不能全局打开而在特定vhosts中关闭。。。

参考 http://httpd.apache.org/docs/current/mod/mod_log_config.html

=======================================================================

关闭 Apache 的web日志记录

发觉VPS上的空间占用快满了,除了把备份的移到其它服务器以外,还发现Apache的日志增长得也太厉害了。对于我来说,去分析web服务器的请求日志意义不大。所以我决定还是关闭掉。Apache服务器的web日志记录关闭不像IIS那样可以直接在IIS管理器的界面上选择就行了。必须通过Apache的配置文件httpd.conf来进行,不过也蛮简单的。

在httpd.conf文件中,有如下一行,你删除了就不产生日志了。我是注释的方式,如:

#CustomLog “logs/access_log” common #by http://tsov.net/ 2011/8/29

这一行可能因你的配置不同有所修改,不一定完全相同。搜索一下就能定位到。方法就这么简单吧。最后记得要重启web服务(不用重启服务器)才有效。

=====================================================================

apache日志,错误等级,关闭日志
怎么样关闭apache2的日志文件(logfile)?这是个问题,因为写日志会给系统带来很大的损耗。关闭日志以后,甚至最高可以提高整体性能近40%(粗略估计)那么如何关闭日志呢?

可以通过降低log级别的办法来减少日志读写。

这里要提醒的是,这么做将给“***检测”以及其他基于日志分析的工作带来麻烦。所以请谨慎使用。

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 ..."


通常情况建议使用 crit 到 warn 之间的设置

==================================================================

清除并限制Apache日志文件大小的方法 PHP+APACHE日志过大清除




作者:admin 来源:本站原创 点击次数:29278 更新时间:2011-10-11 18:38:32


清除并限制Apache日志文件大小的方法 PHP+APACHE日志过大清除


我建的ECSHOP和SHOPEX还有discuz等程序在一个VSP上,D盘大小是10G,所有的PHP环境都安装在D盘,我的网站经过一年的运营也有一二个G,一直硬盘显示容量余额有7G左右突然有一天我登陆VSP提示D盘不足,查找了所有网页文件没发现那里超出了,最后经过排除把目光注意到了APACHE这个文件夹。

用apache架设PHP环境的朋友经常会遇到这样一个问题,硬盘容量莫明奇妙的少了,进入apache目录的日志目录你会发现有二个文件即以access.log和error.log结尾的文件,注意前面有可能会有你的站点名字,查看这二个文件容量你会发现容量很大,这就是apache的日志文件,遇到这个问题首先是停止apache服务,停止成功后删除这二个文件,删除后打开apache的httpd.conf配置文件,具体详情的修改资料见下面介绍:

下面是在网上搜索到的方法,立马见效,顶一个!

在 Windows 下的设置例子如下:
第一步:首先停止apache服务

第二步:删除 Apache2/logs/目录下的 error.log、access.log文件

第三步:打开 Apache 的 httpd.conf配置文件并找到下面两条配置

ErrorLog logs/error.log
CustomLog logs/access.log common

直接注释掉,换成下面的配置文件。

把#ErrorLog logs/error.log换成以下二行代码;
# 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 logs/access.log common换成以下二行代码
# 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
以面代码的意思是限制访问日志文件为 1M和每天只生成一个访问日志

换好后保存,重启apache即可。

是不是发现容量少了很多啊,呵呵,就这么简单

================================================================

限制Apache日志大小

2011-2-14 19:33:51 浏览次数 733


限制Apache日志文件大小的方法access.log,件在 WEB 服务器运行一段时间之后会达到几十兆甚至上百兆,如果Apache运行有错误,error.log也会增大到几十兆,我们知道系统读写一个大的文本文件是非常耗内存的,因此限定日志文件大小十分必要。

通常我们是在{$apache}/conf/httpd.conf中设置Apache的参数,然而我们并没有发现可以设置日志文件大小的配置指令,通过参考http://httpd.apache.org/docs/2.0/programs/rotatelogs.html ,可以用apache 自己的程序 rotatelogs.exe(位于 {$apache}/bin/目录下),来限制日志文件的大小。

Usage: rotatelogs [-l] <logfile> <rotation time in seconds> [offset minutes from UTC] or <rotation size in megabytes>

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



===============

打开httpd.conf

找到这一行,CustomLog logs/access.log common 替换上面的设置

重启apache服务。ok!

=========================================================================

关闭apache2的错误日志记录文件
因为写日志会给系统带来很大的损耗。关闭日志以后,甚至最高可以提高整体性能近40%(粗略估计)那么如何关闭日志呢?

可以通过降低log级别的办法来减少日志读写。

这里要提醒的是,这么做将给“***检测”以及其他基于日志分析的工作带来麻烦。所以请谨慎使用。
网上相关文章很多,但说的都不详细,擦边而过,下面详细说一下具体操作步骤。

编辑conf文件夹下的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即可。





将Httpd.conf 配置文件中的ErrorLog