我全新安装了 ubuntu 20.04。我在 /etc/logrotate.d/rsyslog 文件中设置了每日轮换,最大大小为 1M,但 /var/log/syslog 和 kern.log 文件不断增加。这是 rsyslog 和 /etc/logrotate.conf 配置。
rsyslog 文件
/var/log/syslog
{
rotate 4
maxsize 1M
daily
missingok
notifempty
compress
delaycompress
# create 640 root adm
postrotate
/usr/lib/rsyslog/rsyslog-rotate
# reload rsyslog >/dev/null 2>&1 || true
endscript
}
/var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
{
rotate 4
daily
missingok
notifempty
compress
delaycompress
sharedscripts
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}
Logrotate.conf 文件
rotate log files weekly
#weekly
daily
# use the adm group by default, since this is the owning group
# of /var/log/syslog.
su root adm
# su root syslog
# size 3M
# keep 4 weeks worth of backlogs
rotate 4
# create new (empty) log files after rotating old ones
create
# use date as a suffix of the rotated file
#dateext
# uncomment this if you want your log files compressed
#compress
# compress
# packages drop log rotation information into this directory
include /etc/logrotate.d
# system-specific logs may be also be configured here.
#/var/log/syslog {
# size 1M
# rotate 4
# daily
# missingok
# notifempty
# delaycompress
# compress
# postrotate
# invoke-rc.d rsyslog reload > /dev/null
# endscript
#}
任何帮助,将不胜感激。
编辑:谢谢。这是输出。
$ logrotate --debug /etc/logrotate.conf
WARNING: logrotate in debug mode does nothing except printing debug messages! Consider using verbose mode (-v) instead if this is not what you want.
reading config file /etc/logrotate.conf
including /etc/logrotate.d
reading config file alternatives
reading config file apport
reading config file apt
reading config file bootlog
reading config file btmp
reading config file cups-daemon
reading config file dpkg
reading config file ppp
reading config file rsyslog
reading config file speech-dispatcher
reading config file ubuntu-advantage-tools
reading config file ufw
reading config file unattended-upgrades
reading config file wtmp
Reading state from file: /var/lib/logrotate/status
Allocating hash table for state file, size 64 entries
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Creating new state
Handling 17 logs
rotating pattern: /var/log/alternatives.log monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/apport.log after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/apt/term.log monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/apt/history.log monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/boot.log
after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/btmp monthly (1 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/cups/*log after 1 days (7 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/dpkg.log monthly (12 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/ppp-connect-errors weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/syslog
weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/mail.info
/var/log/mail.warn
/var/log/mail.err
/var/log/mail.log
/var/log/daemon.log
/var/log/kern.log
/var/log/auth.log
/var/log/user.log
/var/log/lpr.log
/var/log/cron.log
/var/log/debug
/var/log/messages
weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/speech-dispatcher/speech-dispatcher.log /var/log/speech-dispatcher/speech-dispatcher-protocol.log after 1 days (7 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/speech-dispatcher/debug-epos-generic /var/log/speech-dispatcher/debug-festival /var/log/speech-dispatcher/debug-flite after 1 days (2 rotations)
empty log files are rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/ubuntu-advantage.log monthly (6 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/ufw.log
weekly (4 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/unattended-upgrades/unattended-upgrades.log
/var/log/unattended-upgrades/unattended-upgrades-dpkg.log
/var/log/unattended-upgrades/unattended-upgrades-shutdown.log
monthly (6 rotations)
empty log files are not rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
rotating pattern: /var/log/wtmp monthly (1 rotations)
empty log files are rotated, only log files >= 1048576 bytes are rotated, old logs are removed
switching euid to 0 and egid to 4
error: error switching euid to 0 and egid to 4: Operation not permitted
问题得到解决。在互联网上搜索后,我发现了一个帖子,它让我对不被处决
https://forums.linuxmint.com/viewtopic.php?t=324733
的可能性有了一个想法。logrotate.timer
我搜索并发现
logrotate timer
设置为每天 12 点(午夜)一次,此时我的计算机已关闭,因此它可能无法执行logrotate.service
。我从中复制了计时器设置anacron.timer
并使其每小时运行一次。除了我还授予/etc/logrotate.d
文件夹 755 权限以及该文件夹 644 权限内的所有文件(它可能更早存在,但我怀疑它可能在试验时发生了变化)。Logrotate.service
还检查计算机是否必须使用交流电源。进行设置false
会导致其他定时器无法在交流电源上执行的问题。所以我保持不变。发布此更改自动日志轮换按计划进行。