logrotate 설정파일 생성

# cd /etc/logrotate.d

# vi apache

==================================

/usr/local/httpd2/logs/*log {
    missingok
    notifempty
    sharedscripts
    postrotate
    /usr/local/httpd2/bin/apachectl graceful 2> /dev/null || true
    endscript
    dateext
}

==================================

 * missingok : 로그파일이 없어도 에러처리하지 않는다.

 * notifempty : 로그파일 용량이 0일 경우 rotate 하지 않는다.

 * sharedscripts : postrotate / endscript 스크립트 한번 실행

 * postrotate / endscript : 순환작업 후 실행할 작업 설정

 * dateext : 로그파일에 YYYYMMDD 형식의 확장자 추가

 

테스트

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

 

실행

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

 

logrotate 정상실행 되지 않을 경우 (로그디렉토리가 /usr 일 경우)

logrotate 테스트시 정상적으로 실행되었다고 나오나, 실질적으로 logrotate가 되지 않는경우가 있습니다.

 * /var/log/syslog 에러로그 

Aug  7 00:00:02 www systemd[1]: logrotate.service: Main process exited, code=exited, status=1/FAILURE
Aug  7 00:00:02 www systemd[1]: logrotate.service: Failed with result 'exit-code'.
Aug  7 00:00:02 www systemd[1]: Failed to start Rotate log files.

 

# vi /lib/systemd/system/logrotate.service

 * 최하단에 로그경로 추가

==================================

ReadWritePaths=/usr/local/httpd2/logs

==================================

 

+ Recent posts