如何在Linux中旋转日志文件?

日志是由不同的服务创建的,如HTTP、FTP、ssh等。我们如何处理这些日志?可能什么都没有,但当时代来临时,从日志文件中获取有关错误、安全事件等的详细信息将非常重要。日志总是被创建的,而且总是长大的。我们如何处理以防止这些日志文件填满我们的磁盘?这里是旋转操作或守护进程。我们可以通过简单的配置轻松地旋转和压缩日志文件。此外,有关旋转日志的信息可以通过电子邮件发送给指定的收件人。

null

默认配置文件

Logrotate默认配置文件驻留 /etc/logrotate.conf文件 . 以下为默认值 配置详细信息

# see "man logrotate" for details # rotate log files weekly weekly  # 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  # RPM packages drop log rotation information into this directory include /etc/logrotate.d  # no packages own wtmp and btmp -- we'll rotate them here /var/log/wtmp {     monthly     create 0664 root utmp         minsize 1M     rotate 1 }  /var/log/btmp {     missingok     monthly     create 0600 root utmp     rotate 1 }  # system-specific logs may be also be configured here.

有关于配置指令的解释。

Default Configuration File
默认配置文件

启用旋转文件的压缩

旋转日志文件创建新的日志文件和旧文件可以压缩,以获得磁盘空间如下。

compress

取消注释 压缩 行或添加新行

更改待办事项

我们需要多少时间来储存旧的原木?我们可以用下面的计数来设置。

rotate 4

如果每周轮换一次,这将轮换或保存日志文件4周。如果每天进行轮换,它将保留4天的旧日志。

相关文章: 如何配置Cisco日志?

指定新的旋转配置

我们可以为不同的日志创建一个新的和不同的rotate配置。新的旋转配置保持不变 /etc/logrotate.d/

$ ls /etc/logrotate.d/ chrony  glusterfs  iscsiuiolog  libvirtd.qemu  numad  psacct  sssd    wpa_supplicant cups    httpd      libvirtd     mariadb        ppp    samba   syslog  yum

正如我们看到的,对于不同的日志(如samba、httpd等)有很多logrotate配置。

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享