linux:logrotate
差别
这里会显示出您选择的修订版和当前版本之间的差别。
后一修订版 | 前一修订版 | ||
linux:logrotate [2017/11/23 17:42] – 创建 memory | linux:logrotate [2023/12/03 10:24] (当前版本) – 外部编辑 127.0.0.1 | ||
---|---|---|---|
行 3: | 行 3: | ||
[[https:// | [[https:// | ||
+ | logrotate 基于 [[linux: | ||
+ | ===== Configuration ===== | ||
+ | |||
+ | 配置文件位于 ''/ | ||
+ | |||
+ | <code conf> | ||
+ | # see "man logrotate" | ||
+ | # 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 / | ||
+ | |||
+ | # no packages own wtmp and btmp -- we'll rotate them here | ||
+ | / | ||
+ | monthly | ||
+ | create 0664 root utmp | ||
+ | minsize 1M | ||
+ | rotate 1 | ||
+ | } | ||
+ | |||
+ | / | ||
+ | missingok | ||
+ | monthly | ||
+ | create 0600 root utmp | ||
+ | rotate 1 | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ==== Directives ==== | ||
+ | |||
+ | 下面对一些常用的指令进行说明 | ||
+ | |||
+ | === 基础 === | ||
+ | |||
+ | **compress**:日志将会使用 '' | ||
+ | |||
+ | **copytruncate**:复制原有日志,并将原有日志文件尺寸 truncate 至 0 。该功能可解决一些程序仍然往旧日志写入新日志内容的问题。 | ||
+ | |||
+ | **create [mode owner group], create [owner group]** :日志创建权限 | ||
+ | |||
+ | **ifempty**: 即使日志为空,仍然 Rotate 日志,'' | ||
+ | |||
+ | **missingok**:日志不存在时不报告错误 | ||
+ | |||
+ | **rotate**:rotate 保留份数,默认为 0,当值为 0 时,旧日志将会被删除 | ||
+ | |||
+ | **size [size]**:当文件大小超过 '' | ||
+ | |||
+ | === 格式 === | ||
+ | |||
+ | **dateext**:存档时使用 '' | ||
+ | |||
+ | === 频率 === | ||
+ | |||
+ | **daily**:每天 '' | ||
+ | |||
+ | **hourly**:每小时 '' | ||
+ | |||
+ | **weekly [weekday]**:每 '' | ||
+ | |||
+ | **monthly**:每个月 '' | ||
+ | |||
+ | ===== Usage ===== | ||
+ | |||
+ | 以下以 nginx 的 logrotate 配置文件来说明常用的用法。 | ||
+ | |||
+ | <code conf / | ||
+ | / | ||
+ | daily # 每天备份一次 | ||
+ | copytruncate | ||
+ | missingok | ||
+ | rotate 60 # 保留60份日志 | ||
+ | compress | ||
+ | delaycompress | ||
+ | notifempty | ||
+ | create 640 nginx adm # 创建日志文件的权限 | ||
+ | dateext | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | ===== Reference ===== | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// |
linux/logrotate.1511430144.txt.gz · 最后更改: 2023/12/03 10:24 (外部编辑)