要清理 CentOS 上的 Apache 日志,请按照以下步骤操作:
首先,确保你有 root 权限或者可以使用 sudo 命令。
打开终端。
Apache 的日志文件通常位于 /var/log/httpd/ 目录下。你可以使用以下命令查看该目录下的所有日志文件:
ls /var/log/httpd/
du -sh /var/log/httpd/access_log
du -sh /var/log/httpd/error_log
truncate 命令将日志文件大小截断为 0 字节。这将删除日志文件中的所有内容。请谨慎操作,因为这将永久删除日志数据。sudo truncate -s 0 /var/log/httpd/access_log
sudo truncate -s 0 /var/log/httpd/error_log
crontab -e
/var/log/httpd/ 替换为实际的日志文件路径。0 1 * * * /usr/bin/truncate -s 0 /var/log/httpd/access_log && /usr/bin/truncate -s 0 /var/log/httpd/error_log
注意:定期清理日志文件可能会导致在出现问题时无法追踪错误。因此,建议至少每周手动检查一次日志文件,以确保服务器正常运行。