快捷搜索:   nginx

linux下logrotate 配置和理解--2

四、使用include 选项覆盖缺省

  当 /etc/logrotate.conf 读入时,include 指定的中的转储将覆盖缺省的,如下例:

  # linuxconf 的参数

  /var/log/htmlaccess.log

  { errors jim

  notifempty

  nocompress

  weekly

  prerotate

  /usr/bin/chattr -a /var/log/htmlaccess.log

  endscript

  postrotate

  /usr/bin/chattr +a /var/log/htmlaccess.log

  endscript

  }

  /var/log/netconf.log

  { nocompress

  monthly

  }

  在这个例子中,当 /etc/logrotate.d/linuxconf 文件被读入时,下面的参数将覆盖/etc/logrotate.conf中缺省的参数。

  Notifempty

  errors jim

  五、为指定的文件配置转储参数

  经常需要为指定文件配置参数,一个常见的例子就是每月转储/var/log/wtmp。为特定文件而使用的参数格式是:

  # 注释

  /full/path/to/file

  {

  option(s)

  }

  下面的例子就是每月转储 /var/log/wtmp 一次:

  #Use logrotate to rotate wtmp

  /var/log/wtmp

  {

  monthly

  rotate 1

  }

六、其他需要注意的问题

  1、尽管花括号的开头可以和其他文本放在同一行上,但是结尾的花括号必须单独成行。

  2、使用 prerotate 和 postrotate 选项

  下面的例子是典型的脚本 /etc/logrotate.d/syslog,这个脚本只是对

  /var/log/messages 有效。

  /var/log/messages

  {

  prerotate

  /usr/bin/chattr -a /var/log/messages

  endscript

  postrotate

  /usr/bin/kill -HUP syslogd

  /usr/bin/chattr +a /var/log/messages

  endscript

  }

  第一行指定脚本对 花括号外的/var/log/messages 有效

  prerotate 命令指定转储以前的动作/usr/bin/chattr -a 去掉/var/log/messages文件的“只追加”属性 endscript 结束 prerotate 部分的脚本postrotate 指定转储后的动作

  /usr/bin/killall -HUP syslogd

  用来重新初始化系统日志守护程序 syslogd

  /usr/bin/chattr +a /var/log/messages

  重新为 /var/log/messages 文件指定“只追加”属性,这样防治程序员或用户覆盖此文件。

  最后的 endscript 用于结束 postrotate 部分的脚本

  3、logrotate 的运行分为三步:

  判断系统的日志文件,建立转储计划以及参数,通过cron daemon 运行下面的代码是 Red Hat Linux 缺省的crontab 来每天运行logrotate。

  #/etc/cron.daily/logrotate

  #! /bin/sh

  /usr/sbin/logrotate /etc/logrotate.conf

  4、/var/log/messages 不能产生的原因:

  这种情况很少见,但是如果你把/etc/services 中的 514/UDP 端口关掉的话,这个文件就不能产生了。

(责任编辑:阿里猫)

顶(0)
踩(0)

您可能还会对下面的文章感兴趣:

最新评论