轮换 Apache 日志文件的最佳方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/44048/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 16:43:01  来源:igfitidea点击:

Best way to rotate Apache log files

apacheloggingwebserverapache2apache2.4

提问by Scott Gottreu

I've got an Apache server that has one access log file that is topping 600MB. This makes it really hard to search the file or parse it.
What software or modules for Apache are available that will make a daily copy of my access file to make it more manageable?

我有一个 Apache 服务器,它有一个超过 600MB 的访问日志文件。这使得搜索文件或解析文件变得非常困难。
有哪些适用于 Apache 的软件或模块可以制作我的访问文件的每日副本以使其更易于管理?

采纳答案by serg10

Have you looked at logrotate- this is probably the simplest, most widely available and well understood method of achieving this. It is highly configurable and will probably do 90% of what you need.

您是否看过logrotate- 这可能是实现此目的的最简单、最广泛可用且易于理解的方法。它是高度可配置的,可能会完成您需要的 90%。

回答by Brian

I'm a big fan of Cronolog. Just install and pipe your logs through it. For daily log rotation, something like this would work:

我是Cronolog 的忠实粉丝。只需通过它安装和管理您的日志。对于每日日志轮换,这样的事情会起作用:

ErrorLog  "|/usr/bin/cronolog /path/to/logs/%Y-%m-%d/error.log"
CustomLog "|/usr/bin/cronolog /path/to/logs/%Y-%m-%d/access.log" combined

Pretty handy, and once installed, easier (in my experience) than logrotate.

非常方便,一旦安装,比 logrotate 更容易(以我的经验)。

回答by alimack

The actual command for Windows, which is quite difficult to find online is:

Windows 的实际命令,在网上很难找到,是:

CustomLog '|" "*Apache-Path/bin/rotatelogs.exe" 
    "**Apache-Path*/logs/backup/internet_access_%d-%m-%y.log" 86400' combined

Where the "internet_access" bit is the name you choose for your files, the 86400 is the number of seconds in one day. You need to change the Apache-Path to the relevant directory you've installed Apache to.

其中“internet_access”位是您为文件选择的名称,86400 是一天中的秒数。您需要将 Apache-Path 更改为您已将 Apache 安装到的相关目录。

回答by Eric Hogue

logrotate

对数旋转

logrotateis probably the best solution. Use the file /etc/logrotate.confto change the settings for all your logs. You van change weeklyto dailyso the logs are rotated every day. Also, you might want to add compressso the archives are compressed. If you don't care about the old logs, you can set rotate rotate 4to something lower.

logrotate可能是最好的解决方案。使用该文件/etc/logrotate.conf更改所有日志的设置。您更改weeklydaily这样日志每天轮换。此外,您可能想要添加compress以便压缩存档。如果您不关心旧日志,则可以将旋转设置rotate 4为较低的值。

回答by Bipin

CustomLog "|bin/rotatelogs /var/logs/logfile 5M" common

CustomLog "|bin/rotatelogs /var/logs/logfile 5M" 常用

This configuration will rotate the logfile whenever it reaches a size of 5 megabytes.

当日志文件达到 5 兆字节时,此配置将轮换日志文件。

ErrorLog "|bin/rotatelogs /var/logs/errorlog.%Y-%m-%d-%H_%M_%S 5M" 

This Would Be Best Way to Redirect Apache logs. No need to compile mod with httpd.

这将是重定向 Apache 日志的最佳方式。无需使用 httpd 编译 mod。

回答by fabien

rotatelog.exe or cronolog.exe on windows os. They are used in pipe command in http.conf Mod_log_rotate additional module for apache ONLY for access log rotation Logrotate ONLY for unix os.

windows 操作系统上的rotatelog.exe 或cronolog.exe。它们在 http.conf 中的管道命令中使用 Mod_log_rotate 附加模块,用于 apache 仅用于访问日志轮换 Logrotate 仅用于 unix 操作系统。

回答by Jake Scott

I have a module that does this for you without the need for external pipes etc :

我有一个模块可以为您完成此操作,而无需外部管道等:

http://www.poptart.org/bin/view/Poptart/ModAutorotate

http://www.poptart.org/bin/view/Poptart/ModAutorotate

I've tried to add it to the Apache modules collection but that seems to have been broken for a while now.

我试图将它添加到 Apache 模块集合中,但现在似乎已经被破坏了一段时间。