5

CentOS-7中tmp目录的清理规则

 3 years ago
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.
neoserver,ios ssh client
CentOS-7中tmp目录的清理规则 |坐而言不如起而行! 二丫讲梵
> 术业专攻 > Linux基础 > 系统与优化 > CentOS-7中tmp目录的清理规则
本文预计阅读时间 3 分钟

因为目前业务当中遇到程序启动之后自动在/tmp目录下生成一个tomcat.1234546854的文件,有时候程序在上传文件的时候会读取一下这个目录,但是如果服务很久(超过十天)没发布过,那么这个目录可能就被自动清理了,然后导致服务报错。然后在网上看到了如下内容:

CentOS6 以下系统(含)使用 watchtmp + cron 来实现定时清理临时文件的效果,这点在 CentOS7 发生了变化,在 CentOS7 下,系统使用 systemd 管理易变与临时文件,与之相关的系统服务有 3 个:

  1. systemd-tmpfiles-setup.service :Create Volatile Files and Directories
  2. systemd-tmpfiles-setup-dev.service:Create static device nodes in /dev
  3. systemd-tmpfiles-clean.service :Cleanup of Temporary Directories

相关的配置文件也有 3 个地方:

  1. /etc/tmpfiles.d/*.conf
  2. /run/tmpfiles.d/*.conf
  3. /usr/lib/tmpfiles.d/*.conf

/tmp 目录的清理规则主要取决于 / usr/lib/tmpfiles.d/tmp.conf 文件的设定,默认的配置内容为:

  1. v /tmp 1777 root root 10d
  2. v /var/tmp 1777 root root 30d
  3. x /tmp/systemd-private-%b-*
  4. X /tmp/systemd-private-%b-*/tmp
  5. x /var/tmp/systemd-private-%b-*
  6. X /var/tmp/systemd-private-%b-*/tmp

我们可以配置这个文件,比如你不想让系统自动清理 “/tmp下以tomcat` 开头的目录,那么增加下面这条内容到配置文件中即可:

  1. x /tmp/tomcat.*

weinxin

二丫讲梵 , 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明CentOS-7中tmp目录的清理规则

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK