freebsd的newsyslog.conf每日日志旋转

我试图利用newsyslog.conf -- newsyslog(8) configuration file来旋转我的apache / nginx / squid日志文件:

 # 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 # 

我究竟做错了什么?

你的configuration应该如下:

 /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 
  • G标志表示你的日志文件名是一个shell模式。
  • B标志告诉newsyslog不要把日志文件放在新日志文件的顶部。
  • 有关其他标志的含义,请参阅newsyslog.conf(5)

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

 # squid.conf logfile_rotate 0 

您可以使用newsyslog -nvF | less执行configuration的干运行 newsyslog -nvF | less

我的Squidconfiguration和干运行命令的来源: “Squid日志旋转与newsyslog”(Jamesoff.net博客文章和评论) 。

鱿鱼有它自己的日志旋转器:

 #/etc/crontab 18 4 1 * * root /usr/local/sbin/squid -k rotate 

configuration:

 #/usr/local/etc/squid/squid.conf logfile_rotate 10 

Apache应该仔细旋转

 #/etc/newsyslog.conf /var/log/apache/vhosts/*.log 660 5 * $W0D0 CG /var/log/apache/tools/*.log 660 5 * $W0D0 CG /var/log/apache/*.log 660 5 * $W0D0 CG /var/run/httpd.pid 1 

首先你必须旋转所有与apache有关的日志,然后发送一个信号1(SIGHUP)给主httpd进程,强制logfile文件描述符被重新打开。