메뉴 건너뛰기

Bigdata, Semantic IoT, Hadoop, NoSQL

Bigdata, Hadoop ecosystem, Semantic IoT등의 프로젝트를 진행중에 습득한 내용을 정리하는 곳입니다.
필요한 분을 위해서 공개하고 있습니다. 문의사항은 gooper@gooper.com로 메일을 보내주세요.



/etc/logrotate.d 을 이용한 catalina.out 나누기

 

Apache Tomcat의 로그파일인 catalina.out은 기본적으로 한개의 파일에 로그가 쌓이게 됩니다.


Tomcat을 재시작 하지 않는 이상 계속적으로 쌓이는 듯합니다. 벌써 용량이 후덜덜하네요.
이 파일을 다시는 볼일이 없다면 상관이 없지만...
열어 보려고 한다면... 시간 꽤 걸리듯합니다.
catalina.out의 만행을 그냥 두고 못 본척하신다면... 나중에 눈물 흘릴 수도 있습니다. :")

저도 모니터링 중에 문제가 생겨서 확인하려고 catalina.out 파일을 열어봤더니...
시간이 좀 걸리더군요...

그래서 catalina.out을 나누는 방법을 검색해봤습니다.

로그 파일을 rotate하는 방법에는 보통 4가지가 있습니다.

1. log4j
2. cronolog
3. logrotate
4. shell script


이번 포스트에서는 logrotate에 대하여 알아보겠습니다. 가장 사용하기 쉽고 제가 원하는 동작을 하더군요. :")

구분위치 및 실행 방법설명
데몬(위치)/usr/sbin/logrotate데몬의 위치 및 데몬프로그램
데몬 설정파일/etc/logrotate.conf설정파일
설정디렉토리/etc/logrotate.dlogrotate에 적용할 각종로그파일들 보관하는 디렉토리
상황파일/var/lib/logrotate.statuslogrotate한 작업내역을 보관한 파일
cron(일단위)/etc/cron.daily/logrotatelogrotate는 주기적으로 실행이되어야하므로 cron에 의해 일단위로 실행이 됨


Apache Tomcat 로그 순환 설정 : http://koov.net/blog/?/tag/rotate
위 블로그 가시면 간단히 catalina.out 로그 파일을 자동으로 나누게 설정하는

방법이 있습니다.

$ cd /etc/logrotate.d
$ cat > tomcat

/var/local/tomcat/logs/catalina.out {
copytruncate
daily
rotate 30
missingok
notifempty
}

$ logrotate -f /etc/logrotate.d/tomcat


실행 후 화면,


위 이미지와 같이 catalina.out.1 이라는 파일이 생성되는군요. 흠... 그럼 1, 2, 3 이런식으로 쌓일텐데 관리자의 입장에서는 좀 불편할 수도.... Buuuuuuuuuuut!!!!!

dateext 라는 옵션이 있군요!!!

$ cd /etc/logrotate.d
$ cat > tomcat

/var/local/tomcat/logs/catalina.out {
copytruncate
daily
rotate 30
missingok
notifempty
dateext
}

$ logrotate -f /etc/logrotate.d/tomcat




알아두셔야 할 점은 copytruncate 옵션은 반드시 써야 한다고 합니다.

copytruncate 옵션을 쓰지 않으면 기존의 맨처음 로그가 생성된 파일에 계속해서 로그가 쌓이게 됩니다. 이러한 원인은 톰캣의 로그가 System.err 객체나 System.out을 사용하기 때문에 시스템의 raw디바이스로 출력이 되어 파이프를 타지 않기 때문입니다.
따라서 원래 로그를 다른이름으로 저장하고 새로운 catalina.out을 생성한다해도 실제 로그 스트림은 다른이름으로 지정된 원래 로그쪽으로 계속해서 쌓이게 됩니다.
이걸 방지하기 위해 현재 로그내용을 복사하여 백업본으로 저장한후 원본 로그의 내용을 비우는 방식으로 저장해야 합니다.
그래서 옵션을 copytruncate를 사용해야 합니다.

copytruncate
Truncate the original log file in place after creating a copy, instead of moving the old log file and optionally creating a new one, It can be used when some program can not be told to close its logfile and thus might continue writing (appending) to the previous log file forever. Note that there is a very small time slice between copying the file and truncating it, so some logging data might be lost. When this option is used, the create option will have no effect, as the old log file stays in place.




logrotate의 설정 옵션에 대하여 조금 더 알아보면은,

dailyLog files are rotated every day.
weeklyLog files are rotated if the current weekday is less than the weekday of the last rotation or if more than a week has passed since the last rotation. This is normally the same as rotating logs on the first day of the week, but if logrotate is not being run every night a log rotation will happen at the first valid opportunity.
monthlyLog files are rotated the first time logrotate is run in a month (this is normally on the first day of the month).
notifemptyDo not rotate the log if it is empty (this overrides the ifempty option).
nocompressOld versions of log files are not compressed.
delaycompressPostpone compression of the previous log file to the next rotation cycle. This only has effect when used in combination with compress. It can be used when some program cannot be told to close its logfile and thus might continue writing to the previous log file for some time.
compressOld versions of log files are compressed with gzip by default.
mail addressWhen a log is rotated out of existence, it is mailed to address. If no mail should be generated by a particular log, the nomail directive may be used.
missingokIf the log file is missing, go on to the next one without issuing an error message.


보다 더 많은 옵션과 설명을 보시려면, http://linuxcommand.org/man_pages/logrotate8.html를 참고하세요.

superuser 사이트입니다. 옵션에 대해서 한글로 자세히 설명되어 있습니다.
http://www.superuser.co.kr/linux/logrotate/page04.htm

번호 제목 글쓴이 날짜 조회 수
740 [CDP7.1.7] oozie sqoop action으로 import혹은 export수행시 발생한 오류에 대한 자세한 로그 확인 하는 방법 gooper 2024.04.19 0
739 [Impala] alter table구문수행시 "WARNINGS: Impala does not have READ_WRITE access to path 'hdfs://nameservice1/DATA/Temp/DB/source/table01_ccd'" 발생시 조치 gooper 2024.04.26 0
738 [CDP7.1.7, Replication]Encryption Zone내 HDFS파일을 비Encryption Zone으로 HDFS Replication시 User hdfs가 아닌 hadoop으로 수행하는 방법 gooper 2024.01.15 1
737 [CDP7.1.7]Hive Replication수행중 Specified catalog.database.table does not exist : hive.db명.table명 오류 발생시 조치방법 gooper 2024.04.05 1
736 [CDP7.1.7][Replication]Table does not match version in getMetastore(). Table view original text mismatch gooper 2024.01.02 2
735 ./gradlew :composeDown 및 ./gradlew :composeUp 를 성공했을때의 메세지 gooper 2023.02.20 6
734 호출 url현황 gooper 2023.02.21 6
733 [vue storefrontui]외부 API통합하기 참고 문서 총관리자 2022.02.09 7
732 [Cloudera Agent] Metadata-Plugin throttling_logger INFO (713 skipped) Unable to send data to nav server. Will try again. gooper 2022.05.16 7
731 [CDP7.1.7, Hive Replication]Hive Replication진행중 "The following columns have types incompatible with the existing columns in their respective positions " 오류 gooper 2023.12.27 7
730 [CDP7.1.7]Oozie job에서 ERROR: Kudu error(s) reported, first error: Timed out: Failed to write batch of 774 ops to tablet 8003f9a064bf4be5890a178439b2ba91가 발생하면서 쿼리가 실패하는 경우 gooper 2024.01.05 7
729 eclipse editor 설정방법 총관리자 2022.02.01 9
728 주문히스토리 조회 총관리자 2022.04.30 10
727 [bitbucket] 2022년 3월 2일 부터 git 작업시 기존에 사용하던 비빌번호를 사용할 수 없도록 변경되었다. 총관리자 2022.04.30 10
726 oozie의 sqoop action수행시 ooize:launcher의 applicationId를 이용하여 oozie:action의 applicationId및 관련 로그를 찾는 방법 gooper 2023.07.26 10
725 주문 생성 데이터 예시 총관리자 2022.04.30 11
724 [EncryptionZone]User:testuser not allowed to do "DECRYPT_EEK" on 'testkey' gooper 2023.06.29 11
723 [CDP7.1.7]Encryption Zone내부/외부 간 데이터 이동(mv,cp)및 CTAS, INSERT SQL시 오류(can't be moved into an encryption zone, can't be moved from an encryption zone) gooper 2023.11.14 11
722 [CDP7.1.7]impala-shell수행시 간헐적으로 "-k requires a valid kerberos ticket but no valid kerberos ticket found." 오류 gooper 2023.11.16 11
721 [Encryption Zone]Encryption Zone에 생성된 table을 select할때 HDFS /tmp/zone1에 대한 권한이 없는 경우 gooper 2023.06.29 12

A personal place to organize information learned during the development of such Hadoop, Hive, Hbase, Semantic IoT, etc.
We are open to the required minutes. Please send inquiries to gooper@gooper.com.

위로