"Logrotate"의 두 판 사이의 차이

잔글 (봇: 자동으로 텍스트 교체 (-<source lang='cli'> +<source lang='console'>))
 
(사용자 2명의 중간 판 26개는 보이지 않습니다)
1번째 줄: 1번째 줄:
==개요==
==개요==
;logrotate
;logrotate
;로그 로테이트
;/usr/sbin/logrotate
;/usr/sbin/logrotate
;로그 로테이트, 로그순환
*[[로그파일]] 관리 도구
*시스템 로그 순환, 압축, 메일발송 자동화
*시스템 로그 순환, 압축, 메일발송 자동화


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

2016년 3월 29일 (화) 10:38 기준 최신판

1 개요[ | ]

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

2 주요 지시어[ | ]

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

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

3 conf 구조[ | ]

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

5 주석[ | ]

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