Logrotate

Jmnote (토론 | 기여)님의 2014년 2월 2일 (일) 14:11 판 (→‎개요)

1 개요

logrotate
로그 로테이트, 로그순환
/usr/sbin/logrotate
  • 시스템 로그 순환, 압축, 메일발송 자동화

2 주요 지시어

logrotate 설정에 사용되는 지시어들은 매우 다양하다. 중요한 것 몇가지만 살펴보자.

  • daily / weekly : 일단위, 주단위 순환
  • rotate 4: 보존파일을 최대 4개까지만 보존[1]
  • size 100M: 지정된 크기를 넘을때만 순환[2]
  • compress: 예전 파일을 gzip으로 압축하여 보존

3 conf 구조

[root@jmnote ~]# 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) 등이 적용된다.
[root@jmnote ~]# 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를 살펴보자.
[root@jmnote ~]# 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 에 대해 적용된다.
[root@jmnote ~]# 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이다.
[root@jmnote ~]# 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 같이 보기

  1. 즉, 4개가 넘어가면 가장 옛날 것을 삭제. 0으로 되어 있다면 순환시 바로 삭제됨.
  2. (주의!) 항상 감시하고 있는 것이 아님. 순환주기가 되었을 때 확인하는 것
문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}