【问题标题】:Disable apache2 log禁用 apache2 日志
【发布时间】:2012-06-03 09:48:49
【问题描述】:

我的服务器上只有 32GB,而日志正在迅速耗尽该空间。所以我想禁用日志。

我想我找到了做这件事的地方,但是由于我在服务器方面完全是个菜鸟,所以我不想在不确定它们不会导致服务器崩溃的情况下开始更改。

在 etc/apache2/apache2.conf 中,我发现了这个:

    #
# The following directives define some format nicknames for use with
# a CustomLog directive (see below).
# If you are behind a reverse proxy, you might want to change %h into %{X-Forwarded-For}i
#
LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

在 etc/apache2/conf.d/other-vhost-access-log 中,我发现了这个:

# Define an access log for VirtualHosts that don't define their own logfile
CustomLog ${APACHE_LOG_DIR}/other_vhosts_access.log vhost_combined

我需要做什么来禁用日志?

提前致谢

【问题讨论】:

  • 添加日志轮换到系统

标签: php apache apache2 debian


【解决方案1】:

这里接受的答案是错误的。注释掉该行不会禁用错误日志,它只是将其恢复为 apache2 默认值。来自apache2ErrorLog documentation:

默认值:ErrorLog logs/error_log (Unix) ErrorLog logs/error.log(Windows 和 OS/2)

换句话说,这将位于 apache 安装根“logs”目录中的某个位置。

要禁用,我认为您需要在不支持日志记录的情况下重新编译(甚至不确定是否可能),或者将 ErrorLog 传递到 /dev/null:

错误日志“|/dev/null”

【讨论】:

  • 这是正确的答案,你肯定会填满你的磁盘空间——就像我们刚刚所做的那样,通过注释掉并重新启动 apache。
【解决方案2】:

如果您真的想禁用日志,则必须注释掉 Apache 配置文件中的任何 ErrorLog 和 CustomLog 指令。在 Debian 上,这些将位于 /etc/apache2/httpd.conf 和 /etc/apache2/apache2.conf(基本配置)和 /etc/apache2/sites-available/*(特定虚拟主机配置)中。

您可以通过在它们前面添加一个“#”字符来将它们注释掉。

更改完成后,运行/etc/init.d/apache2 restart 以使更改生效。

IMO,一个更好的解决方案 - 因为日志通常非常方便 - 是按照 Sergey 上面的建议安装日志轮换。在 Debian 中,运行:

 sudo apt-get install logrotate

在默认配置下,logrotate 将每天拆分日志并压缩旧日志,从而节省大量磁盘空间,同时保留日志本身。

【讨论】:

  • 感谢您的建议...我可以运行上面的脚本,它会工作,还是需要配置一些文件?
  • 对于 logrotate,只需运行上面的命令。 Debian 软件包会自动使用默认设置配置 logrotate,它将每天循环并压缩旧日志。如有必要,您可以使用 /etc/logrotate.conf 中的配置,我相信 Debian 软件包会将特定于应用程序的 logrotate 配置放置在 /etc/logrotate.d 中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-10-02
  • 1970-01-01
  • 2016-05-05
  • 2018-11-02
  • 1970-01-01
  • 2021-06-27
  • 1970-01-01
相关资源
最近更新 更多