Jquery中文网 www.jquerycn.cn
Jquery中文网 >  服务器技术  >  日志与监控  >  正文 学习Linux系统日志管理

学习Linux系统日志管理

发布时间:2014-07-20   编辑:www.jquerycn.cn
Linux系统日志管理
学习Linux系统日志管理
1. 连接时间的日志
连接时间日志一般由/var/log/wtmp和/var/run/utmp这两个文件记录,不过这两个文件无法直接cat查看,并且该文件由系统自动更新,可以通过如下:
w/who/finger/id/last/lastlog/ac 进行查看
[root@xhot ~]# who
root tty1 2010-10-06 22:56
root pts/0 2010-10-06 22:26 (218.192.87.4)
root pts/1 2010-10-06 23:41 (218.192.87.4)
root pts/3 2010-10-06 23:18 (218.192.87.4)
[root@xhot ~]# w
01:01:02 up 2:36, 4 users, load average: 0.15, 0.03, 0.01
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root tty1 - 22:56 1:20m 0.16s 0.16s -bash
root pts/0 218.192.87.4 22:26 2:05m 0.18s 0.18s -bash
root pts/1 218.192.87.4 23:41 0.00s 0.41s 0.00s w
root pts/3 218.192.87.4 23:18 1:38m 0.03s 0.03s -bash
[root@xhot ~]# ac -p //查看每个用户的连接时间
u51 1.23
u55 0.04
root 95.21 //可以看到root连接时间最长吧
xhot 0.06
user1 3.93
total 100.48
[root@xhot ~]# ac -a //查看所有用户的连接时间
total 100.49
[root@xhot ~]# ac -d //查看用户每天的连接时间
Sep 24 total 0.14
Sep 25 total 14.60
Sep 26 total 13.71
Sep 27 total 21.47
Sep 28 total 11.74
Sep 29 total 6.60
Sep 30 total 8.81
Oct 1 total 9.04
Oct 2 total 0.47 //可以看到我国庆3、4、5号出去玩了
Oct 6 total 8.62
Today total 5.29
 
2. 进程监控日志
进程统计监控日志在监控用户的操作指令是非常有效的。当服务器最近发现经常无故关机或者无故被人删除文件等现象时,可以通过使用进程统计日志查看:
[root@xhot ~]# accton /var/account/pacct //开启进程统计日志监控
[root@xhot ~]# lastcomm //查看进程统计日志情况
accton S root pts/1 0.00 secs Thu Oct 7 01:20
accton root pts/1 0.00 secs Thu Oct 7 01:20
ac root pts/1 0.00 secs Thu Oct 7 01:14
ac root pts/1 0.00 secs Thu Oct 7 01:14
free root pts/1 0.00 secs Thu Oct 7 01:10
lastcomm root pts/1 0.00 secs Thu Oct 7 01:09
bash F root pts/1 0.00 secs Thu Oct 7 01:09
lastcomm root pts/1 0.00 secs Thu Oct 7 01:09
ifconfig root pts/1 0.00 secs Thu Oct 7 01:09
lastcomm root pts/1 0.00 secs Thu Oct 7 01:09
lastcomm root pts/1 0.00 secs Thu Oct 7 01:09
lastcomm root pts/1 0.00 secs Thu Oct 7 01:09
accton S root pts/1 0.00 secs Thu Oct 7 01:09
[root@xhot ~]# accton //关闭进程统计日志监控
 
3. 系统和服务日志
系统日志服务是由一个名为syslog的服务管理的,如一下日志文件都是由syslog日志服务驱动的:
/var/log/lastlog :记录最后一次用户成功登陆的时间、登陆IP等信息
/var/log/messages :记录Linux操作系统常见的系统和服务错误信息
/var/log/secure :Linux系统安全日志,记录用户和工作组变坏情况、用户登陆认证情况
/var/log/btmp :记录Linux登陆失败的用户、时间以及远程IP地址
/var/log/cron :记录crond计划任务服务执行情况
[root@xhot ~]# cat /var/log/lastlog
Lpts/0218.192.87.4
Lpts/1218.192.87.4
Lpts/1218.192.87.4
Lpts/0218.192.87.46
Lpts/0218.192.87.4

您可能感兴趣的文章:
学习Linux系统日志管理
Linux根据系统日志查看网卡是否报错
Linux管理日志系统详解
Linux日志服务介绍和日志服务器配置
使用日志保护Linux的安全
Linux下自动清理日志的shell脚本
php系统日志切割的实例
PHP错误日志的使用及汇总
查看linux日志的方法
用ASP.NET将网页错误信息写入系统日志

[关闭]