freebsd 的 newsyslog.conf 每日日志轮换

ale*_*xus 0 freebsd log-rotation

我正在尝试利用newsyslog.conf -- newsyslog(8) configuration file来轮换我的apache//日志文件nginxsquid

# uname -a
FreeBSD X 9.2-RELEASE-p17 FreeBSD 9.2-RELEASE-p17 #0 r282430: Mon May  4 13:59:58 PDT 2015     root@X:/usr/obj/usr/src/sys/R610  amd64
# tail -1 /etc/newsyslog.conf 
<include> /etc/newsyslog-local.conf
# cat /etc/newsyslog-local.conf 
/var/log/httpd-*.log    root:wheel  644 7   *   @T00    JC  /var/run/httpd.pid
/var/log/nginx-*.log    root:wheel  644 7   *   @T00    JC  /var/run/nginx.pid
/var/log/squid/*.log    squid:squid 640 7   *   @T00    JC  /var/run/squid/squid.pid
# newsyslog 
# echo $?
0
# ll /var/log/httpd-* /var/log/nginx-* /var/log/squid/*log*
-rw-r--r--  1 root   wheel   794179378 Jun 10 12:13 /var/log/httpd-access.log
-rw-r--r--  1 root   wheel   236848603 Jun 10 12:09 /var/log/httpd-error.log
-rw-r--r--  1 root   wheel     3513917 Jun 10 12:09 /var/log/httpd-ssl_request.log
-rw-r--r--  1 root   wheel  1789191504 Jun 10 12:13 /var/log/nginx-access.log
-rw-r--r--  1 root   wheel   165855753 Jun 10 12:13 /var/log/nginx-error.log
-rw-r-----  1 squid  squid     5604675 Jun 10 12:01 /var/log/squid/access.log
-rw-r-----  1 squid  squid       12589 Jun 10 10:47 /var/log/squid/cache.log
# 
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

小智 5

您的配置应如下所示:

/var/log/httpd-*.log    root:wheel  644 7   *   @T00    GBJC  /var/run/httpd.pid 1
/var/log/nginx-*.log    root:wheel  644 7   *   @T00    GBJC  /var/run/nginx.pid 1
/var/log/squid/*.log    squid:squid 640 7   *   @T00    GBJC  /var/run/squid/squid.pid 30
Run Code Online (Sandbox Code Playgroud)
  • G标志表示您的日志文件名是 shell 模式。
  • B标志告诉 newsyslog 不要将日志旋转文本放在新日志文件的顶部。
  • 有关其他标志含义,请参阅newsyslog.conf(5) 。

如果你想对 Squid 使用 newsyslog,需要告诉它不要执行自己的 logrotate(SquidLogs FAQ):

# squid.conf
logfile_rotate 0
Run Code Online (Sandbox Code Playgroud)

您可以使用 来试运行您的配置newsyslog -nvF | less

我的 Squid 配置和空运行命令来源:“Squid logrotation with newsyslog”(Jamesoff.net 博客文章和评论)