Logrotate
About
커널이나 각 데몬의 메시지를 계속 기록하게 되면 로그 파일 크기가 커져 파일 시스템의 파일 용량 상한에 도달하게 되고 메시지를 기록할 수 없게 된다. 이를 방지하기 위한 것이 logrotate이다.
logrotate는 cron 경유로 구동되며 지정된 로그 파일을 이동, 압축하고 새로운 로그 파일을 생성한다. 또한, 필요하면 데몬을 재구동하기도 한다.
처리 순서
- cron이
/etc/cron.daily/logrotate
를 읽어들임 - logrotate가
/etc/logrotate.conf
를 설정파일로써 실행하여logrotate.conf
에 지정된 로그 파일을 처리함 -
/etc/logrotate.d/
아래의 파일을 읽어들여 지정된 로그 파일을 처리함
주요 logrotate 지시어 리스트
- create
- missingok
- rotate
- daily, weekly, monthly, yearly
- compress
- delaycompress
- compresscmd
- postrotate/endscript
- notifempty
- sharedscripts
- size/minsize
- nocreate
See also
Troubleshooting
Free-space driven log rotation
디스크의 남은 공간을 확인하고 제거하는 logrotate:
/mnt/user/logs/*.log /mnt/user/logs/*/*.log {
daily
missingok
rotate 7
compress
delaycompress
notifempty
su root www-data
create 760 root www-data
firstaction
for file in `find -type f -size +1024M`; do
percent=`df -h | grep /mnt/user | awk '{print $5}' | sed 's/%//'`
if [ $percent -gt 50 ]; then
echo "Removed $file" >> /mnt/user/logs/logrotate.log
rm $file
fi
done;
endscript
}