Logrotate 不会旋转日志,尽管它说它会

Logrotate 不会旋转日志,尽管它说它会

我有一个正常工作的 logrotate 配置,直到突然停止工作。我猜想在我log更新应用程序时删除并重新创建文件夹后,它停止旋转我的日志。以下是配置和 logrotate 日志的相关部分。

/etc/logrotate.conf

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp, or btmp -- we'll rotate them here
/var/log/wtmp {
    missingok
    monthly
    create 0664 root utmp
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0660 root utmp
    rotate 1
}

# system-specific logs may be configured here
/var/lib/redmine/log/production.log{
    daily
    rotate 30
    compress
    delaycompress
    missingok
    notifempty
}

在我手动运行 logrotate 之后:

rotating pattern: /var/lib/redmine/log/production.log after 1 days (30 rotations)
empty log files are not rotated, old logs are removed
considering log /var/lib/redmine/log/production.log
  log needs rotating
rotating log /var/lib/redmine/log/production.log, log->rotateCount is 30
dateext suffix '-20151209'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
compressing log with: /bin/gzip
renaming /var/lib/redmine/log/production.log.30.gz to /var/lib/redmine/log/production.log.31.gz (rotatecount 30, logstart 1, i 30),
renaming /var/lib/redmine/log/production.log.29.gz to /var/lib/redmine/log/production.log.30.gz (rotatecount 30, logstart 1, i 29),
renaming /var/lib/redmine/log/production.log.28.gz to /var/lib/redmine/log/production.log.29.gz (rotatecount 30, logstart 1, i 28),
renaming /var/lib/redmine/log/production.log.27.gz to /var/lib/redmine/log/production.log.28.gz (rotatecount 30, logstart 1, i 27),
renaming /var/lib/redmine/log/production.log.26.gz to /var/lib/redmine/log/production.log.27.gz (rotatecount 30, logstart 1, i 26),
renaming /var/lib/redmine/log/production.log.25.gz to /var/lib/redmine/log/production.log.26.gz (rotatecount 30, logstart 1, i 25),
renaming /var/lib/redmine/log/production.log.24.gz to /var/lib/redmine/log/production.log.25.gz (rotatecount 30, logstart 1, i 24),
renaming /var/lib/redmine/log/production.log.23.gz to /var/lib/redmine/log/production.log.24.gz (rotatecount 30, logstart 1, i 23),
renaming /var/lib/redmine/log/production.log.22.gz to /var/lib/redmine/log/production.log.23.gz (rotatecount 30, logstart 1, i 22),
renaming /var/lib/redmine/log/production.log.21.gz to /var/lib/redmine/log/production.log.22.gz (rotatecount 30, logstart 1, i 21),
renaming /var/lib/redmine/log/production.log.20.gz to /var/lib/redmine/log/production.log.21.gz (rotatecount 30, logstart 1, i 20),
renaming /var/lib/redmine/log/production.log.19.gz to /var/lib/redmine/log/production.log.20.gz (rotatecount 30, logstart 1, i 19),
renaming /var/lib/redmine/log/production.log.18.gz to /var/lib/redmine/log/production.log.19.gz (rotatecount 30, logstart 1, i 18),
renaming /var/lib/redmine/log/production.log.17.gz to /var/lib/redmine/log/production.log.18.gz (rotatecount 30, logstart 1, i 17),
renaming /var/lib/redmine/log/production.log.16.gz to /var/lib/redmine/log/production.log.17.gz (rotatecount 30, logstart 1, i 16),
renaming /var/lib/redmine/log/production.log.15.gz to /var/lib/redmine/log/production.log.16.gz (rotatecount 30, logstart 1, i 15),
renaming /var/lib/redmine/log/production.log.14.gz to /var/lib/redmine/log/production.log.15.gz (rotatecount 30, logstart 1, i 14),
renaming /var/lib/redmine/log/production.log.13.gz to /var/lib/redmine/log/production.log.14.gz (rotatecount 30, logstart 1, i 13),
renaming /var/lib/redmine/log/production.log.12.gz to /var/lib/redmine/log/production.log.13.gz (rotatecount 30, logstart 1, i 12),
renaming /var/lib/redmine/log/production.log.11.gz to /var/lib/redmine/log/production.log.12.gz (rotatecount 30, logstart 1, i 11),
renaming /var/lib/redmine/log/production.log.10.gz to /var/lib/redmine/log/production.log.11.gz (rotatecount 30, logstart 1, i 10),
renaming /var/lib/redmine/log/production.log.9.gz to /var/lib/redmine/log/production.log.10.gz (rotatecount 30, logstart 1, i 9),
renaming /var/lib/redmine/log/production.log.8.gz to /var/lib/redmine/log/production.log.9.gz (rotatecount 30, logstart 1, i 8),
renaming /var/lib/redmine/log/production.log.7.gz to /var/lib/redmine/log/production.log.8.gz (rotatecount 30, logstart 1, i 7),
renaming /var/lib/redmine/log/production.log.6.gz to /var/lib/redmine/log/production.log.7.gz (rotatecount 30, logstart 1, i 6),
renaming /var/lib/redmine/log/production.log.5.gz to /var/lib/redmine/log/production.log.6.gz (rotatecount 30, logstart 1, i 5),
renaming /var/lib/redmine/log/production.log.4.gz to /var/lib/redmine/log/production.log.5.gz (rotatecount 30, logstart 1, i 4),
renaming /var/lib/redmine/log/production.log.3.gz to /var/lib/redmine/log/production.log.4.gz (rotatecount 30, logstart 1, i 3),
renaming /var/lib/redmine/log/production.log.2.gz to /var/lib/redmine/log/production.log.3.gz (rotatecount 30, logstart 1, i 2),
renaming /var/lib/redmine/log/production.log.1.gz to /var/lib/redmine/log/production.log.2.gz (rotatecount 30, logstart 1, i 1),
renaming /var/lib/redmine/log/production.log.0.gz to /var/lib/redmine/log/production.log.1.gz (rotatecount 30, logstart 1, i 0),
renaming /var/lib/redmine/log/production.log to /var/lib/redmine/log/production.log.1
creating new /var/lib/redmine/log/production.log mode = 0644 uid = 1000 gid = 1000
removing old log /var/lib/redmine/log/production.log.31.gz
error: error opening /var/lib/redmine/log/production.log.31.gz: No such file or directory

在我列出日志目录之后:

ll /var/lib/redmine/log/
total 178484
drwxrwxr-x  2 redmine redmine      4096 Dec  9 12:05 ./
drwxr-xr-x 20 redmine redmine      4096 Dec  6 23:56 ../
-rw-rw-r--  1 redmine redmine     49581 Dec  8 14:47 development.log
-rw-r--r--  1 redmine redmine 182700709 Dec  9 12:05 production.log

所以它说它确实轮换了日志文件,但实际上什么也没发生。这是什么原因造成的?

答案1

一个原因可能是您正在像 redmine 用户一样列出您的日志,而 logrotate 以 root 身份工作,因此目录列表不会显示它们

我宁愿创建文件 /etc/logrotate.d/redmine 其中包含以下内容:

/path/to/your/redmine/log/production.log {
daily
missingok
rotate 31
compress
delaycompress
notifempty
copytruncate
} 

然后通过以下方式测试:

sudo /usr/sbin/logrotate -f /etc/logrotate.d/redmine

答案2

问题出在文件夹的权限错误log。Logrotate 无法处理它,因为它具有组写入权限。在chmod 755日志文件夹上运行后,一切开始正常工作。

相关内容