- 로그 순환 , LogRotate : linux ubuntu process log file rotation setting
    - 매뉴얼 
How to Setup and Manage Log Rotation Using Logrotate in Linux 
https://www.tecmint.com/install-logrotate-to-manage-log-rotation-in-linux/ 
https://linuxconfig.org/logrotate-8-manual-page 
https://nerd-mix.tistory.com/36 
//-------------------------------------
< 지시어 >
daily : 매일 순환 , (weekly ,monthly, yearly) 
rotate 숫자 :  순환되어 생성될 파일 최대수 
compress :  순환된 로그파일 압축(gzip) 
delaycompress  : 바로 이전 로그파일은 압축하지 않음 
dateext :  로그파일에  날짜 YYYYMMDD형식의 확장자 추가 
dateformat -%Y%m%d   : 날짜 형식 지정 
mail 메일주소 : 로테이트 설정에 의해 보관주기가 끝난 파일을 이메일 전송 
mailfirst 메일주소 : 로테이트시 신규파일 이전의 로그를 이메일 전송 
nomail : 메일로 통보받지 않음. 
errors 메일주소 : 로테이트 실행시 에러가 발생하면 이메일 전송 
maxage 일 :  지정된 일수가 지난 백업 파일 삭제 
missingok :  로그파일이 없을 경우에도 에러 처리하지 않는다
size 사이즈 :  지정한 크기보다 크면 순환, (100, 100k, 100M , 100G )
    - 주의! 지정한 크기에 도달하지 않으면 로테이션 실행 안함
ifempty :  로그파일이 비어있어도 순환 
notifempty   :  파일의 사이즈가 0이면, rotate 하지 않음 
sharedscripts  :  와일드카드 패턴과 일치하는 로그 수에 관계없이 스크립트를 한 번만 실행 
prerotate : 로테이트 전에 실행할 스크립트  
postrotate : 로테이트 후에 실행할 스크립트  
create 파일모드 유저 그룹 : 로그파일 모드 유저 그룹 지정 
extension 확장자  : 로테이트 후 생성되는 파일의 확정자를 지정 ex) .log  <== 점 포함해서 기입
copytruncate : 로그 복사후, 원본 로그 파일 크기를 0으로 자름 ( copy -> truncate) 
    - create 설정이 무시됨, 주의! 미세한 로그 공백기가 생길수 있음
    - 기본 동작 :  move -> create 
//------------------------------------- 
    - logrotate 설치 
$ sudo apt update 
$  sudo apt install logrotate 
$  logrotate --version
    - 기본 설정 파일 
/etc/logrotate.conf 
    - 프로그램 별 설정 파일이 있는 폴더 
/etc/logrotate.d 
//------------------------------------- 
    - /etc/logrotate.d/nginx 파일 내용
//
/var/log/nginx/*.log {
        daily
        missingok
        rotate 14
        compress
        delaycompress
        notifempty
        create 0640 www-data adm
        sharedscripts
        prerotate
                if [ -d /etc/logrotate.d/httpd-prerotate ]; then \
                        run-parts /etc/logrotate.d/httpd-prerotate; \
                fi \
        endscript
        postrotate
                invoke-rc.d nginx rotate >/dev/null 2>&1
        endscript
}
//------------------------------------- 
    - 설정 파일 실행(테스트) 
logrotate -d -v /etc/logrotate.d/설정파일 
        -d : 테스트만 하고 실제 실행은 하지 않음(디버깅용) 
        -v : 상세 정보 표시 
        -f : 강제 실행 , d 옵션과 함께 사용하지 않는다
//------------------------------------- 
    - 에러 메시지 :  "parent directory has insecure permissions" 
설정 파일에 "su 소유자 그룹" 추가  create 에서 설정된 내용 
예) su www-data www-data 
//------------------------------------- 
    - 에러 메시지 :  "log does not need rotating"  
- 해결 방법 : 로그 파일 크기가 작아서 순환 실행할 필요가 없을때 메시지,  테스트한다면 -f 옵션으로 강제 실행 
'IT' 카테고리의 다른 글
| 닌텐도 스위치 비행슈팅게임 (사이쿄 컬렉션) (0) | 2022.05.19 | 
|---|---|
| [Linux] supervisor 에러 해결 방법 (0) | 2022.05.09 | 
| 안드로이드 컬러노트 앱 백업 파일 경로 (0) | 2022.04.17 | 
| 안드로이드 Nearby Share 사용법 (0) | 2022.04.17 | 
| HEIC, HEIF 이미지 파일 보기, 포맷 변환 (0) | 2022.04.17 | 










