컴퓨터/노트북/인터넷
IT 컴퓨터 기기를 좋아하는 사람들의 모임방
조회 수 2594 추천 수 0 댓글 0
단축키
Prev이전 문서
Next다음 문서
단축키
Prev이전 문서
Next다음 문서
설치
$ sudo apt install logrotate
vi /etc/logrotate.conf
## 로그 파일을 순환시킬 기간에 대한 설정 (daily, weekly, monthly, yearly)
# see "man logrotate" for details
# rotate log files weekly
weekly
# use the adm group by default, since this is the owning group
# of /var/log/syslog.
su root adm
## 순환된 로그 파일을 보관할 기간에 대한 설정 (위에서 설정한 기간 단위 설정)
# keep 4 weeks worth of backlogs
rotate 4
## 로그 파일 순환 후 새로운 로그 파일 생성
# create new (empty) log files after rotating old ones
create
## 순환된 파일의 파일명 변경 옵션(YYYYMMDD)
# use date as a suffix of the rotated file
#dateext
## 순환된 파일을 압축하여 보관하는 옵션
# uncomment this if you want your log files compressed
#compress
## 로그 순환에 대한 추가 설정 파일이 저장된 디렉토리
# packages drop log rotation information into this directory
include /etc/logrotate.d
# system-specific logs may be also be configured here.
데몬 기본 정보
- 데몬 위치: /usr/sbin/logrotate
- 데몬 설정 파일 경로: /etc/logrotate.conf
- rotate 기능을 활용하고 싶은 application의 rotate 설정 파일 경로: /etc/logrotate.d/
- 데몬에서 관리되는 log file에 대한 rotate 상태 기록 파일: /var/lib/logrotate/logrotate.status
Application log의 rotate 설정
/etc/logrotate.d/ 경로에 testrotate 파일 생성
/logs/*.log {
rotate 10000
create
daily
missingok
dateext
dateformat -%Y-%m-%d_%H
maxage 14
maxsize 10M
}
- rotate 10000: 로그 파일 개수를 10000개로 유지
- 10000 개가 넘어가면 오래된 파일부터 삭제
- create: 원본 파일이 rotate 되고, 원본 파일 명으로 신규 파일이 생성
- 비활성화 nocreate, 복사본을 만들려면 copy, copy 옵션을 사용할 경우 create 옵션이 적용되지 않음
- daily: 일 단위로 rotate
- weeky, monthly, houly 등 원하는 rotate 기간에 따라 설정
- missingok: 로그 파일이 없는 경우에도 에러 없이 다음으로 넘어감
- nomissingok가 default, 로그 없을 시 error 발생
- dateext: test.log.1 test.log.2처럼 숫자를 붙이는 대신 지정한(dateformat) 날짜 형태의 값으로 확장자를 생성
- dateformat: dateext 옵션과 함께 사용하며, 로그 파일이 rotate될 때, 어떤 형태로 확장자를 생성할 지 설정
- test.log → test.log-2022-10-12_00
- maxage 14: 14일 이상이 지난 로그 파일을 삭제
- maxsize 10M: 10M 이상이 된 로그 파일을 설정된 기간 조건과 관계 없이 rotate
- compress: gzip으로 압축
- nocompress: 압축하지 않음
- size 용량: 지정된 용량이 되면 rotate
- sharedscripts: postrotate ~ endscript 안에 script 가 동작할 때 각각의 로그 마다 실행되는 것이 아니라 1번만 실행되도록 하는 옵션
- notifempty: 로그 파일이 비어있으면 로테이트 하지 않음
- create 640 nginx adm: 로그 파일 새로 생성 시, 파일 권한을 640으로 생성, 소유자/그룹은 nginx
- postrotate: 로테이트 작업이 끝난 후, 실행할 스크립트 입력