加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

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

发布时间:2020-12-13 18:17:45 所属栏目:Linux 来源:网络整理
导读:我注意到在/ var / log中创建的邮件日志正由root(用户和组)创建并拥有. 我写了一个监控日志的Nagios检查,为了让Nagios用户可以访问它,我给了另一个组读取权限,即: chmod o+r /var/log/maillog 现在当我想到它时,这只是一个日志文件,当日志文件将被填充时,日
我注意到在/ 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配置中处理的).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读