linux日志文件配置文件_如何在Linux中旋转日志文件?

linux日志文件配置文件_如何在Linux中旋转日志文件?_第1张图片

linux日志文件配置文件

Logs are created by different services like HTTP, FTP, ssh, etc. What do we with these logs? May be nothing but when the times came it will be important to get detailed information about the error, security event etc from log files. Logs are created all times and always grows up. How can we handle to prevent these logs files to fill our disks? Here came the rotate operation or daemon. We can rotate and compress our logs file easily with a simple configuration. Also, information about rotated logs can be emailed to specified recipient.

日志由HTTP,FTP,ssh等不同的服务创建。我们如何处理这些日志? 可能无非是时候到了,从日志文件中获取有关错误,安全事件等的详细信息非常重要。 日志始终创建,并且一直在增长。 我们如何处理以防止这些日志文件填满磁盘? 这里是旋转操作或守护程序。 我们可以通过简单的配置轻松地旋转和压缩日志文件。 此外,有关轮换日志的信息可以通过电子邮件发送给指定的收件人。

默认配置文件 (Default Configuration File)

Logrotate default configuration file resides /etc/logrotate.conf . Below is default  configuration details

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.

There are explanations about configuration directives.

有关于配置指令的说明。

linux日志文件配置文件_如何在Linux中旋转日志文件?_第2张图片 Default Configuration File 默认配置文件

对旋转文件启用压缩(Enable Compression For Rotated Files)

Rotating log files create new log file and old files can be compressed to gain disk space like below.

旋转日志文件会创建新的日志文件,而旧文件可以进行压缩以获取磁盘空间,如下所示。

compress

Uncomment compress line or add a new line

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

更改积压(Change BackLog)

How much time we will store old logs? We can set it with count like below.

我们将存储旧日志多少时间? 我们可以用下面的计数来设置它。

rotate 4

This will rotate or save log files for 4 weeks if rotation is done weekly. If rotation is done daily it will hold old logs for 4 days.

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

LEARN MORE  How Configure Cisco For Logging?
了解更多信息如何配置Cisco进行日志记录?

指定新的旋转配置 (Specify New Rotate Configuration)

We can create a new and different rotate configuration for different logs. New rotate configuration is hold in /etc/logrotate.d/

我们可以为不同的日志创建新的和不同的轮换配置。 新的旋转配置保存在/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

As we see there is a lot of logrotate configuration for different logs like samba, httpd, etc.

如我们所见,samba,httpd等不同日志有很多logrotate配置。

翻译自: https://www.poftut.com/rotate-log-files-linux/

linux日志文件配置文件

你可能感兴趣的:(linux,nginx,java,运维,docker)