CentOS-7中tmp目录的清理规则
source link: http://www.eryajf.net/3142.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
因为目前业务当中遇到程序启动之后自动在/tmp
目录下生成一个tomcat.1234546854
的文件,有时候程序在上传文件的时候会读取一下这个目录,但是如果服务很久(超过十天)没发布过,那么这个目录可能就被自动清理了,然后导致服务报错。然后在网上看到了如下内容:
CentOS6 以下系统(含)使用 watchtmp + cron
来实现定时清理临时文件的效果,这点在 CentOS7 发生了变化,在 CentOS7 下,系统使用 systemd 管理易变与临时文件,与之相关的系统服务有 3 个:
systemd-tmpfiles-setup.service :Create Volatile Files and Directories
systemd-tmpfiles-setup-dev.service:Create static device nodes in /dev
systemd-tmpfiles-clean.service :Cleanup of Temporary Directories
相关的配置文件也有 3 个地方:
/etc/tmpfiles.d/*.conf
/run/tmpfiles.d/*.conf
/usr/lib/tmpfiles.d/*.conf
/tmp
目录的清理规则主要取决于 / usr/lib/tmpfiles.d/tmp.conf
文件的设定,默认的配置内容为:
v /tmp 1777 root root 10d
v /var/tmp 1777 root root 30d
x /tmp/systemd-private-%b-*
X /tmp/systemd-private-%b-*/tmp
x /var/tmp/systemd-private-%b-*
X /var/tmp/systemd-private-%b-*/tmp
我们可以配置这个文件,比如你不想让系统自动清理 “/tmp下以
tomcat` 开头的目录,那么增加下面这条内容到配置文件中即可:
x /tmp/tomcat.*
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK