Shell

推荐列表 站点导航

当前位置:首页 > 脚本编程 > Shell >

学习Linux系统日志管理

来源:网络整理  作者:网友投稿  发布时间:2020-12-29 14:56
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

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://www.juheyunku.com/jiaob/shell/10714.shtml

相关文章
最新文章
Centos下PHP5升级为PHP7的方法 Centos下PHP5升级为PHP7的方法

时间:2021-01-03

在php当中常量和变量的区 在php当中常量和变量的区

时间:2020-12-29

PHP中经典的四大排序算法 PHP中经典的四大排序算法

时间:2020-12-29

dw怎么运行php文件? dw怎么运行php文件?

时间:2020-12-29

PHP PHP_EOL 换行符 PHP PHP_EOL 换行符

时间:2020-12-29

Python3爬虫进阶:MongoDB存储 Python3爬虫进阶:MongoDB存储

时间:2020-12-29

python如何运行一个python程 python如何运行一个python程

时间:2020-12-29

用PHP写一个计算器(附完 用PHP写一个计算器(附完

时间:2020-12-29

Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

学习Linux系统日志管理

2020-12-29 编辑:网友投稿

学习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

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://www.juheyunku.com/jiaob/shell/10714.shtml

相关文章

风云图片

推荐阅读

返回Shell频道首页