access_log很大,没有被归档。如何重置它?
我发现我的access_log 占用了我的大部分硬盘。它的大小超过 200 GB。我怎样才能重置它?
我在 CentOS 服务器上使用 Apache 2.2.3 和 Plesk。
谢谢你们!
I have discovered that my access_log is occupying most of my HDD. It's over 200 GB in size. How can I reset it ?
I am using Apache 2.2.3 on a CentOS server with Plesk.
Thank you guys !
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(8)
knx'答案很好,但我建议重命名日志,并创建一个新日志,这样您就可以重新启动apache,而无需等待访问日志被压缩,如果它很大,这可能需要一段时间。
需要访问 ssh
首先,重命名当前日志文件:
其次,创建一个新的日志文件并给予与原始日志文件相同的权限、所有者/组和 selinux 上下文:(
可能需要 root 才能执行此操作)
接下来,重新启动 apache
然后对旧文件进行 Gzip 压缩(文本文件压缩率非常好)。如果我们假设该文件名为
/var/log/apache/access.log
,那么请执行以下操作:这 4 点是 logrotate 自动执行的操作。
knx'answer is good, but I would suggest to rename the log, and create a new one, so that you can restart apache without waiting for the access log to be compressed, which can take a while if it's big.
needs access to ssh
First, rename the current log file:
Second, create a new log file and give the same permissions, owner/group and selinux context as the original one:
(probably need to be root to do that)
Next, restart apache
Then Gzip the old file (text files compression ratios are really good). If we assume the file is named
/var/log/apache/access.log
then do this:these 4 points are what logrotate do automatically.
如果您可以通过 SSH 访问服务器,那么您可以:
1) Gzip 旧文件(文本文件压缩率非常好)。如果我们假设该文件名为 /var/log/apache/access.log ,则执行以下操作:
gzip -c /var/log/apache/access.log > /var/log/apache/access.log.gz
2) 清除当前文件
echo > /var/log/apache/access.log
3) 重新启动 apache
同样,正如 Dez 建议的那样,考虑使用 logrotate 进行生产级 apache 日志归档。
If you have access by SSH to the server, then you can:
1) Gzip the old file (text files compression ratios are really good). If we assume the file is named /var/log/apache/access.log then do this:
gzip -c /var/log/apache/access.log > /var/log/apache/access.log.gz
2) Clear the current file
echo > /var/log/apache/access.log
3) Restart apache
Also as Dez has suggested consider using logrotate for production grade apache log archiving.
使用 logrotate 守护进程来干净地维护您的日志,特别是与 apache 相关的日志。
关于 logrotate 的简要信息:http://www.scriptinstallation.in/logrotate.html
Use the logrotate daemon in order to have a clean maintenance of your logs, specially, the apache related logs.
A brief info about logrotate: http://www.scriptinstallation.in/logrotate.html
如果在 Ubuntu 上这样做:
当创建访问日志时,它也会神奇地启动错误日志。
If on Ubuntu do:
When creating that access log it magically starts the error log too.
我知道这篇文章已经很老了,但我遇到了同样的问题,没有答案正确地涵盖它。
重点是 apache 根据其配置将文件创建为
access_log
。但是,logrotate 仅查找*.log
,因此名称与搜索模式不匹配。解决方案:要么将
*_log
添加到 logrotate 配置中,要么更改 apache 配置以使其创建名为access.log
的日志文件。更改 apache 配置需要重新加载 apache。I know this post is ages old, but I just had same problem and no answer covers it correctly.
The point is the apache creates the file as
access_log
, according to its configuration. However, logrotate only looks for*.log
, hence the name does not match the search pattern.Solutions: Either you add
*_log
to logrotate configuration, or change the apache configuration to make it create the log file namedaccess.log
. Changing apache configuration requires apache reload.一种简单的解决方案是禁用 access_log,仅注释配置文件中的一行。
来源: https ://www.mydigitallife.info/how-to-disable-and-turn-off-apache-httpd-access-and-error-log/
对于 Plesk 用户:
https://stackoverflow.com/a/41000240/1792240
A simple solution is to disable access_log, commenting only one line on the configuration file.
Source: https://www.mydigitallife.info/how-to-disable-and-turn-off-apache-httpd-access-and-error-log/
For Plesk users:
https://stackoverflow.com/a/41000240/1792240
重命名该文件,创建新的 access_log,然后重新启动 Apache。
Rename the file, create a new access_log, then restart Apache.
将文件重命名为不同的文件名,并创建名为 access_log 的新文件并重新启动 apache(否则 apache 会保持对文件的锁定并且不会“看到”文件更改)
Rename the file to different filename and create new file with the name access_log and restart apache (otherwise apache keeps the lock on the file and don't "see" the file change)