1 개요[ | ]
- logrotate
- /usr/sbin/logrotate
- 로그 로테이트, 로그순환
- 로그파일 관리 도구
- 시스템 로그 순환, 압축, 메일발송 자동화
2 주요 지시어[ | ]
logrotate 설정에 사용되는 지시어들은 매우 다양하다. 중요한 것 몇가지만 살펴보자.
- daily / weekly : 일단위, 주단위 순환
- rotate 4: 보존파일을 최대 4개까지만 보존[1]
- size 100M: 100MB를 넘을때만 순환[2]
- compress: 예전 파일을 gzip으로 압축하여 보존
3 conf 구조[ | ]
Console
Copy
[root@zetawiki ~]# cat /etc/logrotate.conf | egrep -v "^[[:space:]]*$" | grep -v ^#
weekly
rotate 4
create
dateext
include /etc/logrotate.d
/var/log/wtmp {
monthly
create 0664 root utmp
minsize 1M
rotate 1
}
/var/log/btmp {
missingok
monthly
create 0600 root utmp
rotate 1
}
- → /etc/logrotate.conf에는 wtmp, btmp에 대한 것만 있고, 다른 로그에 대해서는 /etc/logrotate.d 폴더에 설정한다.
- → 이 파일은 하위 파일들에 대해 템플릿의 역할을 한다(상속). 옵션을 따로 명기하지 않으면 주단위(weekly), 보존파일 최대 4개(rotate 4) 등이 적용된다.
Console
Copy
[root@zetawiki ~]# ll /etc/logrotate.d
total 84
-rw-r--r-- 1 root root 144 Feb 23 2012 acpid
-rw-r--r-- 1 root root 288 Nov 12 2007 conman
-rw-r--r-- 1 root root 180 Nov 25 2012 httpd
... (생략)
- → 여러가지 로그순환 설정이 되어 있다. 여기서는 httpd를 살펴보자.
Console
Copy
[root@zetawiki ~]# cat /etc/logrotate.d/httpd
/var/log/httpd/*log {
missingok
notifempty
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/httpd/httpd.pid 2>/dev/null` 2> /dev/null || true
endscript
}
- → /etc/logrotate.d/httpd는 /var/log/httpd/*log 에 대해 적용된다.
Console
Copy
[root@zetawiki ~]# ll /var/log/httpd/*log
-rw-r--r-- 1 root root 2362719 Feb 2 13:25 /var/log/httpd/access_log
-rw-r--r-- 1 root root 257620 Feb 2 13:25 /var/log/httpd/error_log
- → /var/log/httpd/*log는 곧 access_log과 error_log이다.
Console
Copy
[root@zetawiki ~]# ll /var/log/httpd/*log*
-rw-r--r-- 1 root root 2362719 Feb 2 13:25 /var/log/httpd/access_log
-rw-r--r-- 1 root root 74277057 Feb 2 04:01 /var/log/httpd/access_log.1
-rw-r--r-- 1 root root 100736948 Jan 26 04:02 /var/log/httpd/access_log.2
-rw-r--r-- 1 root root 97242280 Jan 19 04:01 /var/log/httpd/access_log.3
-rw-r--r-- 1 root root 93556561 Jan 12 04:02 /var/log/httpd/access_log.4
-rw-r--r-- 1 root root 257620 Feb 2 13:25 /var/log/httpd/error_log
-rw-r--r-- 1 root root 5063067 Feb 2 04:02 /var/log/httpd/error_log.1
-rw-r--r-- 1 root root 6701905 Jan 26 04:02 /var/log/httpd/error_log.2
-rw-r--r-- 1 root root 4858782 Jan 19 04:02 /var/log/httpd/error_log.3
-rw-r--r-- 1 root root 4466931 Jan 12 04:02 /var/log/httpd/error_log.4
- → 주단위(weekly), 보존파일 4개(rotate 4)로 로그가 순환되고 있다.
4 같이 보기[ | ]
- logrotate 설정하기
- logrotate 지시어
- /etc/logrotate.conf
- /etc/logrotate.d/httpd
- /var/lib/logrotate.status
- /etc/cron.daily/logrotate
- 로그 파일
- rotatelogs
- logrotate 버전 확인