access_log很大,没有被归档。如何重置它?

发布于 2024-09-01 08:52:41 字数 118 浏览 8 评论 0原文

我发现我的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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

慢慢从新开始 2024-09-08 08:52:41

knx'答案很好,但我建议重命名日志,并创建一个新日志,这样您就可以重新启动apache,而无需等待访问日志被压缩,如果它很大,这可能需要一段时间。

需要访问 ssh

首先,重命名当前日志文件:

mv /var/log/apache/access.log /var/log/apache/access.log.1

其次,创建一个新的日志文件并给予与原始日志文件相同的权限、所有者/组和 selinux 上下文:(

touch /var/log/apache/access.log
chown --reference=/var/log/apache/access.log.1 /var/log/apache/access.log
chmod --reference=/var/log/apache/access.log.1 /var/log/apache/access.log
restorecon --reference=/var/log/apache/access.log.1 /var/log/apache/access.log

可能需要 root 才能执行此操作)

接下来,重新启动 apache

然后对旧文件进行 Gzip 压缩(文本文件压缩率非常好)。如果我们假设该文件名为 /var/log/apache/access.log ,那么请执行以下操作:

gzip -c /var/log/apache/access.log.1 > /var/log/apache/access.log.1.gz

这 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:

mv /var/log/apache/access.log /var/log/apache/access.log.1

Second, create a new log file and give the same permissions, owner/group and selinux context as the original one:

touch /var/log/apache/access.log
chown --reference=/var/log/apache/access.log.1 /var/log/apache/access.log
chmod --reference=/var/log/apache/access.log.1 /var/log/apache/access.log
restorecon --reference=/var/log/apache/access.log.1 /var/log/apache/access.log

(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:

gzip -c /var/log/apache/access.log.1 > /var/log/apache/access.log.1.gz

these 4 points are what logrotate do automatically.

暖阳 2024-09-08 08:52:41

如果您可以通过 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.

飘落散花 2024-09-08 08:52:41

使用 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

以歌曲疗慰 2024-09-08 08:52:41

如果在 Ubuntu 上这样做:

sudo su
cd /var/log/apache2
rm access.log
rm error.log
touch access.log

当创建访问日志时,它也会神奇地启动错误日志。

If on Ubuntu do:

sudo su
cd /var/log/apache2
rm access.log
rm error.log
touch access.log

When creating that access log it magically starts the error log too.

油饼 2024-09-08 08:52:41

我知道这篇文章已经很老了,但我遇到了同样的问题,没有答案正确地涵盖它。

重点是 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 named access.log. Changing apache configuration requires apache reload.

2024-09-08 08:52:41

一种简单的解决方案是禁用 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

猥︴琐丶欲为 2024-09-08 08:52:41

重命名该文件,创建新的 access_log,然后重新启动 Apache。

Rename the file, create a new access_log, then restart Apache.

離殇 2024-09-08 08:52:41

将文件重命名为不同的文件名,并创建名为 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)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文