[시스템 관리] 05. 로그 관리 - logwatch

Date:     Updated:

카테고리:

태그:


🔔 로그 로테이션 - logwatch


logwatch 는 Linux 용 시스템 로그 모니터링 프로그램으로 시스템 로그중 중요하다고 판단되는 내용만을 뽑아서 결과를 정기적으로 root 에게 email 로 전송해 주는 역할을 수행한다.


■ logwatch 설치

# CentOS (RHEL 계열)
yum -y install logwatch
# Ubuntu (Debian 계열)
apt -y install logwatch


■ logwatch - nginx 설정

nginx의 로그 정보는 http와 거의 동일하기 때문에 http용 설정 파일을 복사한 다음 편집해서 설정파일로 작성한다.

{
    cp /usr/share/logwatch/default.conf/services/http.conf /etc/logwatch/conf/services/nginx.conf
    cp /usr/share/logwatch/scripts/services/http /etc/logwatch/scripts/services/nginx
    cp /usr/share/logwatch/default.conf/logfiles/http.conf /etc/logwatch/conf/logfiles/nginx.conf
}
# /etc/logwatch/conf/services/nginx.conf 파일 내용 변경

Title = "nginx"
# Which logfile group...
LogFile = nginx
# /etc/logwatch/conf/logfiles/nginx.conf 파일 내용 변경

~(생략)~
# What actual file?  Defaults to LogPath if not absolute path....
#LogFile = httpd/*access_log
#LogFile = apache/*access.log.1
#LogFile = apache/*access.log
#LogFile = apache2/*access.log.1
#LogFile = apache2/*access.log
#LogFile = apache2/*access_log
#LogFile = apache-ssl/*access.log.1
#LogFile = apache-ssl/*access.log
#LogFile = nginx/*access.log
#LogFile = nginx/*access.log.1
LogFile = /var/log/nginx/*access.log
LogFile = /var/log/nginx/*access.log.1


# If the archives are searched, here is one or more line
# (optionally containing wildcards) that tell where they are...
#If you use a "-" in naming add that as well -mgt
#Archive = archiv/httpd/*access_log.*
#Archive = httpd/*access_log.*
#Archive = apache/*access.log.*.gz
#Archive = apache2/*access.log.*.gz
#Archive = apache2/*access_log.*.gz
#Archive = apache-ssl/*access.log.*.gz
#Archive = archiv/httpd/*access_log-*
#Archive = httpd/*access_log-*
#Archive = apache/*access.log-*.gz
#Archive = apache2/*access.log-*.gz
#Archive = apache2/*access_log-*.gz
#Archive = apache-ssl/*access.log-*.gz
#Archive = nginx/*access.log.*.gz
Archive = /var/log/nginx/*access.log.*.gz

# Expand the repeats (actually just removes them now)
*ExpandRepeats


# Keep only the lines in the proper date range...
*ApplyhttpDate

# vi: shiftwidth=3 tabstop=3 et
설정 내용
LogFile 감시할 로그 파일명을 지정
Archive 아카이브로 처리된 로그 파일명을 지정 (로케이션된 파일명)


■ logwatch - nginx 테스트

$ logwatch --service nginx --range all

 ################### Logwatch 7.4.3 (04/27/16) ####################
        Processing Initiated: Sun Jul 30 20:11:32 2023
        Date Range Processed: all
        Detail Level of Output: 0
        Type of Output/Format: stdout / text
        Logfiles for Host: dlp.test.srv
 ##################################################################

 --------------------- nginx Begin ------------------------

 Requests with error response codes
    403 Forbidden
       /test/: 2 Time(s)
    404 Not Found
       /test/: 5 Time(s)
       /test/nginx-logo.png: 5 Time(s)
       /test/poweredby.png: 5 Time(s)
       /test212121: 1 Time(s)

 ---------------------- nginx End -------------------------


 ###################### Logwatch End #########################
설정 내용
–service 서비스명 지정
–ragne 로그의 분석 범위를 지정


■ logwatch - cron 설정

logwatch의 cron 설정은 설치할 때 /etc/cron.daily/0logwatch라는 Shell 스크립트 파일로 설치되어 있으며, 매일 자동으로 실행되도록 설정되어 있으므로 별도로 cron 설정을 하지 않아도 된다.

logwatch의 리포트를 확인해 보면 완벽하지는 않지만 해당 리포트에 있는 작은 징후를 놓치지 않으려고 노력하면 문제를 조기에 검출할 수 있다.

SYS_MGMT 카테고리 내 다른 글 보러가기

댓글 남기기