常见的系统日志及各自用途

xiaoxiao2021-02-28  79

常见的系统日志及各自用途:

/var/log/messages,记录内核消息、各种服务的公共消息/var/log/dmesg,记录系统启动过程的各种消息/var/log/cron,记录与cron计划任务相关的消息/var/log/maillog,记录邮件收发相关的消息/var/log/secure,记录与访问限制相关的安全消息

日志消息的优先级(高-->低):

EMERG(紧急):级别0,系统不可用的情况ALERT(警报):级别1,必须马上采取措施的情况CRIT(严重):级别2,严重情形ERR(错误):级别3,出现错误WARNING(警告):级别4,值得警告的情形NOTICE(注意):级别5,普通但值得引起注意的事件INFO(信息):级别6,一般信息DEBUG(调试):级别7,程序/服务调试消息

RHEL7提供的journalctl日志工具的常见用法:

journalctl | grep 关键词journalctl -u 服务名 -p 优先级journalctl -n 消息条数journalctl --since="yyyy-mm-dd HH:MM:SS" --until="yyyy-mm-dd HH:MM:SS"

[root@host50 ~]# grep 8909 /var/log/messagesJul  7 19:40:07 host50 httpd: (13)Permission denied: AH00072: make_sock: could not bind to address [::]:8909

[root@host50 ~]# dmesg  |  grep  -i  mouse [    0.682742] mousedev: PS/2 mouse device common for all mice [    0.683233] input: VirtualPS/2 VMware VMMouse as /devices/platform/i8042/serio1/input/input2

[    0.683354] input: VirtualPS/2 VMware VMMouse as /devices/platform/i8042/serio1/input/input3

查看登录成功的消息

[root@host50 ~]#  last  -2root     pts/1        192.168.4.254    Sat Jul  7 16:21   still logged in   

root     pts/0        192.168.4.254    Sat Jul  7 11:16   still logged in 

查看登录失败的消息 

[root@host50 ~]#  lastb  -2btmp begins Sat Jul  7 11:14:41 2018

journalctl日志提取工具

[root@host50 ~]#  journalctl  -p err  -n  10  //错误级别在10以上的日志消息-- Logs begin at 六 2018-07-07 11:14:35 CST, end at 六 2018-07-07 19:42:23 CST. --7月 07 11:14:42 host50 smartd[723]: Problem creating device name scan list7月 07 11:14:42 host50 smartd[723]: In the system's table of devices NO devices found to scan7月 07 19:40:07 host50 systemd[1]: Failed to start The Apache HTTP Server.7月 07 19:40:10 host50 setroubleshoot[6764]: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket

7月 07 19:40:10 host50 setroubleshoot[6764]: SELinux is preventing /usr/sbin/httpd from name_bind access on the tcp_socket

[root@host50 ~]#  journalctl  -u httpd  //列出与服务http相关的消息

-- Logs begin at 六 2018-07-07 11:14:35 CST, end at 六 2018-07-07 19:50:01 CST. --

列出某个时间段的日志信息

[root@host50 ~]# journalctl  --since  "2018-07-07 14:11"  --until  "2018-07-07 18:11"-- Logs begin at 六 2018-07-07 11:14:35 CST, end at 六 2018-07-07 19:50:01 CST. --

转载请注明原文地址: https://www.6miu.com/read-2626773.html

最新回复(0)