Logrotate가 예상대로 작동하지 않습니다.

Logrotate가 예상대로 작동하지 않습니다.

내 CentOS 6 설치에서 httpd에 대한 기본 logrotate 규칙은 다음과 같습니다.

[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를 변경하여 현재와 같이 작동하고 크기가 100M에 도달하면 error.log가 압축되도록 하고 싶습니다.

이를 위해 다음을 시도합니다.

(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
}

/usr/sbin/logrotate /etc/logrotate.d/httpd_error(ii) 1분마다 실행되는 cron 작업을 만듭니다.

그러나 작동하지 않습니다. 로그 파일을 생성하고 수동으로 실행하면 다음과 같은 결과가 /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

실제로 회전 설정을 얻게 됩니다.

관련 정보