본문 바로가기
자격증

[리눅스마스터 1급] 7. 시스템 분석

by LimSeongHyeon 2025. 4. 19.

 


로그 파일과 명령어

분류 경로 설명 관련 명령어
System /messages 시스템 전반의 일반 로그 메시지  
/boot.log 부팅 시 발생한 메시지 기록  
/kern 커널 관련 메시지 로그 dmesg
/dmesg 부팅 시 커널 링버퍼 메시지 기록 dmesg
/cron cron 작업 실행 기록  
/yum.log yum 패키지 설치/제거 기록  
Login /secure 사용자 인증 및 보안 관련 로그 (SSH 등)  
/faillog 로그인 실패 이력  
/lastlog 사용자별 마지막 로그인 기록 lastlog
/wtmp 로그인/로그아웃, 시스템 부팅/종료 기록 last
/btmp 비정상 로그인 시도 (로그인 실패 기록) lastb
/utmp 현재 로그인한 사용자 정보  
Service /maillog 메일 서비스 로그 (Postfix, Sendmail 등)  
/httpd/ Apache 웹서버 액세스/에러 로그 디렉토리  
/mysql.log MySQL 서비스 로그 (설정에 따라 다름)  
/xferlog FTP 전송 로그  

 

/var/log에 로그 파일들이 모두 모여있으니 해당 디렉토리에서 파일명으로 유추하면 될 것 같다.
참고로 btmp나 lastb의 b는 bad로 실패를 의미한다.

rsyslog (로그 관리)

/etc/rsyslog.conf에 환경설정 내용이 정의되어 있다. /etc/rc.d/init.d/rsyslog는 rsyslogd를 실행하는 스크립트로 구성되어 있으며 최종적으로 /sbin/rsyslogd가 실행되면서 rsyslog가 작동하기 시작한다.

 

관련 파일 찾기
$ locate -i /etc/*rsyslog*
/etc/rsyslog.conf
/etc/rsyslog.d

$ locate -i rsyslogd
/run/rsyslogd.pid
/usr/lib/dracut/modules.d/98syslog/rsyslogd-start.sh
/usr/lib/dracut/modules.d/98syslog/rsyslogd-stop.sh
/usr/sbin/rsyslogd
/usr/share/man/man8/rsyslogd.8.gz

 

 

rsyslog.conf

- Global Directives: rsyslogd의 전역 설정을 담당한다.
- Tmplates: 로그 메세지의 format을 보관한다.
- Output Channels: 출력 채널에 대한 설정을 저장하고 불러올 수 있게 한다.
- Rules: 로그 출력 규칙에 대해서 정의한다.
$ man rsyslog.conf
rsyslog.conf 파일에 대한 메뉴얼이 자세히 나와있다. 때문에 하단의 Rules에 대한 설명을 보기 전, man rsyslog.conf의 내용들을 살펴보도록 하자. (특히 SELECTORS, ACTIONS 영역을 살펴보도록 하자.)

 

 

Rules

  • Facility: 로그를 발생시키는 주체를 의미한다. (Input)
  • Priority: 로그 메시지의 수준을 의미한다. 만약 로그 메시지의 수준에 대한 필터가 불가능하다면 쓸모없는 내용까지 로그에 작성되므로 로그 추적 및 로그 보관이 어려워질 것이다. (Filter)
  • Action: 해당 로그를 어떻게 사용할지에 대한 내용이 담긴다. (Output)

 

Facility
$ man rsyslog.conf | grep -A 5 "The  facility"
       The  facility  is  one  of  the following keywords: auth, authpriv, cron, daemon, kern, lpr, mail, mark, news, security
       (same as auth), syslog, user, uucp and local0 through local7. The keyword security should not be used anymore and  mark
       is  only  for internal use and therefore should not be used in applications.  Anyway, you may want to specify and redi‐
       rect these messages here. The facility specifies the subsystem that produced the message, i.e. all  mail  programs  log
       with the mail facility (LOG_MAIL) if they log using syslog.
facility에서 사용 가능한 keywords를 안내해주고 있다. 기억이 안날때 정말 유용하게 사용이 가능하다.

keywords: auth, authpriv, cron, daemon, kern, lpr, mail, mark, news, security (same as auth), syslog, user, uucp and local0 through local7

 

 

Priority

 

$ man rsyslog.conf | grep -A 3 "The  priority"
       The  priority  is  one of the following keywords, in ascending order: debug, info, notice, warning, warn (same as warn‐
       ing), err, error (same as err), crit, alert, emerg, panic (same as emerg). The keywords error, warn and panic are  dep‐
       recated and should not be used anymore. The priority defines the severity of the message.
none을 제외한 priority의 keywords가 man에 제시되고 있다.

 

 

Action
유형 형식 예시
파일에 기록 파일 경로 /var/log/custom-logfile
TTY로 전송 터미널 경로 /dev/tty1
UDP로 전송 @[IP] @192.168.0.1
TCP로 전송 @@[IP] @@10.0.0.2:514
유저에게 브로드캐스트 omusrmsg:[user-name] omusrmsg:*
omusrmsg:lim
Action은 따로 확인할 방법이 마땅치 않기 때문에 인지하고 있는 것이 좋다.

 


logrotate (로그 용량 관리)

logrotate는 기본적으로 /etc/logrotate.conf에 설정 항목들이 기록되어 있으며 해당 설정 과정 중 /etc/logrotate.d 내부의 설정들을 import하게 된다. 이런 설정 값들이 cron.daily/logrotate 스크립트 내부 동작에서 반영되며 cron은 해당 스크립트를 하루마다 호출하여 logrotate를 수행하도록 만든다.

 

logrotate.conf
$ cat /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

# system-specific logs may be also be configured here.

 

rotate 주기

roate되는 주기를 설정할 수 있다. 설정 값에는 [daily, weekly, monthly, yearly]가 있다. 위에서 언급했듯 logrotate는 cron이 하루에 한번 동작하기 때문에 하루보다 긴 주기에 대해서 설정이 가능하다.

 

 

rotate 저장 전략

rotate된 파일의 최대 보유 개수를 의미한다. rotate된 파일을 저장하는 방식은 위와 같다. logrotate에 의해 새로운 로그 백업이 생성되는 경우 가장 마지막(오래된) 로그를 삭제하고 log3을 log4로, log2를 log3로, log1을 log2로 한칸씩 밀어낸다. 이후 app.log를 app.log1에 저장하고 app.log의 내용을 reset하면 rotate작업이 완료된다. 여기서 포인트는 log4는 가장 오래된, log1은 가장 최신의 로그를 유지한다는 점이다.
app.log의 내용을 reset하는 작업은 create 옵션으로 명시된다.

 

 

특정 로그에 대하여 rotate

[root@c47bd92e06fb ~]# cat /etc/logrotate.d/wtmp
# no packages own wtmp -- we'll rotate it here
/var/log/wtmp {
    missingok
    monthly
    create 0664 root utmp
    minsize 1M
    maxsize 1G
    rotate 5
}

 

missingok: 로그파일이 확인되지 않더라도 별다른 에러없이 넘어가는 것을 의미한다.
monthly: 한달에 한번 로테이션을 진행한다.
create 0664 root utmp: 로그 파일이 생성될 때 갖게되는 파일 권한을 의미한다.
minsize 1M: 로그파일이 최소한 1MB보다 커야하며 이 이전에는 로테이션이 진행되지 않는다.
maxsize 1G: 로그파일이 1GB 초과 시, 로테이션이 진행되며 이는 주기의 영향을 받지 않는다.
rotate 5: 최대 로테이트된 로그 보유 개수를 5개로 지정한다.

journalctl (로그 확인)

$ journalctl --help
journalctl [OPTIONS...] [MATCHES...]

Query the journal.

Options:
     --system                Show the system journal
     --user                  Show the user journal for the current user
  -M --machine=CONTAINER     Operate on local container
  -S --since=DATE            Show entries not older than the specified date
  -U --until=DATE            Show entries not newer than the specified date
  -c --cursor=CURSOR         Show entries starting at the specified cursor
     --after-cursor=CURSOR   Show entries after the specified cursor
     --show-cursor           Print the cursor after all the entries
  -b --boot[=ID]             Show current boot or the specified boot
     --list-boots            Show terse information about recorded boots
  -k --dmesg                 Show kernel message log from the current boot
  -u --unit=UNIT             Show logs from the specified unit
     --user-unit=UNIT        Show logs from the specified user unit
  -t --identifier=STRING     Show entries with the specified syslog identifier
  -p --priority=RANGE        Show entries with the specified priority
  -g --grep=PATTERN          Show entries with MESSAGE matching PATTERN
     --case-sensitive[=BOOL] Force case sensitive or insenstive matching
  -e --pager-end             Immediately jump to the end in the pager
  -f --follow                Follow the journal
  -n --lines[=INTEGER]       Number of journal entries to show
     --no-tail               Show all lines, even in follow mode
  -r --reverse               Show the newest entries first
  -o --output=STRING         Change journal output mode (short, short-precise,
                               short-iso, short-iso-precise, short-full,
                               short-monotonic, short-unix, verbose, export,
                               json, json-pretty, json-sse, cat, with-unit)
     --output-fields=LIST    Select fields to print in verbose/export/json modes
     --utc                   Express time in Coordinated Universal Time (UTC)
  -x --catalog               Add message explanations where available
     --no-full               Ellipsize fields
  -a --all                   Show all fields, including long and unprintable
  -q --quiet                 Do not show info messages and privilege warning
     --no-pager              Do not pipe output into a pager
     --no-hostname           Suppress output of hostname field
  -m --merge                 Show entries from all available journals
  -D --directory=PATH        Show journal files from directory
     --file=PATH             Show journal file
     --root=ROOT             Operate on files below a root directory
     --interval=TIME         Time interval for changing the FSS sealing key
     --verify-key=KEY        Specify FSS verification key
     --force                 Override of the FSS key pair with --setup-keys

Commands:
  -h --help                  Show this help text
     --version               Show package version
  -N --fields                List all field names currently used

문제

기본 로그 파일 및 명령어

 

파일

1) 시스템에 발생하는 표준 메세지가 기록되는 로그 파일 전체 경로를 작성하세요.
2) 로그인 / 로그아웃, 시스템 이벤트의 기록 로그를 저장하는 로그 파일의 전체 경로를 작성하세요.
3) 불법 로그인 (로그인 실패)에 대한 정보를 기록하는 로그 파일의 전체 경로를 작성하세요.
4) 현재 로그인 중인 사용자 정보를 기록하는 로그 파일의 전체 경로를 작성하세요.
5) 인증 기반의 접속(telnet, ssh 등)과 관련된 로그가 기록되는 로그 파일의 전체 경로를 작성하세요.
6) 메일 서비스와 관련된 로그가 기록되는 로그 파일의 전체 경로를 작성하세요.
7) 부팅과 관련된 로그가 기록되는 로그 파일의 전체 경로를 작성하세요.
더보기

1) /var/log/messages

2) /var/log/wtmp

3) /var/log/btmp

4) /var/log/utmp

5) /var/log/secure

6) /var/log/maillog

7) /var/log/boot.log

 

 

명령어

1) 시스템 로그에 메시지를 기록하는 명령어를 작성하세요.
2) 최근 3일 동안 로그인한 사용자의 기록을 출력하는 명령어를 작성하세요.
3) reduser 사용자가 로그인한 정보를 출력하는 명령어를 작성하세요.
4) reduser 사용자가 로그인에 실패한 정보를 출력하는 명령어를 작성하세요.
5) reduser 사용자의 마지막 로그인 정보만 출력하는 명령어를 작성하세요.
더보기

1) logger

2) lastlog -t 3

3) last reduser

4) lastb reduser

5) lastlog -u reduser


 

시스템 로그

 


 

로그 로테이션