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
}