logrotate 文件切割 权限问题

1、问题描述

logrotate 切割文件时,报错

root@test 11:04:53:/usr# logrotate  -d /etc/logrotate.d/rsyslog 

报错信息:

rotating pattern: /var/log/syslog
 after 1 days (14 rotations)
olddir is archive, empty log files are not rotated, old logs are removed
considering log /var/log/syslog
error: skipping "/var/log/syslog" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.

rotating pattern: /var/log/kern.log
/var/log/auth.log
 weekly (14 rotations)
olddir is archive, empty log files are not rotated, old logs are removed
considering log /var/log/kern.log
error: skipping "/var/log/kern.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.
considering log /var/log/auth.log
error: skipping "/var/log/auth.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.

2、分析

错误信息都一样,摘出一段,如下:

error: skipping “/var/log/syslog” because parent directory has insecure permissions (It’s world writable or writable by group which is not “root”) Set “su” directive in config file to tell logrotate which user/group should be used for rotation.

主要原因还是权限的问题, 需要指定执行脚本的用户或组。

其实,解决方法也给出来了:
Set “su” directive in config file to tell logrotate which user/group should be used for rotation.

3、 解决方法

在 logrotate 的配置中,指定用户和组,su root root

logrotate 完整配置如下:

/var/log/syslog
{
    su root root  # 指定用户、组
    daily
    rotate 14
    missingok
    notifempty
    
#   delaycompress
#    compress
    
    dateext
    dateformat -%Y-%m-%d
    
    olddir archive
    
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
    endscript
}

/var/log/kern.log
/var/log/auth.log
{
    su root root # 指定用户、组
    weekly
    rotate 14
    missingok
    notifempty
    
#    compress    
#    delaycompress
    
    olddir archive
    
    dateext
    dateformat -%Y-%m-%d
    
    sharedscripts
    postrotate
        /usr/lib/rsyslog/rsyslog-rotate
    endscript
}
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值