상세 컨텐츠

본문 제목

리눅스 로그 관리 - Logrotate

Ops/Monitoring

by 크리두 2020. 11. 3. 19:08

본문

반응형

Logrotate란?

리눅스 서버를 관리하기 위해 log를 다들 열심히 남깁니다. 서버 상태 또는 디버깅, 장애를 대비하기 위해 남기도록 설정하지만 서비스를 오래 운영하다보면 엄청난 양이 쌓이게 됩니다. 로그의 양이 너무 많아지면 서비스를 위한 서버가 필요한 resource들이 부족해지는 문제 또는 여러 영향이 있기 때문에 logrotate를 통해 관리를 하게 됩니다.

기능

  • 여러 개의 로그 파일을 동시에 관리
  • rotate 수 설정
  • 압축
  • 로테이트 전/후로 스크립트를 실행

Logrotate 실행

logrotate.conf 구조

전체 구조는 아래와 같으며 하나씩 구조를 파악해보자.

# see "man logrotate" for details
# rotate log files weekly
weekly

# keep 4 weeks worth of backlogs
rotate 4

# 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

# RPM packages drop log rotation information into this directory
include /etc/logrotate.d

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
        minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

# system-specific logs may be also be configured here.
  • 로그 회전 주기를 정하는 설정입니다.
# rotate log files weekly
weekly
yearly : 매년

monthly : 매월

weekly : 매주

daily : 매일
  • 로그 파일 개수
# keep 4 weeks worth of backlogs
rotate 4
정리하는 로그의 개수를 지정
  • 로그파일 생성 설정
# create new (empty) log files after rotating old ones
create
  • 파일명 날짜설정
# use date as a suffix of the rotated file
dateext
dateext를 추가하면 로그 파일의 파일명에 날짜를 넣어 생성
  • 로그파일 압축
# uncomment this if you want your log files compressed
compress
gzip 형태로 압축을 하고, 압축을 하지 않으려면 nocompress로 설정
반응형

'Ops > Monitoring' 카테고리의 다른 글

Elasticsearch 개념정리  (0) 2021.12.16
fluentd 설치 및 설정  (0) 2020.04.07
모니터링 시스템 Prometheus 설치 #2 (docker & grafana )  (0) 2020.02.18
fluentd 설치 (CentOS 7)  (0) 2020.01.10
fluentd 설정 및 도커화 (CentOS 7)  (0) 2020.01.10

관련글 더보기

댓글 영역