Logrotate не работает так, как ожидалось

Logrotate не работает так, как ожидалось

Правила logrotate по умолчанию для httpd в моей установке CentOS 6 выглядят следующим образом:

[root@myVM ~]# cat /etc/logrotate.d/httpd
/var/log/httpd/*log {
    missingok
    notifempty
    sharedscripts
    delaycompress
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}

Также по умолчанию logrotate cron выполняется раз в полночь. Я хочу изменить logrotate, чтобы он работал так, как сейчас, плюс чтобы error.log сжимался, если его размер достигнет 100M.

Чтобы сделать это, я пробую следующее:

(i) Создайте /etc/logrotate.d/httpd_errorфайл конфигурации:

[root@myVM ~]# cat  /etc/logrotate.d/httpd_error 
/var/log/httpd/error_log {
    missingok
    notifempty
    size 100M
    sharedscripts
    delaycompress
    postrotate
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
    endscript
}

(ii) Создайте действие cron, которое будет запускаться /usr/sbin/logrotate /etc/logrotate.d/httpd_errorкаждую минуту

Однако это не работает. Когда я генерирую файл журнала и запускаю его вручную, /usr/sbin/logrotate -d /etc/logrotate.d/httpd_errorя получаю:

[root@myVM ~]# perl -e 'print "error error error" x 10000 for 1..1000 ;' > /var/log/httpd/error_log 
[root@myVM ~]# ls -al /var/log/httpd/error_log                                                      
-rwxrwxrwx. 1 root root 170000000 2015-10-07 04:10 /var/log/httpd/error_log
[root@myVM ~]# /usr/sbin/logrotate -d /etc/logrotate.d/httpd_error 
reading config file /etc/logrotate.d/httpd_error
reading config info for /var/log/httpd/error_log 

Handling 1 logs

rotating pattern: /var/log/httpd/error_log  104857600 bytes (no old logs will be kept)
empty log files are not rotated, old logs are removed
considering log /var/log/httpd/error_log
  log needs rotating
rotating log /var/log/httpd/error_log, log->rotateCount is 0
dateext suffix '-20151007'
glob pattern '-[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]'
renaming /var/log/httpd/error_log.1 to /var/log/httpd/error_log.2 (rotatecount 1, logstart 1, i 1), 
renaming /var/log/httpd/error_log.0 to /var/log/httpd/error_log.1 (rotatecount 1, logstart 1, i 0), 
renaming /var/log/httpd/error_log to /var/log/httpd/error_log.1
disposeName will be /var/log/httpd/error_log.1
running postrotate script
running script with arg /var/log/httpd/error_log : "
        /sbin/service httpd reload > /dev/null 2>/dev/null || true
"
removing old log /var/log/httpd/error_log.1
error: error opening /var/log/httpd/error_log.1: No such file or directory

Что я делаю не так?

Если это актуально, то мой logrotate.confвыглядит так:

[root@myVM ~]# 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

# use date as a suffix of the rotated file
dateext

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

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

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

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

решение1

Ваша ошибка здесь в попытке запустить только одну часть вашей конфигурации ( /usr/sbin/logrotate -d /etc/logrotate.d/httpd_error), в которой нет никакой ротации. Вы игнорируете свой logrotate.conf.

Использовать:

/usr/sbin/logrotate -d /etc/logrotate.conf

так что вы фактически получаете настройки вращения.

Связанный контент