linux系统日志
- /var/log/messages //是linux系统一个总的日志——>除非某些服务,有定义单独的日志
- /etc/logrotate.conf 日志切割配置文件
- 参考日志文件文章
- dmesg命令
- /var/log/dmesg 日志
- last命令,调用的文件/var/log/wtmp
- lastb命令查看登陆失败的用户,对应的文件时/var/log/btmp
- /var/log/secure
系统日志
- /var/log/messages //是linux系统一个总的日志——>除非某些服务,有定义单独的日志
- 系统中存有一个日志切割机制,日志的滚动,在增加到必定级别了,就会自动切割
[root@hf-01 ~]#
[root@hf-01 ~]# ls /var/log/messages
/var/log/messages
[root@hf-01 ~]# less !$
less /var/log/messages
[root@hf-01 ~]# du -sh !$
du -sh /var/log/messages
388K /var/log/messages
- 在查看日志的时候,会发现日志自动切割了
- linux系统中有一个logrotate服务,会自动切割日志,防止无限制的增长
[root@hf-01 ~]# ls /var/log/messages*
/var/log/messages /var/log/messages-20171120 /var/log/messages-20171203
/var/log/messages-20171112 /var/log/messages-20171127
[root@hf-01 ~]#
- 查看日志文件cat /etc/logrotate.conf
[root@hf-01 ~]# cat /etc/logrotate.conf
# see "man logrotate" for details //会告诉你查看logrotate的帮助文档
# 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 //是否须要压缩,压缩成 .tar.gz
# 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.
[root@hf-01 ~]#
- 查看 /etc/logrotate.d/syslog 文件
- 它会为cron,maillog,messages,secure,spooler这几个日志进行切割
- messages日志是由 syslogd 服务决定的,因此 kill -HUP 就会从新加载这个日志
- 还有一个脚本,shell命令行,在把日志切割后(挪走),更名字生成新的日志
- Linux系统有一个特色,一个服务写一个文件的时候,并非按照文件名去写的,而是根据inode来写的
[root@hf-01 ~]# ls /etc/logrotate.d
ppp samba syslog wpa_supplicant yum
[root@hf-01 ~]# cat /etc/logrotate.d/syslog
/var/log/cron
/var/log/maillog
/var/log/messages
/var/log/secure
/var/log/spooler
{
sharedscripts
postrotate
/bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true
endscript
}
[root@hf-01 ~]#
dmesg命令
- dmesg命令,会把系统硬件相关的日志列出来
- 假如你的网卡有问题了,硬盘损坏了,都会记录在这个日志中
- dmesg -c //清空当前日志
/var/log/dmesg日志文件
- /var/log/dmesg //这是一个日志文件
- 这个日志文件和 dmesg命令 没有任何关联
- 它是系统启动的一个日志,记录的信息
last命令
- last命令,查看你正确的登陆历史
- 调用的文件/var/log/wtmp
- 记录是是谁,在哪里,来源IP,时间,登陆的时长都会有记录
- /var/log/wtmp日志是一个二进制文件,不能直接cat查看的,只能用last命令去查看
[root@hf-01 ~]# last
root pts/0 192.168.74.1 Thu Dec 7 01:41 still logged in
reboot system boot 3.10.0-123.el7.x Thu Dec 7 01:36 - 05:38 (04:01)
root pts/1 192.168.74.1 Wed Dec 6 05:11 - 05:13 (00:01)
root pts/0 192.168.74.1 Wed Dec 6 01:27 - crash (1+00:09)
reboot system boot 3.10.0-123.el7.x Wed Dec 6 01:26 - 05:38 (1+04:11)
root pts/0 192.168.74.1 Tue Dec 5 01:38 - crash (23:48)
reboot system boot 3.10.0-123.el7.x Tue Dec 5 01:37 - 05:38 (2+04:00)
root pts/0 192.168.74.1 Mon Dec 4 03:23 - down (02:57)
root pts/0 192.168.74.1 Sun Dec 3 17:42 - 03:23 (09:40)
等等等,只截取了一部分
[root@hf-01 ~]# ls /var/log/wtmp
/var/log/wtmp
lastb命令
- lastb命令,查看登陆失败的用户
- /var/log/btmp也是二进制文件,不能直接cat的
[root@hf-01 ~]# lastb
btmp begins Sat Dec 2 04:25:01 2017
[root@hf-01 ~]# ls /var/log/btmp
/var/log/btmp
[root@hf-01 ~]#
安全日志
- /var/log/secure
- 好比登陆操做系统,验证成功会在这里记录一个日志,失败也会去记录
[root@hf-01 ~]# ls /var/log/secure
/var/log/secure
[root@hf-01 ~]#