Logrotate 편집하기

경고: 로그인하지 않았습니다. 편집을 하면 IP 주소가 공개되게 됩니다. 로그인하거나 계정을 생성하면 편집자가 사용자 이름으로 기록되고, 다른 장점도 있습니다.

편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.

최신판 당신의 편집
1번째 줄: 1번째 줄:
==개요==
==개요==
;logrotate
;logrotate
;로그 로테이트
;/usr/sbin/logrotate
;/usr/sbin/logrotate
;로그 로테이트, 로그순환
*[[로그파일]] 관리 도구
*시스템 로그 순환, 압축, 메일발송 자동화
*시스템 로그 순환, 압축, 메일발송 자동화


==주요 지시어==
==기본 설정==
logrotate 설정에 사용되는 지시어들은 매우 다양하다. 중요한 것 몇가지만 살펴보자.
CentOS 기본 설정이다.
*daily / weekly : 일단위, 주단위 순환
<source lang='dos'>
*rotate 4: 보존파일을 최대 4개까지만 보존<ref>즉, 4개가 넘어가면 가장 옛날 것을 삭제. 0으로 되어 있다면 순환시 바로 삭제됨.</ref>
[root@jmnote ~]# cat /etc/logrotate.conf | egrep -v "^[[:space:]]*$" | grep -v ^#
*size 100M: 100MB를 넘을때만 순환<ref>(주의!) 항상 감시하고 있는 것이 아님. 순환주기가 되었을 때 확인하는 것</ref>
*compress: 예전 파일을 gzip으로 압축하여 보존
 
==conf 구조==
<source lang='console'>
[root@zetawiki ~]# cat /etc/logrotate.conf | egrep -v "^[[:space:]]*$" | grep -v ^#
weekly
weekly
rotate 4
rotate 4
34번째 줄: 27번째 줄:
}
}
</source>
</source>
:→ [[/etc/logrotate.conf]]에는 [[wtmp]], [[btmp]]에 대한 것만 있고, 다른 로그에 대해서는 /etc/logrotate.d 폴더에 설정한다.
:→ /etc/logratotat.conf에는 [[wtmp]], [[btmp]]에 대한 것만 있고, 다른 로그에 대해서는 /etc/logrotate.d 폴더에 설정한다.
:→ 이 파일은 하위 파일들에 대해 템플릿의 역할을 한다(상속). 옵션을 따로 명기하지 않으면 주단위(weekly), 보존파일 최대 4개(rotate 4) 등이 적용된다.
<source lang='dos'>
<source lang='console'>
[root@jmnote ~]# ll /etc/logrotate.d
[root@zetawiki ~]# ll /etc/logrotate.d
total 32
total 84
-rw-r--r--. 1 root root  71 Jun 22 2012 cups
-rw-r--r-- 1 root root  144 Feb 23 2012 acpid
-rw-r--r--. 1 root root 103 Jun 22 2012 dracut
-rw-r--r-- 1 root root  288 Nov 12  2007 conman
-rw-r--r--. 1 root root 185 Feb 7 2012 httpd
-rw-r--r-- 1 root root  180 Nov 25 2012 httpd
-rw-r--r--. 1 root root 136 Aug 22  2010 ppp
... (생략)
-rw-r--r--. 1 root root 329 Jun 22  2012 psacct
</source>
-rw-r--r--. 1 root root 210 May 17  2012 syslog
:→ 여러가지 로그순환 설정이 되어 있다. 여기서는 httpd를 살펴보자.
-rw-r--r--. 1 root root 100 Jun 22  2012 wpa_supplicant
<source lang='console'>
-rw-r--r--. 1 root root 100 Jun 22  2012 yum
[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
}
</source>
</source>
:→ /etc/logrotate.d/httpd는 /var/log/httpd/*log 에 대해 적용된다.
<source lang='console'>
[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
</source>
:→ /var/log/httpd/*log는 곧 access_log과 error_log이다.
<source lang='console'>
[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
</source>
:→ 주단위(weekly), 보존파일 4개(rotate 4)로 로그가 순환되고 있다.


==같이 보기==
==같이 보기==
*[[logrotate 설정하기]]
*[[logrotate 지시어]]
*[[/etc/logrotate.conf]]
*[[/etc/logrotate.conf]]
*[[/etc/logrotate.d/httpd]]
*[[/var/lib/logrotate.status]]
*[[/etc/cron.daily/logrotate]]
*[[로그 파일]]
*[[로그 파일]]
*[[rotatelogs]]
*[[logrotate 버전 확인]]
==주석==
<references/>


[[분류: logrotate]]
[[분류: 로그]]
[[분류: /usr/sbin]]
[[분류: /usr/sbin]]

제타위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 3.0 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 제타위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요!

취소 편집 도움말 (새 창에서 열림)