CentOS 6.x
我很困惑我放在 /tmp/ 中的文件何时被删除。
/etc/cron.daily/tmpwatch 有以下内容:
#! /bin/sh
flags=-umc
/usr/sbin/tmpwatch "$flags" -x /tmp/.X11-unix -x /tmp/.XIM-unix \
-x /tmp/.font-unix -x /tmp/.ICE-unix -x /tmp/.Test-unix \
-X '/tmp/hsperfdata_*' 10d /tmp
/usr/sbin/tmpwatch "$flags" 30d /var/tmp
for d in /var/{cache/man,catman}/{cat?,X11R6/cat?,local/cat?}; do
if [ -d "$d" ]; then
/usr/sbin/tmpwatch "$flags" -f 30d "$d"
fi
done
Run Code Online (Sandbox Code Playgroud)
第 5 行中读取的部分-X '/tmp/hsperfdata_*' 10d /tmp
让我相信我放在 /tmp/ 中的文件将保留 10 天(假设它们在删除过程中没有被锁定,或者该目录安装在 tmpfs 文件系统上)。
那是对的吗?
在 CentOS 6 上,似乎tmpwatch
是基于文件上次访问的时间(时间)决定删除。如果已经 10 天 (10d) 或更长时间,那么它会在tmpwatch
运行时被删除。
从tmpwatch
手册页:
By default, tmpwatch dates files by their atime (access time), not
their mtime (modification time). If files aren't being removed when
ls -l implies they should be, use ls -u to examine their atime to see if
that explains the problem.
Run Code Online (Sandbox Code Playgroud)
同样来自手册页:
The time parameter defines the threshold for removing files. If the
file has not been accessed for time, the file is removed. The time
argument is a number with an optional single-character suffix specifying
the units: m for minutes, h for hours, d for days. If no suffix is
specified, time is in hours.
Run Code Online (Sandbox Code Playgroud)
在 RHEL7/CENTOS7 上,有一个每天运行的 systemd 目标:(systemd-tmpfiles-clean.timer
替换/etc/cron.daily/tmpwatch
)。默认值为OnBootSec=15min
和OnUnitActiveSec=1d
。引用systemd.timer联机帮助页:
OnBootSec= 定义了一个与机器启动时间相关的计时器。
OnUnitActiveSec= 定义一个计时器,该计时器与该计时器激活的单元上次激活的时间有关。
所以现在每天清理 /tmp ,大约在系统启动的那个小时:所以时间是 undefined。对于大型部署,并非所有虚拟机同时执行清理,很好。
对于历史,运行:
$ journalctl -u systemd-tmpfiles-clean
Mar 12 21:44:17 c7.klabs.be systemd[1]: Starting Cleanup of Temporary Directories...
Mar 12 21:44:18 c7.klabs.be systemd[1]: Started Cleanup of Temporary Directories.
Run Code Online (Sandbox Code Playgroud)
其中“开始清理”实际上意味着“完成”。
归档时间: |
|
查看次数: |
28366 次 |
最近记录: |