日志系统:
系统的日志是记录硬件、软件和系统问题的信息,同时也记录系统中发生的事件。
(通过它检查错误发生的原因,或者查找攻击者留下的痕迹)
可以分为:事件日志 和消息日志
处理日志的进程
rsyslogd 进程采集与记录绝大部分与系统相关的日志
(安全、认证、计划任务等)
ps命令查看该进程:
[root@Linux ~]# ps aux | grep rsyslogd root 975 0.0 0.5 548152 9168 ? Ssl 2021 20:00 /usr/sbin/rsyslogd -n root 24294 0.0 0.0 112812 976 pts/1 S+ 17:45 0:00 grep --color=auto rsyslogd
(apache、Nginx、MySQL等服务以自己的方式记录与分析日志)
日志可以存放本地,也可以存放远程服务器
常见的日志文件:
/var/log目录下都是日志文件,文件名称以日期结尾表示该日志已经被切割过
[root@Linux ~]# ls /var/log anaconda chrony cron-20221016 journal messages-20220925 secure-20220925 spooler-20221016 ansible.log cloudinit-deploy.log dmesg lastlog messages-20221002 secure-20221002 tallylog audit cloud-init.log dmesg.old maillog messages-20221009 secure-20221009 tuned boot.log cloud-init-output.log ecs_network_optimization.log maillog-20220925 messages-20221016 secure-20221016 wtmp boot.log-20210910 cron firewalld maillog-20221002 mysqld.log spooler xferlog boot.log-20210914 cron-20220925 grubby maillog-20221009 rhsm spooler-20220925 yum.log btmp cron-20221002 grubby_prune_debug maillog-20221016 sa spooler-20221002 yum.log-20220101 btmp-20221001 cron-20221009 httpd messages secure spooler-20221009
/var/log/messages 文件为系统的主日志文件,几乎系统发生的所有事件都会记录到此文件中
[root@Linux ~]# tail /var/log/messages Oct 20 17:23:00 Linux nscd: 18031 monitoring file `/etc/group` (26) Oct 20 17:23:00 Linux nscd: 18031 monitoring directory `/etc` (2) Oct 20 17:23:00 Linux nscd: 18031 monitoring file `/etc/passwd` (25) Oct 20 17:23:00 Linux nscd: 18031 monitoring directory `/etc` (2) Oct 20 17:23:00 Linux nscd: 18031 monitoring file `/etc/group` (26) Oct 20 17:23:00 Linux nscd: 18031 monitoring directory `/etc` (2) Oct 20 17:23:00 Linux systemd-logind: Removed session 68041. Oct 20 17:30:01 Linux systemd: Started Session 68042 of user root. Oct 20 17:40:01 Linux systemd: Started Session 68043 of user root. Oct 20 17:50:01 Linux systemd: Started Session 68044 of user root.