WAS

웹서버 log rolling (logrotate)

Lawmin 2025. 4. 3. 13:53

기본적인 httpd log 에 대한 6개월 보관 설정 예시 (오래된 것은 삭제)

# vi /etc/logrotate.d/httpd

/var/log/httpd/*log {
    weekly                # 로그 파일을 주 단위로 회전
    rotate 24             # 24주(약 6개월) 동안 로그를 보관
    missingok             # 로그 파일이 없더라도 오류 무시
    notifempty            # 로그가 비어있으면 회전하지 않음
    compress              # gzip 압축하여 저장 (.gz)
    delaycompress         # 가장 최근 파일은 압축하지 않음
    sharedscripts         # 여러 개의 로그 파일을 한 번에 관리
    postrotate
        /bin/systemctl reload httpd > /dev/null 2>&1 || true
    endscript
}