繁体   English   中英

Ubuntu 12.10 logrotate问题

[英]Ubuntu 12.10 logrotate issue

在Ubuntu 12.10上,将以下条目添加到“ /etc/logrotate.d”路径中:

# cat /etc/logrotate.d/tsdb
/home/logs/*dat {
        daily
        rotate 30
        compress
        missingok
        notifempty
        create 0664 nagios nagios
}

以下是“ /etc/cron.daily/logrotate”文件的外观:

# cat /etc/cron.daily/logrotate
#!/bin/sh

# Clean non existent log file entries from status file
cd /var/lib/logrotate
test -e status || touch status
head -1 status > status.clean
sed 's/"//g' status | while read logfile date
do
    [ -e "$logfile" ] && echo "\"$logfile\" $date"
done >> status.clean
mv status.clean status

test -x /usr/sbin/logrotate || exit 0
/usr/sbin/logrotate /etc/logrotate.conf

我希望日志可以旋转,但是我看不到它们在旋转。 我在这里做错了什么?

状态文件确实显示logrotate在有问题的文件上运行,但是我看不到任何旋转的日志:

# cat /var/lib/logrotate/status
logrotate state -- version 2
"/home/logs/service-perfdata.dat" 2013-11-26
"/home/logs/host-perfdata.dat" 2013-11-26

同样,这是“ /etc/logrotate.conf”文件的外观:

# cat /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

以下是logrotate手动运行的输出:

# /usr/sbin/logrotate -vd /etc/logrotate.conf

rotating pattern: /home/logs/*dat  after 1 days (30 rotations)
empty log files are not rotated, old logs are removed
considering log /home/logs/host-perfdata.dat
  log does not need rotating
considering log /home/logs/service-perfdata.dat
  log does not need rotating

logrotate最初处理日志文件的方式是不直观的:

  • 第一次运行时,它将日期和日志文件名写到状态文件中(不会轮换任何日志)。
  • 下次运行时,它将检查状态文件以查看是否应轮换日志。

在您的情况下,您看到它检查了有问题的文件,并在第一次运行时为每个文件写了一个状态行。 随后的所有运行都将使用该行上的日期,并将其与日志文件日期进行比较,以查看其是否应该轮换。 我怀疑您的文件的日期为11月26日,并于11月26日进行了检查,因此它们不需要旋转。 回溯日志文件或回溯状态文件中的条目都会使它为您轮换文件。

在状态文件中没有条目的情况下,即使文件需要旋转,它也不会在第一次运行时旋转它们,除非您使用-f (强制)标志。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM