로그파일이란 간단히 정리하면 켜지고 나서 종료될 때까지 OS상에서 발생되는 모든 이벤트를 기록해놓은 파일이라고 할 수 있다.
그렇다면 로그파일이 왜 중요할까?
다양한 로그를 이용해 시스템 상태를 체크하거나 장애가 발생했을 경우 원인을 추적하는데 유용하게 사용할 수 있기 때문이다.
뿐만아니라, 최근에는 IT Compliance가 강조되면서 로그파일의 보존이 더욱 중요해졌다.
/var은 시스템을 운영할 때 발생되는 로그가 위치한 디렉토리이다.
리눅스 환경에서는 대부분 /var/log
경로에 로그파일이 위치하지만 경로와 룰에 대한 상세정보는 /etc/rsyslog.conf
에서 관리한다.
vim /etc/rsyslog.conf
# rsyslog v5 configuration file
# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html
#### MODULES ####
$ModLoad imuxsock # provides support for local system logging (e.g. via logger command)
$ModLoad imklog # provides kernel logging support (previously done by rklogd)
#$ModLoad immark # provides --MARK-- message capability
# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514
# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514
#### GLOBAL DIRECTIVES ####
# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on
# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf
#### RULES ####
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
# The authpriv file has restricted access.
authpriv.* /var/log/secure
# Log all the mail messages in one place.
mail.* -/var/log/maillog
# Log cron stuff
cron.* /var/log/cron
# Everybody gets emergency messages
*.emerg *
# Save news errors of level crit and higher in a special file.
uucp,news.crit /var/log/spooler
# Save boot messages also to boot.log
local7.* /var/log/boot.log
# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$WorkDirectory /var/lib/rsyslog # where to place spool files
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList # run asynchronously
#$ActionResumeRetryCount -1 # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###
로그이름 | 로그 파일명 | 관련 데몬 | 간략한 설명 |
---|---|---|---|
커널 로그 | /dev/console | kernel | 콘솔에 뿌려지는 로그 |
시스템 로그 | /var/log/messages | syslogd | 리눅스 커널 로그 및 주된 로그 |
보안 로그 | /var/log/secure | xinetd | 보안 인증 관련 로그 |
메일 로그 | /var/log/maillog | sendmail popper | 메일 로그(sendmail에 의한 로그) |
크론 로그 | /var/log/cron | crond | crond에 의한 로그 |
부팅 로그 | /var/log/boot.log | kernel | 시스템 부팅 시의 로그 |
커널 부트 메세지 로그 | /var/log/dmesg | kernel | 부팅될 당시의 각종 메세지들 저장 |
커널 로그 | /var/log/wtmp | kernel | 시스템 전체 로그인 기록 저장 |
커널 로그 | /var/log/utmp | kernel | 현재 로그인 사용자에 대한 기록, 사용자 IP저장 |
FTP 로그 | /var/log/xferlog | ftpd | FTP 로그 |
웹 로그 | /var/log/httpd/access_log | httpd | 아파치(웹서버) 로그 저장 |
웹 로그 | /var/log/httpd/error_log | httpd | 아파치(웹서버) 에러 로그 저장 |
네임서버 로그 | /var/log/named.log | named | 네임서버(DNS) 로그 |
Mar 9 03:10:01 localhost rsyslogd: [origin software="rsyslogd" swVersion="5.8.10" x-pid="1687" x-info="http://www.rsyslog.com"] rsyslogd was HUPed
Mar 9 03:28:11 localhost dhclient[1770]: DHCPREQUEST on eth1 to 192.168.0.1 port 67 (xid=0x6b4e1cbb)
Mar 9 03:28:11 localhost dhclient[1770]: DHCPACK from 192.168.0.1 (xid=0x6b4e1cbb)
Mar 9 03:28:11 localhost dhclient[1770]: bound to 192.168.0.39 -- renewal in 3317 seconds.
Mar 9 03:28:11 localhost NetworkManager[1752]: <info> (eth1): DHCPv4 state changed bound -> renew
[root@zetawiki ~]# cat /var/log/maillog
... (생략)
Aug 27 04:04:07 localhost postfix/postfix-script[2248]: starting the Postfix mail system
Aug 27 04:04:07 localhost postfix/master[2249]: daemon started -- version 2.6.6, configuration /etc/postfix
Aug 27 04:05:01 localhost postfix/pickup[2257]: C29D0390A: uid=0 from=<root>
Aug 27 04:05:01 localhost postfix/cleanup[2639]: C29D0390A: message-id=<20130827110501.C29D0390A@jmnote.localdomain>
Aug 27 04:05:01 localhost postfix/qmgr[2258]: C29D0390A: from=<root@jmnote.localdomain>, size=568, nrcpt=1 (queue active)
Aug 27 04:05:01 localhost postfix/local[2641]: C29D0390A: to=<root@jmnote.localdomain>, orig_to=<root>, relay=local, delay=0.07, delays=0.03/0.03/0/0.01, dsn=2.0.0, status=sent (delivered to mailbox)
Aug 27 04:05:01 localhost postfix/qmgr[2258]: C29D0390A: removed
Aug 27 04:06:01 localhost postfix/pickup[2257]: D209D390A: uid=0 from=<root>
Aug 27 04:06:01 localhost postfix/cleanup[2639]: D209D390A: message-id=<20130827110601.D209D390A@jmnote.localdomain>
Aug 27 04:06:01 localhost postfix/qmgr[2258]: D209D390A: from=<root@jmnote.localdomain>, size=568, nrcpt=1 (queue active)
Aug 27 04:06:01 localhost postfix/local[2641]: D209D390A: to=<root@jmnote.localdomain>, orig_to=<root>, relay=local, delay=0.02, delays=0.02/0/0/0, dsn=2.0.0, status=sent (delivered to mailbox)
Aug 27 04:06:01 localhost postfix/qmgr[2258]: D209D390A: removed
[root@zetawiki ~]# cat /var/log/secure
... (생략)
Aug 13 15:39:16 localhost sshd[2668]: Accepted password for root from 192.168.0.246 port 1089 ssh2
Aug 13 15:39:16 localhost sshd[2668]: pam_unix(sshd:session): session opened for user root by (uid=0)
Aug 13 15:52:19 localhost useradd[2841]: new group: name=testuser, GID=501
Aug 13 15:52:19 localhost useradd[2841]: new user: name=testuser, UID=501, GID=501, home=/home/testuser, shell=/bin/bash
Aug 13 15:52:23 localhost su: pam_unix(su-l:session): session opened for user testuser by root(uid=0)
Aug 13 15:52:27 localhost su: pam_unix(su-l:session): session closed for user testuser
Aug 13 15:54:20 localhost userdel[2893]: delete user 'testuser'
Aug 13 15:54:20 localhost userdel[2893]: removed group 'testuser' owned by 'testuser'
... (생략)
[root@zetawiki ~]# tail -30 /var/log/cron
... (생략)
Jul 7 01:10:01 localhost CROND[3155]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 7 01:20:01 localhost CROND[3158]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 7 01:30:01 localhost CROND[3161]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Jul 7 01:40:01 localhost CROND[3164]: (root) CMD (/usr/lib64/sa/sa1 1 1)
Aug 2 20:54:52 localhost crond[2261]: (CRON) STARTUP (1.4.4)
Aug 2 20:54:53 localhost crond[2261]: (CRON) INFO (running with inotify support)
Aug 2 20:55:00 localhost crontab[2491]: (root) LIST (root)
Aug 2 20:55:02 localhost crontab[2493]: (root) BEGIN EDIT (root)
Aug 2 20:55:16 localhost crontab[2493]: (root) END EDIT (root)
Aug 2 20:56:05 localhost crontab[2505]: (root) BEGIN EDIT (root)
Aug 2 20:56:19 localhost crontab[2505]: (root) REPLACE (root)
Aug 2 20:56:19 localhost crontab[2505]: (root) END EDIT (root)
Aug 2 20:56:21 localhost crontab[2510]: (root) LIST (root)
Aug 2 20:57:01 localhost CROND[2517]: (root) CMD (sh /root/script/check.sh)
Aug 2 20:58:01 localhost CROND[2598]: (root) CMD (sh /root/script/check.sh)
Aug 2 20:59:01 localhost CROND[2615]: (root) CMD (sh /root/script/check.sh)
dmesg :
root@zetawiki:~# dmesg
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
... (생략)
[ 17.182925] random: nonblocking pool is initialized
[83649.584278] init: systemd-logind main process (526) killed by TERM signal
[83654.119111] init: irqbalance main process (917) killed by TERM signal
[83667.248557] systemd-udevd[13285]: starting version 204
cat /var/log/dmesg :
root@zetawiki:~# cat /var/log/dmesg
[ 0.000000] Initializing cgroup subsys cpuset
[ 0.000000] Initializing cgroup subsys cpu
[ 0.000000] Initializing cgroup subsys cpuacct
... (생략)
[ 9.859137] audit: type=1400 audit(1443014929.652:18): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="/usr/lib/connman/scripts/dhclient-script" pid=816 comm="apparmor_parser"
[ 9.859341] audit: type=1400 audit(1443014929.652:19): apparmor="STATUS" operation="profile_replace" profile="unconfined" name="/usr/lib/connman/scripts/dhclient-script" pid=816 comm="apparmor_parser"
[ 9.870241] audit: type=1400 audit(1443014929.660:20): apparmor="STATUS" operation="profile_load" profile="unconfined" name="/usr/sbin/tcpdump" pid=818 comm="apparmor_parser"
[root@zetawiki ~]# cat /var/log/boot.log
Welcome to CentOS
Starting udev: [ OK ]
Setting hostname jmnote: [ OK ]
Setting up Logical Volume Management: No volume groups found
[ OK ]
Checking filesystems
/dev/sda2: clean, 96222/1164592 files, 671728/4657920 blocks
/dev/sda1: recovering journal
/dev/sda1: clean, 38/76912 files, 42806/307200 blocks
[ OK ]
Remounting root filesystem in read-write mode: [ OK ]
Mounting local filesystems: [ OK ]
Enabling local filesystem quotas: [ OK ]
Enabling /etc/fstab swaps: [ OK ]
Entering non-interactive startup
Calling the system activity data collector (sadc):
Checking acpi hot plug [ OK ]
Starting VMware Tools services in the virtual machine:
Switching to guest configuration: [ OK ]
VM communication interface: [ OK ]
VM communication interface socket family: [ OK ]
Guest filesystem driver: [ OK ]
Mounting HGFS shares: [FAILED]
Blocking file system: [ OK ]
Guest operating system daemon: [ OK ]
ip6tables: Applying firewall rules: [ OK ]
iptables: Applying firewall rules: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: Device eth0 does not seem to be present, delaying initialization.
[FAILED]
Starting auditd: [ OK ]
Starting portreserve: [ OK ]
Starting system logger: [ OK ]
Starting irqbalance: [ OK ]
Starting kdump: [FAILED]
Starting system message bus: [ OK ]
Setting network parameters... [ OK ]
Starting NetworkManager daemon: [ OK ]
Starting Avahi daemon... [ OK ]
Starting cups: [ OK ]
Mounting other filesystems: [ OK ]
Starting acpi daemon: [ OK ]
Starting HAL daemon: [ OK ]
Retrigger failed udev events [ OK ]
Enabling Bluetooth devices:
Starting sshd: [ OK ]
Starting Virtual Printing daemon: done
Starting postfix: [ OK ]
Starting abrt daemon: [ OK ]
Starting crond: [ OK ]
Starting atd: [ OK ]
[root@zetawiki ~]# lastlog
Username Port From Latest
root :0 Mon Feb 6 04:49:14 -0800 2012
bin **Never logged in**
daemon **Never logged in**
adm **Never logged in**
... (생략)
avahi-autoipd **Never logged in**
gdm **Never logged in**
jmnote **Never logged in**
한번 이상 로그인한 계정 확인
[root@zetawiki ~]# lastlog | grep -v Never
Username Port From Latest
root pts/1 135.79.246.80 Thu Aug 30 09:04:51 +0900 2012
jmnote pts/1 135.79.246.80 Wed Aug 29 15:33:43 +0900 2012
testuser pts/1 246.80.135.79 Wed Jul 18 13:49:08 +0900 2012
grep -v : 매칭되는 PATTERN이 존재하지 않는 라인을 선택.
한번도 로그인하지 않은 계정 확인
[root@zetawiki ~]# lastlog | grep Never
bin **Never logged in**
daemon **Never logged in**
adm **Never logged in**
... (생략)
특정 계정 확인
lastlog -u 계정명
lastlog | grep 계정명
3일 이내 로그인한 계정 확인
[testuser@jmnote ~]$ lastlog -t 3
Username Port From Latest
root pts/0 192.168.0.217 Wed Jan 8 01:32:31 +0900 2014
testuser pts/1 localhost.locald Wed Jan 8 01:38:44 +0900 2014
[root@zetawiki ~]# last -f /var/log/wtmp
root pts/0 135.79.246.80 Sun Nov 17 17:45 still logged in
root pts/15 135.79.246.80 Wed Nov 13 17:40 - 17:40 (00:00)
root pts/15 135.79.246.80 Wed Nov 13 17:40 - 17:40 (00:00)
... (생략)
wtmp begins Mon Nov 8 23:11:20 2010
=> last 명령어로 wtmp 파일 내용을 볼 수 있다.
=> -f /var/log/wtmp가 없어도 기본값이 /var/log/wtmp이기 때문에 동일하다.
last -f file : 지정한 파일에서 정보를 읽어와서 출력
[root@localhost ~]# tail /var/log/xferlog
... (생략)
Sun Jun 24 19:41:00 2007 1 localhost 882 /tmp/test1 b _ o r root ftp 0 * c
Sun Jun 24 19:42:15 2007 1 localhost 882 /tmp/test2 b _ i r root ftp 0 * c