freebsd newsyslog.conf.d 设置存档目录

freebsd newsyslog.conf.d set archive dir

在 FreeBSD 上,我有一个名为

的文件

my_site

/usr/local/etc/newsyslog.conf.d

文件 my_site 的内容如下所示:

/path/to/site/log/site.access_log 644 7 1048576 * GCZ /var/run/nginx.pid  30

现在我需要知道如何指定存档目标目录。

我没有在文档中找到任何关于如何在配置文件中设置存档目录的内容。

检查 Files 部分中 NEWSYSLOG(8) 的底部:

FILES
     /etc/newsyslog.conf              newsyslog configuration file
     /etc/newsyslog.conf.d            Each file in this directory will be
                                      included by the default newsyslog.conf.
     /usr/local/etc/newsyslog.conf.d  Each file in this directory will be
                                      included by the default newsyslog.conf.

例如,如果您想旋转 /var/log/daemon.log,您可以使用以下内容创建文件 /etc/newsyslog.conf.d/extra.conf

/var/log/daemon.log                        600  7     *    @T00  J

然后测试(不要旋转)运行这个:

# newsyslog -nv

-n 将导致 newsyslog 不 trim 日志,而是打印出如果未指定此选项将执行的操作。

-v 用于详细模式。

所以你可能会看到这样的东西:

Processing /etc/newsyslog.conf
Found: <include> /etc/newsyslog.conf.d/*
Found: <include> /usr/local/etc/newsyslog.conf.d/*
Processing /etc/newsyslog.conf.d/extra.conf
var/log/all.log <7J>: --> will trim at Wed Apr 25 00:00:00 2018
/var/log/amd.log <7J>: does not exist, skipped.
/var/log/auth.log <7J>: --> will trim at Tue Jan  1 00:00:00 2019
/var/log/console.log <5J>: does not exist, skipped.
/var/log/cron <3J>: size (Kb): 1 [100] --> skipping
/var/log/daily.log <7J>: does not exist, skipped.
/var/log/debug.log <7J>: size (Kb): 1 [100] --> skipping
/var/log/init.log <3J>: does not exist, skipped.
/var/log/kerberos.log <7J>: does not exist, skipped.
/var/log/lpd-errs <7J>: size (Kb): 1 [100] --> skipping
/var/log/maillog <7J>: --> will trim at Wed Apr 25 00:00:00 2018
/var/log/messages <5J>: --> will trim at Tue Jan  1 00:00:00 2019
/var/log/monthly.log <12J>: does not exist, skipped.
/var/log/pflog <3J>: size (Kb): 60 [100] --> skipping
/var/log/ppp.log <3J>: size (Kb): 1 [100] --> skipping
/var/log/devd.log <3J>: size (Kb): 1 [100] --> skipping
/var/log/security <10J>: size (Kb): 1 [100] --> skipping
/var/log/sendmail.st <10>: does not exist, skipped.
/var/log/utx.log <3>: --> will trim at Tue May  1 05:00:00 2018
/var/log/weekly.log <5J>: does not exist, skipped.
/var/log/xferlog <7J>: size (Kb): 1 [100] --> skipping
/var/log/daemon.log <7J>: does not exist, skipped.

注意最后一行:

/var/log/daemon.log <7J>: does not exist, skipped.

在这种情况下,有助于调试并发现 syslogd 中可能缺少该条目,可以通过将此行添加到 /etc/syslog.conf:

来解决这个问题
daemon.notice                        /var/log/daemon.log