log-files – Linux:如何对日志轮换创建的新创建的日志强制执行特定权限?

我注意到在/ var / log中创建的邮件日志正由root(用户和组)创建并拥有.
我写了一个监控日志的Nagios检查,为了让Nagios用户可以访问它,我给了另一个组读取权限,即:
chmod o+r /var/log/maillog

现在当我想到它时,这只是一个日志文件,当日志文件将被填充时,日志旋转机制将重命名该文件并打开一个新文件,但新的maillog文件将没有我允许的读取权限.

所以我的问题是,如何确保日志轮换机制将创建具有Nagios用户权限的所有新mailllog文件?

提前致谢

解决方法

logrotate有create选项:
create mode owner group

Immediately after rotation (before the postrotate script is run) the log file is created (with the same name as the log
file just rotated). mode specifies the mode for the log file in octal (the same as chmod(2)),owner specifies the user
name who will own the log file,and group specifies the group the log file will belong to. Any of the log file attributes
may be omitted,in which case those attributes for the new file will use the same values as the original log file for the
omitted attributes. This option can be disabled using the nocreate option.

更多信息与男人logrotate.

像这样使用它:

/var/log/maillog {
....
        create 664 user group
....
}

在/etc/logrotate.conf中或/etc/logrotate.d中的单独文件中检查是否已有任何其他文件覆盖此文件.如何配置取决于您的操作系统(例如,在Ubuntu上,这是在rsyslog配置中处理的).

相关文章

linux常用进程通信方式包括管道(pipe)、有名管道(FIFO)、...
Linux性能观测工具按类别可分为系统级别和进程级别,系统级别...
本文详细介绍了curl命令基础和高级用法,包括跳过https的证书...
本文包含作者工作中常用到的一些命令,用于诊断网络、磁盘占满...
linux的平均负载表示运行态和就绪态及不可中断状态(正在io)的...
CPU上下文频繁切换会导致系统性能下降,切换分为进程切换、线...