Logcheck

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Logcheck and the translation is 39% complete.
Outdated translations are marked like this.

이 안내서는 logcheck를 이용하여 시스템 로그를 분석하는 방법을 알려드립니다.

logcheck로 시작하기

배경

app-admin/logcheck는 시스템 로그를 분석하는 도구인 app-admin/logsentry의 개선 버전입니다. 게다가 logcheck 는 일반적으로 내장 데이터베이스가 딸려오며, 관심 없는 잡다한 로그 메시지를 걸러냅니다. 이 도구의 일반 개념은 불필요한 내용으로 간주된 메시지를 제외한 모든 메시지에 관심이 있는걸로 간주합니다. logcheck은 주기적으로 관심있는 내용의 요약본을 이메일로 송부합니다.

logcheck 설치

중요
logsentry를 시스템에 설치했다면 제거하는걸 추천합니다. 게다가, 권한 위반과 파일 충돌 문제를 해결하려면 /etc/logcheck를 제거해야 합니다.
root #emerge -c logsentry
root #rm -rf /etc/logcheck

이제 logcheck 설치를 수행할 수 있습니다.

root #emerge --ask app-admin/logcheck

기본 설정

app-admin/logcheck는 루트 실행을 막기 위해 "logcheck" 사용자를 따로 만듭니다. 실제로 루트 계정으로 실행하는 동작을 막습니다. 로그 분석을 하도록 하려면 logcheck가 읽을 수 있게 해야 합니다. app-admin/syslog-ng의 예제입니다:

파일 /etc/syslog-ng/syslog-ng.conf/etc/syslog-ng/syslog-ng.conf 일부
options {
        owner(root);
  
        ## (Make log files group-readable by logcheck)
        group(logcheck);
        perm(0640);
};

이제 설정을 다시 불러온 후 기대한 바대로 동작하는지 확인하십시오.

root #/etc/init.d/syslog-ng 다시 불러오기
root #ls -l /var/log/messages
-rw-r----- 1 root logcheck 1694438 Feb 12 12:18 /var/log/messages

이제 /etc/logcheck/logcheck.conf 에 있는 기본 logcheck 설정을 건드려야 합니다.

파일 /etc/logcheck/logcheck.conf/etc/logcheck/logcheck.conf 기본 설정
# Controls the level of filtering:
# Can be Set to "workstation", "server" or "paranoid" for different
# levels of filtering. Defaults to server if not set.
## (The workstation level includes server, and server includes paranoid.
The paranoid level filters almost no messages)
REPORTLEVEL="server"
  
# Controls the address mail goes to:
# *NOTE* the script does not set a default value for this variable!
# Should be set to an offsite "emailaddress@some.domain.tld"
## (Make sure you can receive the logcheck e-mails. Testing is strongly
recommended)
SENDMAILTO="root"
  
# Controls if syslog-summary is run over each section.
# Alternatively, set to "1" to enable extra summary.
# HINT: syslog-summary needs to be installed.
## (If you get a lot of similar messages in the logs, you
may want to install app-admin/syslog-summary and enable
this setting)
SYSLOGSUMMARY=0

어떤 로그 파일(/etc/logcheck/logcheck.logfiles)을 검색해야 하는지 logcheck에게 알려야 합니다.

파일 /etc/logcheck/logcheck.logfiles/etc/logcheck/logcheck.logfiles 기본 설정
## (This is an example for syslog-ng)
/var/log/messages

Enable periodical log check

마지막으로, 크론 잡에서 logcheck를 활성화 하십시오.

Cron users

If logcheck is emerged with the "cron" USE flag enabled, it can read /etc/cron.hourly/logcheck.cron

파일 /etc/cron.hourly/logcheck.cronBasic /etc/cron.hourly/logcheck.cron
#!/bin/sh
#
# To enable sync via cron, execute "sudo -u logcheck touch /etc/logcheck/cron-logcheck-enabled"
if [[ ! -f /etc/logcheck/cron-logcheck-enabled ]]; then
    exit
fi
if [ ! -d /var/lock/logcheck ]; then
    mkdir -p /var/lock/logcheck
    chown logcheck:logcheck /var/lock/logcheck
fi
sudo -u logcheck nice -n10 /usr/sbin/logcheck

To enable an hourly cron job, run:

root #sudo -u logcheck touch /etc/logcheck/cron-logcheck-enabled
참고
크론에 대한 더 많은 내용은 크론 안내서를 보십시오.

Systemd users

If logcheck is emerged with "systemd" USE flag enabled, a logcheck.timer can be activated running:

root #systemctl enable --now logcheck.timer

축하합니다! 이제 이메일로 중요한 로그 메시지를 받아 보실 수 있습니다. 예제 메시지는 다음과 같습니다:

코드 logcheck 메시지 예제
System Events
=-=-=-=-=-=-=
Feb 10 17:13:53 localhost kernel: [30233.238342] conftest[25838]: segfault at 40 ip 40061403 sp bfc443c4 error 4
in libc-2.10.1.so[4003e000+142000]
Feb 11 12:31:21 localhost postfix/pickup[18704]: fatal: could not find any active network interfaces
Feb 11 12:31:22 localhost postfix/master[3776]: warning: process //usr/lib/postfix/pickup pid 18704 exit status 1
Feb 11 12:31:22 localhost postfix/master[3776]: warning: //usr/lib/postfix/pickup: bad command startup -- throttling

문제 해결

일반적인 요령

다음과 같이 더 많은 디버깅 정보를 표시하려 한다면 logcheck의 -d 스위치를 사용할 수 있습니다:

root #su -s /bin/bash -c '/usr/sbin/logcheck -d' logcheck
D: [1281318818] Turning debug mode on
D: [1281318818] Sourcing - /etc/logcheck/logcheck.conf
D: [1281318818] Finished getopts c:dhH:l:L:m:opr:RsS:tTuvw
D: [1281318818] Trying to get lockfile: /var/lock/logcheck/logcheck.lock
D: [1281318818] Running lockfile-touch /var/lock/logcheck/logcheck.lock
D: [1281318818] cleanrules: /etc/logcheck/cracking.d/kernel
...
D: [1281318818] cleanrules: /etc/logcheck/violations.d/su
D: [1281318818] cleanrules: /etc/logcheck/violations.d/sudo
...
D: [1281318825] logoutput called with file: /var/log/messages
D: [1281318825] Running /usr/sbin/logtail2 on /var/log/messages
D: [1281318825] Sorting logs
D: [1281318825] Setting the Intro
D: [1281318825] Checking for security alerts
D: [1281318825] greplogoutput: kernel
...
D: [1281318825] greplogoutput: returning 1
D: [1281318825] Checking for security events
...
D: [1281318825] greplogoutput: su
D: [1281318825] greplogoutput: Entries in checked
D: [1281318825] cleanchecked - file: /tmp/logcheck.uIFLqU/violations-ignore/logcheck-su
D: [1281318825] report: cat'ing - Security Events for su
...
D: [1281318835] report: cat'ing - System Events
D: [1281318835] Setting the footer text
D: [1281318835] Sending report: 'localhost 2010-08-09 03:53 Security Events' to root
D: [1281318835] cleanup: Killing lockfile-touch - 17979
D: [1281318835] cleanup: Removing lockfile: /var/lock/logcheck/logcheck.lock
D: [1281318835] cleanup: Removing - /tmp/logcheck.uIFLqU

This page is based on a document formerly found on our main website gentoo.org.
The following people contributed to the original document: phajdan.jr, nightmorph
They are listed here because wiki history does not allow for any external attribution. If you edit the wiki article, please do not add yourself here; your contributions are recorded on each article's associated history page.