旋转Apache日志文件的最佳方式

时间:2023-01-12 23:44:25

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的软件或模块可以使我的访问文件的每日副本更易于管理?

7 个解决方案

#1


45  

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%。

#2


26  

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简单(根据我的经验)。

#3


11  

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路径更改为已安装Apache的相关目录。

#4


6  

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

logrotate可能是最佳解决方案。使用文件的/ etc / logrotate。改变所有日志的设置。你可以把“周”改为“日”,这样日志就可以每天轮换。另外,您可能需要添加“compress”,以便压缩归档文件。如果你不关心旧的日志,你可以将“rotate 4”设置为更低的值。

#5


3  

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

自定义日志“|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。

#6


1  

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.

rotatelog。exe或cronolog。exe在windows操作系统。它们在http中的管道命令中使用。conf Mod_log_rotate附加模块只用于访问日志旋转,只用于unix操作系统。

#7


0  

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模块集合中,但这似乎已经中断了一段时间。

#1


45  

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%。

#2


26  

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简单(根据我的经验)。

#3


11  

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路径更改为已安装Apache的相关目录。

#4


6  

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

logrotate可能是最佳解决方案。使用文件的/ etc / logrotate。改变所有日志的设置。你可以把“周”改为“日”,这样日志就可以每天轮换。另外,您可能需要添加“compress”,以便压缩归档文件。如果你不关心旧的日志,你可以将“rotate 4”设置为更低的值。

#5


3  

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

自定义日志“|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。

#6


1  

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.

rotatelog。exe或cronolog。exe在windows操作系统。它们在http中的管道命令中使用。conf Mod_log_rotate附加模块只用于访问日志旋转,只用于unix操作系统。

#7


0  

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模块集合中,但这似乎已经中断了一段时间。