
logrotate를 사용하는 데 문제가 있습니다. 내가 지시한 대로 작동하지 않는 것 같습니다.
환경:
- 센토스 6.4
- 로그 회전 3.7.8
내 /etc/logrotate.conf 파일의 내용은 다음과 같습니다.
# rotate log files weekly
daily
# keep 4 weeks worth of backlogs
rotate 30
# 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
compresscmd /usr/bin/bzip2
uncompresscmd /usr/bin/bunzip2
compressext .bz2
# RPM packages drop log rotation information into this directory
include /etc/logrotate.d
문제가 있는 logrotate 파일은 다음과 같습니다(elasticsearch의 경우 /etc/logrotate.d/elasticsearch에 있음).
/var/log/elasticsearch/*.log {
missingok
notifempty
copytruncate
postrotate
rm -rf /var/log/elasticsearch/*.log.$(date +%Y)*
size 1k
rotate 7
daily
}
우선, 내 rotate 7
구성을 따르지 않습니다. 실행하면 다음 logrotate -d /etc/logrotate.conf
과 같은 줄이 표시됩니다.
회전 로그 /var/log/elasticsearch/gravity-es-prod02.log, log->rotateCount는 30입니다.
...그리고 30개의 서로 다른 *.bz2 파일을 회전한다고 말하는 여러 문장도 있습니다.
gravity-es-prod02.log.2015-12-01
둘째, dateext를 활성화하지 않았음에도 불구하고 여전히 지정된 로그 파일(및 마지막 수동 정리 이후의 이전 날짜)이 남아 있었습니다. 이것들도 정리되지 않아서 수동으로 정리하기 위해 postrotate 라인을 추가했지만 그것도 제대로 작동하지 않은 것 같습니다.
편집하다 logrotate 스크립트를 실행하기 위한 cron 파일은 매우 표준적입니다.
#> cat /etc/cron.daily/logrotate
#!/bin/sh
/usr/sbin/logrotate /etc/logrotate.conf >/dev/null 2>&1
EXITVALUE=$?
if [ $EXITVALUE != 0 ]; then
/usr/bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE]"
fi
exit 0
답변1
귀하가 제공한 스크립트에서 버그를 발견했습니다(종료 스크립트 누락).
postrotate
rm -rf /var/log/elasticsearch/*.log.$(date +%Y)*
endscript
나는 이 부분이 실패하고 어떻게든 이 로그 모드의 전역 설정을 적용한다고 생각합니다.