/var/log/syslog 没有轮换

/var/log/syslog 没有轮换

我刚刚安装了 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

答案1

问题解决了。在网上搜索后,我看到了一篇帖子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会导致计时器无法在交流电源上执行的其他问题。所以我保持不变。

发布此更改后,自动日志轮换将按照计划进行。

相关内容