Sysops Notepad

Centos 7 logrotate를 사용한 로그 관리 하기 본문

업무/sys

Centos 7 logrotate를 사용한 로그 관리 하기

sysops 2018. 6. 6. 12:57

로그가 엄청나가 많이 쌓인다구요 ?


걱정 마세요


우리에겐 logrotate가 있으니까요!


logrotate란 messages 나 wtmp등 system log 뿐만 아니라 각종 오픈소스들 log , user log까지도 모두 관리가 됩니다!


저는 아래 예제를 참고해서  logrotate를 통해서 log들을 압축을 해보세요!


 -------------------------------------------------------------------------------------

* 테스트 환경 : centos 7.5 


1. yum install logrotate


- 보통 기본 설치되어 있습니다!


2. vi /etc/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
}

/var/log/test/testmessages {
    weekly
    create 0664 root root
    rotate 4

    compress
}


# 주마다 쌓인 로그를 압축하여  testmessages.yyymmdd 포멧으로 저장하며 4주간 보관




3. logrotate -f /etc/logrotate.conf  

- 바로 적용시키기


-------------------------------------------------------------------------------------


추가로 옵션으로는 


monthly : 월 단위

daily : 일 단위

weekly : 주 단위

maxsize :최대사이즈

minsize : 최소사이즈

nocompress : 압축


등이 있으며  한파일에만 라인을 추가할 필요 없이 /etc/logrotate.d/ 디렉토리 밑에 파일을 생성하여 같은 포맷으로 작성하셔도 설정 가능합니다!



끝!

Comments