평소 로그 관리를 게을리 했었는데 Xenserver를 계기로 제대로 관리 해보자!
일반적으로 리눅스의 logrotate는 다음과 같이 구성된다.
- /usr/sbin/logrotate : 실행 데몬
- /etc/logrotate.conf: 메인 설정 파일
- /etc/logrotate.d: 세부 설정 파일 디렉토리
- /usr/sbin/logrotate
- 데몬 으로써 구동 되고 있지 않아 cron에 의해 주기적으로 실행된다.
- 내용
# see “man logrotate” for details
# rotate log files weekly
weekly (주 단위로 로테이트 이며 daily, monthly로 변경 가능)
# keep 4 weeks worth of backlogs
rotate 4 (4회 까지 한다는 의미로 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 (압축, 주석처리시 디스크의 빈 용량을 보고 판단한다. decompress시 압축하지 않는다. )
# 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
}
# system-specific logs may be also be configured here.
~
.
- /etc/logrotate.d
- 해당 디렉토리 파일에 존재하는 설정은 logrotate.conf 파일의 설정을 따르지 않고 해당 설정 파일을 우선한다.
/var/log/httpd/*log {
missingok (로그파일이 발견되지 않을 경우 에러 메시지를 출력하지 않고 계속 진행)
notifempty (로그파일이 빈더라도 덮어쓰지 않는다. 기본적으로 ifempty이며 덮어쓴다.)
daily (로그 로테이트의 일단위 실행)rotate 100 (100일까지 저장)
sharedscripts
delaycompress
postrotate
/sbin/service httpd reload > /dev/null 2>/dev/null || true
endscript
}.