Post

linux(CentOS7) 日志系统

Linux 日志系统

日志用途

  • 系统审计
  • 检测追踪
  • 分析统计
    • Web 应用请求量
    • 错误码分布
    • 性能
    • 是否需要扩容
    • 多少用户量

常见的日志文件

  • 登录日志
1
2
3
4
5
6
7
8
9
10
11
12
[root@Cc log]# lastlog
用户名           端口     来自             最后登陆时间
root             pts/1    113.118.200.16   四 3月 26 21:38:34 +0800 2020
ftp                                        **从未登录过**
sshd                                       **从未登录过**
ntp                                        **从未登录过**
nginx                                      **从未登录过**
mysql                                      **从未登录过**
redis                                      **从未登录过**
dockerroot                                 **从未登录过**
yf               pts/5                     一 3月 23 21:14:45 +0800 2020
[root@Cc log]#
  • who
  • users(查看当前用户)
  • 最近重启日志
1
2
3
[root@Cc log]# last reboot
reboot   system boot  3.10.0-1062.4.1. Fri Mar 20 17:14 - 22:55 (6+05:41)
reboot   system boot  3.10.0-1062.4.1. Fri Mar 20 17:14 - 09:14  (-7:-59)

日志文件说明

1
2
3
4
5
6
/var/log/message 系统启动后的信息和错误日志,是Red Hat Linux中最常用的日志之一
/var/log/secure 与安全相关的日志信息
/var/log/maillog 与邮件相关的日志信息
/var/log/cron 与定时任务相关的日志信息
/var/log/spooler 与UUCP和news设备相关的日志信息
/var/log/boot.log 守护进程启动和停止相关的日志消息

日志系统

rsyslog 日志系统

/etc/rsyslog.conf 默认配置,该配置文件对应日志文件请看上面【日志文件说明】

使用日志轮转

主要配置文件 /etc/logrotate.conf

主要配置目录 /etc/logrotate.d

1
2
3
4
5
6
7
8
9
[root@Cc etc]# logrotate --help;
用法: logrotate [OPTION...] <configfile>
  -d, --debug               详细显示指令执行过程
  -f, --force               强行启动记录文件维护
  -m, --mail=command        发送邮件的命令 (而不是 `/bin/mail')
  -s, --state=statefile     指定状态文件
  -v, --verbose             执行日志滚动式显示详细信息
  -l, --log=STRING          Log file
  -?						帮助文档
查看 nginx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
[root@Cc logrotate.d]# cat -n /etc/logrotate.d/nginx
     1  /var/log/nginx/*.log {
     2          daily
     3          missingok
     4          rotate 52
     5          compress
     6          delaycompress
     7          notifempty
     8          create 640 nginx adm
     9          sharedscripts
    10          postrotate
    11                  if [ -f /var/run/nginx.pid ]; then
    12                          kill -USR1 `cat /var/run/nginx.pid`
    13                  fi
    14          endscript
    15  }
[root@Cc logrotate.d]#

范例—————利用系统日志定位问题

1
这个预留,动手利用第五章知识完成

7 用户和组

This post is licensed under CC BY 4.0 by the author.