logrotate主配置文件详解

一、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   #指定滚动后创建的新文件的权限为0644,数组为root,属组为utmpminsize 1M             #指定文件的值小于1M不滚动   rotate 1                #指定保留几个备份副本}/var/log/btmp {missingok   #如果日志文件不存在发送错误消息monthlycreate 0600 root utmprotate 1}# system-specific logs may be also be configured here.

二、主配置文件参数详解

PS:配置文件中的更多参数可用man logrotate查看

compressOld versions of log files are compressed with gzip(1) by default. See also nocompress.compresscmdSpecifies which command to use to compress log files.  The default is gzip(1).  See also compress.uncompresscmdSpecifies which command to use to uncompress log files.  The default is gunzip(1).compressextSpecifies  which  extension  to  use on compressed logfiles, if compression is enabled.  The defaultfollows that of the configured compression command.compressoptionsCommand line options may be passed to the compression program, if one is in use.  The  default,  forgzip(1),  is "-6" (biased towards high compression at the expense of speed).  If you use a differentcompression command, you may need to change the compressoptions to match.copy   Make a copy of the log file, but don't change the original at all.  This option  can  be  used,  forinstance,  to  make a snapshot of the current log file, or when some other utility needs to truncateor parse the file.  When this option is used, the create option will have no effect, as the old  logfile stays in place.copytruncateTruncate  the  original  log file to zero size in place after creating a copy, instead of moving theold log file and optionally creating a new one.  It can be used when some program cannot be told  toclose  its  logfile  and  thus  might continue writing (appending) to the previous log file forever.Note that there is a very small time slice between copying the file and truncating it, so some  log‐ging  data  might  be lost.  When this option is used, the create option will have no effect, as theold log file stays in place.create mode owner group, create owner groupImmediately after rotation (before the postrotate script is run) the log file is created  (with  thesame  name  as  the  log file just rotated).  mode specifies the mode for the log file in octal (thesame as chmod(2)), owner specifies the user name who will own the log file, and group specifies  thegroup  the  log  file  will  belong to. Any of the log file attributes may be omitted, in which casethose attributes for the new file will use the same values as the original log file for the  omittedattributes. This option can be disabled using the nocreate option.createolddir mode owner groupIf  the  directory  specified  by olddir directive does not exist, it is created. mode specifies themode for the olddir directory in octal (the same as chmod(2)), owner specifies  the  user  name  whowill  own  the  olddir directory, and group specifies the group the olddir directory will belong to.This option can be disabled using the nocreateolddir option.daily  Log files are rotated every day.dateextArchive old versions of log files adding a date extension like YYYYMMDD instead of simply  adding  anumber. The extension may be configured using the dateformat and dateyesterday options.dateformat format_stringSpecify  the extension for dateext using the notation similar to strftime(3) function. Only %Y %m %d%H and %s specifiers are allowed.  The default value is -%Y%m%d except hourly, which uses  -%Y%m%d%Has  default  value.   Note that also the character separating log name from the extension is part ofthe dateformat string. The system clock must be set past Sep 9th 2001  for  %s  to  work  correctly.Note  that the datestamps generated by this format must be lexically sortable (i.e., first the year,then the month then the day. e.g., 2001/12/01 is ok, but 01/12/2001 is not, since  01/11/2002  wouldsort  lower  while  it is later).  This is because when using the rotate option, logrotate sorts allrotated filenames to find out which logfiles are older and should be removed.dateyesterdayUse yesterday's instead of today's date to create the dateext extension, so  that  the  rotated  logfile has a date in its name that is the same as the timestamps within it.delaycompressPostpone compression of the previous log file to the next rotation cycle.  This only has effect whenused in combination with compress.  It can be used when some program cannot be  told  to  close  itslogfile and thus might continue writing to the previous log file for some time.extension extLog  files  with  ext extension can keep it after the rotation.  If compression  is  used,  the com‐pression extension (normally .gz) appears after ext. For example you have a logfile named  mylog.fooand want to rotate it to mylog.1.foo.gz instead of mylog.foo.1.gz.hourly Log files are rotated every hour. Note that usually logrotate is configured to be run by cron daily.You have to change this configuration and run logrotate hourly to be  able  to  really  rotate  logshourly.ifemptyRotate the log file even if it is empty, overriding the notifempty option (ifempty is the default).include file_or_directoryReads  the  file  given  as  an  argument  as  if it was included inline where the include directiveappears. If a directory is given, most of the files in that directory are read in  alphabetic  orderbefore  processing of the including file continues. The only files which are ignored are files whichare not regular files (such as directories and named pipes) and files whose names end  with  one  ofthe taboo extensions, as specified by the tabooext directive.mail addressWhen a log is rotated out of existence, it is mailed to address. If no mail should be generated by aparticular log, the nomail directive may be used.mailfirstWhen using the mail command, mail the just-rotated file, instead of the about-to-expire file.maillastWhen using the mail command, mail the about-to-expire file, instead of the just-rotated  file  (thisis the default).maxage countRemove  rotated  logs  older  than  <count>  days.  The  age is only checked if the logfile is to berotated. The files are mailed to the configured address if maillast and mail are configured.maxsize sizeLog files are rotated when they grow bigger than size bytes even before the  additionally  specifiedtime  interval  (daily, weekly, monthly, or yearly).  The related size option is similar except thatit is mutually exclusive with the time interval options, and it causes log files to be rotated with‐out  regard  for the last rotation time.  When maxsize is used, both the size and timestamp of a logfile are considered.minsize  sizeLog files are rotated when they grow bigger than size bytes, but not before the additionally  speci‐fied  time  interval (daily, weekly, monthly, or yearly).  The related size option is similar exceptthat it is mutually exclusive with the time interval options, and it causes log files to be  rotatedwithout  regard  for the last rotation time.  When minsize is used, both the size and timestamp of alog file are considered.missingokIf the log file is missing, go on to the next  one  without  issuing  an  error  message.  See  alsonomissingok.monthlyLog  files are rotated the first time logrotate is run in a month (this is normally on the first dayof the month).nocompressOld versions of log files are not compressed. See also compress.nocopy Do not copy the original log file and leave it in place.  (this overrides the copy option).nocopytruncateDo not truncate the original log file in place after creating a copy (this overrides  the  copytrun‐cate option).nocreateNew log files are not created (this overrides the create option).nocreateolddirolddir directory is not created by logrotate when it does not exist.nodelaycompressDo  not postpone compression of the previous log file to the next rotation cycle (this overrides thedelaycompress option).nodateextDo not archive  old versions of log files with date extension (this overrides the dateext option).nomail Do not mail old log files to any address.nomissingokIf a log file does not exist, issue an error. This is the default.noolddirLogs are rotated in the directory they normally reside in (this overrides the olddir option).nosharedscriptsRun prerotate and postrotate scripts for every log file which is rotated (this is the  default,  andoverrides  the  sharedscripts option). The absolute path to the log file is passed as first argumentto the script. If the scripts exit with error, the remaining actions will not be  executed  for  theaffected log only.noshredDo not use shred when deleting old log files. See also shred.notifemptyDo not rotate the log if it is empty (this overrides the ifempty option).olddir directoryLogs are moved into directory for rotation. The directory must be on the same physical device as thelog file being rotated, unless copy, copytruncate or renamecopy option is  used.  The  directory  isassumed  to be relative to the directory holding the log file unless an absolute path name is speci‐fied. When this option is used all old versions of the log end up in directory.  This option may  beoverridden by the noolddir option.postrotate/endscriptThe  lines  between  postrotate and endscript (both of which must appear on lines by themselves) areexecuted (using /bin/sh) after the log file is rotated. These directives may only  appear  inside  alog  file definition. Normally, the absolute path to the log file is passed as first argument to thescript. If sharedscripts is specified, whole pattern is passed to the script.  See  also  prerotate.See sharedscripts and nosharedscripts for error handling.prerotate/endscriptThe  lines  between  prerotate  and endscript (both of which must appear on lines by themselves) areexecuted (using /bin/sh) before the log file is rotated  and  only  if  the  log  will  actually  berotated.  These directives may only appear inside a log file definition. Normally, the absolute pathto the log file is passed as first argument to the script.  If  sharedscripts  is  specified,  wholepattern  is  passed  to the script.  See also postrotate.  See sharedscripts and nosharedscripts forerror handling.firstaction/endscriptThe lines between firstaction and endscript (both of which must appear on lines by  themselves)  areexecuted  (using  /bin/sh)  once before all log files that match the wildcarded pattern are rotated,before prerotate script is run and only if at least one log will actually be rotated.  These  direc‐tives  may  only appear inside a log file definition. Whole pattern is passed to the script as firstargument. If the script exits with error, no further processing is done. See also lastaction.lastaction/endscriptThe lines between lastaction and endscript (both of which must appear on lines  by  themselves)  areexecuted  (using  /bin/sh)  once  after all log files that match the wildcarded pattern are rotated,after postrotate script is run and only if at least one log is rotated. These  directives  may  onlyappear inside a log file definition. Whole pattern is passed to the script as first argument. If thescript exits with error, just an error message is shown (as this  is  the  last  action).  See  alsofirstaction.preremove/endscriptThe  lines  between  preremove  and endscript (both of which must appear on lines by themselves) areexecuted (using /bin/sh) once just before removal of a log file.  The logrotate will pass  the  nameof file which is soon to be removed. See also firstaction.rotate countLog  files are rotated count times before being removed or mailed to the address specified in a maildirective. If count is 0, old versions are removed rather than rotated.size sizeLog files are rotated only if they grow bigger then size bytes. If size is followed by k,  the  sizeis  assumed  to  be in kilobytes.  If the M is used, the size is in megabytes, and if G is used, thesize is in gigabytes. So size 100, size 100k, size 100M and size 100G are all valid.sharedscriptsNormally, prerotate and postrotate scripts are run for each log which is rotated  and  the  absolutepath  to  the  log file is passed as first argument to the script. That means a single script may berun multiple times for log file entries which match multiple  files  (such  as  the  /var/log/news/*example).  If  sharedscripts  is  specified,  the scripts are only run once, no matter how many logsmatch the wildcarded pattern, and whole pattern is passed to them.  However, if none of the logs  inthe  pattern  require  rotating, the scripts will not be run at all. If the scripts exit with error,the remaining actions will not be executed for any logs. This option overrides  the  nosharedscriptsoption and implies create option.shred  Delete  log files using shred -u instead of unlink().  This should ensure that logs are not readableafter their scheduled deletion; this is off by default.  See also noshred.shredcycles countAsks GNU shred(1) to overwrite log files count times before deletion.  Without this option,  shred'sdefault will be used.start countThis  is the number to use as the base for rotation. For example, if you specify 0, the logs will becreated with a .0 extension as they are rotated from the original log files.  If you specify 9,  logfiles  will  be  created  with  a .9, skipping 0-8.  Files will still be rotated the number of timesspecified with the rotate directive.su user groupRotate log files set under this user and group instead of using default user/group  (usually  root).user  specifies  the user name used for rotation and group specifies the group used for rotation. Ifthe user/group you specify here does not have sufficient privilege to make files with the  ownershipyou've specified in a create instruction, it will cause an error.tabooext [+] listThe  current taboo extension list is changed (see the include directive for information on the tabooextensions). If a + precedes the list of extensions, the current taboo extension list is  augmented,otherwise it is replaced. At startup, the taboo extension list contains .rpmsave, .rpmorig, ~, .dis‐abled, .dpkg-old, .dpkg-dist, .dpkg-new, .cfsaved, .ucf-old,  .ucf-dist,  .ucf-new,  .rpmnew,  .swp,.cfsaved, .rhn-cfg-tmp-*weekly [weekday]Log  files  are  rotated  once each weekday, or if the date is advanced by at least 7 days since thelast rotation (while ignoring the exact time).  The weekday intepretation  is  following:   0  meansSunday, 1 means Monday, ..., 6 means Saturday; the special value 7 means each 7 days, irrespectivelyof weekday.  Defaults to 0 if the weekday argument is omitted.yearly Log files are rotated if the current year is not the same as the last rotation.

Linux日志系统-03:logrotate主配置文件详解相关推荐

  1. Linux(centos)系统各个目录的作用详解

    转自:Linux(centos)系统各个目录的作用详解 现在公司的服务器使用CentOS系统,在网上找到了这篇介绍linux各个目录的文章,觉得十分不错,所以拿来存个档. 整理之后如下: 文件系统的类 ...

  2. linux dstat 监控软件,Linux 全能系统监控工具dstat的实例详解

    全能系统监控工具dstat dstat 是一个可以取代vmstat,iostat,netstat和ifstat这些命令的多功能产品.dstat克服了这些命令的局限并增加了一些另外的功能,增加了监控项, ...

  3. java linux tracert_Linux系统中tracert命令使用详解

    Linux系统中Tracert命令用来显示数据包到达目标主机是所经过的路径.下面由学习啦小编为大家整理了linux系统中tracert命令使用详解,希望对大家有帮助! Linux系统中tracert命 ...

  4. Linux /etc下用户和用户组配置文件详解

    /1.etc/passwd配置文件详解 passwd配置文件是保存计算机用户相关信息的文件,该文件每行按冒号分隔,有7列,分别如下: 示例:fc:X:1000:1000:fc:/home/fc:/bi ...

  5. linux 日志按大小切割_nginx入门详解(六)- 日志切割

    上一章讲解了nginx的目录加密功能,本章重点介绍nginx的日志切割. 笨办法学linux:nginx入门详解(五)- 目录加密​zhuanlan.zhihu.com 在第二章,我们探讨了nginx ...

  6. httpd二之主配置文件详解、测试工具、压力测试ab

    本文主要讲述httpd的主配置文件中可以配置的选项以及参数,以2.2系列的为主,在http2.4以后会添加一些新的功能和模块,配置文件可能也会有一些差别,关于2.4的配置文件将在后续推出,敬请期待! ...

  7. linux dns主配置文件,RHEL 5下DNS的主配置文件详解

    wangyu 于 2009-10-09 17:16:05发表: 用RHEL5默认安装了DNS服务,当使用service named start时发现缺少named.conf.如下所示: [root@l ...

  8. Linux安装Maven、POM及配置文件详解

    下载Maven 下载地址 https://maven.apache.org/download.cgi 下载maven安装包 [root@oahzero]# wget https://mirrors.t ...

  9. 【Linux】循序渐进学运维-tomcat配置文件详解

    文章目录 目录结构及作用 tomcat配置文件 1. context.xml 2. web.xml 3. server.xml 4. tomcat-users.xml 运维常用配置文件讲解 1. 整体 ...

最新文章

  1. wampserver环境配置局域网访问
  2. oracle exists 变量,Num58 Oracle总结
  3. lt;二gt;读lt;lt;大话设计模式gt;gt;之策略模式
  4. 多传感器信息融合算法总结
  5. 定时器里面的作用域问题
  6. JAVA基础:Hibernate外键关联与HQL语法
  7. [NOTE] WebGoat v8.2.2学习笔记
  8. CentOS6.4下安装TeamViewer8
  9. 狂奔的瑞幸咖啡讲了一个好故事 但还缺失一种 “感觉”
  10. python汉字排序规则_Python 中文排序
  11. 演示和解析Flex布局中的各种属性
  12. Java获取四分位数
  13. tiny4412开发板Android篇_3基于tiny4412的Android系统的烧写(SD卡烧写到emmc)
  14. 坐标转换中的七参数详谈
  15. 网络安全——防火墙详解
  16. 几种常见代码管理工具比较(2009)
  17. 英伟达哭晕在厕所,4090Ti显卡被春晚“首发”
  18. 链路聚合的手工与LACP配置
  19. 反常积分(广义积分)存在判别法
  20. 智能建筑系统(中英)

热门文章

  1. 【JetPack】ViewBinding 视图绑定组件 ( 启用模块 | 视图绑定定制 | 绑定类名称生成规则 | 绑定类字段生成规则 | 绑定类获取根视图 | 绑定类获取布局组件 )
  2. 【Android 应用开发】Android 图表绘制 achartengine 示例解析
  3. 【Android 应用开发】Android - 时间 日期相关组件
  4. Leetcode 912. Sort an Array
  5. Python爬虫从入门到放弃(十二)之 Scrapy框架的架构和原理
  6. Java数据库连接池实现原理
  7. 【MFC】在CHtmlView中准确判断页面加载完成
  8. 爬虫五 Beautifulsoup模块详细
  9. Seetaface 向树莓派 移植
  10. 【转】浅析C语言的非局部跳转:setjmp和longjmp