Linux系统日志

文本类型日志

/var/log/messages  
/var/log/dmesg
/var/log/secure  //安全日志,如登录系统成功或失败都会记录下来
/var/log/cron
/var/log/maillog
/var/log/yum.log

二进制类型日志

/var/log/wtmp
/var/log/lastlog
/var/run/utmp
注意:这三个文件中保存了系统用户登录、退出等相关事件的事件信息,不能直接使用tail、less等文本查看工具进行浏览
      需要使用who、w、users、last和ac等用户查询命令来获取日志信息


系统有一个日志切割机制,当日志文件大小增涨到一定程度了,就会对这个日志进行切割,存放位置/var/log/目录下,文件名以message-日期的格式,日志切割主配置文件是/etc/logrotate.conf

[root@localhost log]# 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

# no packages own wtmp and btmp -- we'll rotate them here
/var/log/wtmp {
    monthly
    create 0664 root utmp
	minsize 1M
    rotate 1
}

/var/log/btmp {
    missingok
    monthly
    create 0600 root utmp
    rotate 1
}

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

image.png

Linux系统日志_第1张图片

dmesg命令(记录硬件信息)

# dmesg 
# dmesg -c

last命令

last命令用于查询wtmp文件,显示出自从该文件被创建以来登录过的所有用户记录,最近登录的用户将显示在最前面。

[root@localhost log]# last
root     pts/0        192.168.221.1    Sat Feb 24 08:39   still logged in   
root     tty1                          Sat Feb 24 08:38   still logged in   
root     tty1                          Sat Feb 24 08:36 - 08:38  (00:01)    
reboot   system boot  3.10.0-693.el7.x Sat Mar 24 08:35 - 15:50 (-27+-16:-45
root     tty1                          Tue Jan  2 01:14 - 17:42 (27+16:27)  
reboot   system boot  3.10.0-693.el7.x Tue Jan  2 01:13 - 17:42 (27+16:28)  

wtmp begins Tue Jan  2 01:13:46 2018

lastb命令

lastb命令会记录登入系统失败的用户信息显示出来

[root@localhost ~]# lastb
root     ssh:notty    192.168.221.1    Sat Feb 24 15:54 - 15:54  (00:00)    
root     ssh:notty    192.168.221.1    Sat Feb 24 15:53 - 15:53  (00:00)    
root     ssh:notty    192.168.221.20   Sat Feb 24 09:52 - 09:52  (00:00)    

btmp begins Sat Feb 24 09:52:43 2018