【等保合规】Ubuntu 日志模块配置解读

日志默认配置参数

Ubuntu

$ lsb_release -a  // Ubuntu 版本查看
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy

默认配置参数

$ cat /etc/logrotate.conf
# see "man logrotate" for details

# global options do not affect preceding include directives

# rotate log files weekly
# 设置日志轮转方式,
weekly   

# use the adm group by default, since this is the owning group
# of /var/log/syslog.
su root adm

# keep 4 weeks worth of backlogs
rotate 4

# create new (empty) log files after rotating old ones
create

# use date as a suffix of the rotated file
#dateext

# uncomment this if you want your log files compressed
#compress

# packages drop log rotation information into this directory
include /etc/logrotate.d

# system-specific logs may also be configured here.

参数解析如下:

  1. weekly:指定日志文件轮转的周期为每周一次。
  2. su root adm:指定在执行日志轮转时,应该以 root 用户和 adm 用户组的身份来执行。adm 用户组通常是日志文件的所有者。
  3. rotate 4:指定保留4周的日志文件备份。当轮转发生时,如果日志文件的数量超过了这个数字,最旧的日志文件将被删除。
  4. create:在轮转旧的日志文件之后,创建一个新的(空的)日志文件。
  5. dateext:如果取消注释(即去掉前面的 #),这个选项会在轮转的日志文件名后添加日期作为后缀。例如,如果日志文件名为 syslog,轮转后的文件名可能会是 syslog-2024-01-01。
  6. compress:如果取消注释,这个选项会在轮转日志文件时对其进行压缩,通常使用 gzip。
  7. include /etc/logrotate.d:指定 logrotate 应该读取 /etc/logrotate.d 目录下的配置文件,这些文件包含了特定应用程序的日志轮转配置。
  8. system-specific logs may also be configured here.:这是一个注释,说明系统特定的日志也可以在这个配置文件中进行配置。

等保合规要求,服务器日志应满足存储时间不少于六个月,(实际生产要求最好是一百八十天以上),应将 rotate 4 修改为 rotate 26(7 * 26 = 182 > 180),修改完后保存退出并重启服务,日志内容存储在 /var/log


你可能感兴趣的:(运维,ubuntu,linux,运维)