加入收藏 | 设为首页 | 会员中心 | 我要投稿 源码网 (https://www.900php.com/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 服务器 > 搭建环境 > Windows > 正文

详解Centos 7和Centos 6系统的/tmp目录自动清理规则及区别

发布时间:2019-10-19 20:03:50 所属栏目:Windows 来源:波波说运维
导读:副标题#e# 概述 分享最近应用碰到的一个奇怪bug,一开始以为是代码上的问题,找了一段时间发现居然是因为系统的一个自动清理规则导致,下面一起来看看吧~ 一、应用报错: logwire.core.exceptions.GeneralUnhandledException:服务端未处理异常 ... Causedby
副标题[/!--empirenews.page--]

概述

分享最近应用碰到的一个奇怪bug,一开始以为是代码上的问题,找了一段时间发现居然是因为系统的一个自动清理规则导致,下面一起来看看吧~

一、应用报错:

  1. logwire.core.exceptions.GeneralUnhandledException: 服务端未处理异常  
  2. ...  
  3. Caused by: org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is  
  4. java.io.IOException: The temporary upload location [/tmp/tomcat.5454715517323162300.8031/work/Tomcat/localhost/ROOT] is not valid  
  5. ....  
  6. Caused by: java.io.IOException: The temporary upload location [/tmp/tomcat.5454715517323162300.8031/work/Tomcat/localhost/ROOT] is not valid 

报错截图:

详解Centos 7和Centos 6系统的/tmp目录自动清理规则及区别

详解Centos 7和Centos 6系统的/tmp目录自动清理规则及区别

二、思路

CentOS 7 系统有一个默认定时器会每隔 1 天执行一次临时目录清理操作,把 /tmp 目录下所有超过 10 天没有任何变动的子目录全部删除。

若某个 Logwire 系统的用户操作不太活跃,则 tomcat 运行临时目录(形如: /tmp/tomcat.xxx)会被删除。这时候如果有用户试图上传文件,则服务端会报错:

The temporary upload location [/tmp/tomcat.5454715517323162300.8031/work/Tomcat/localhost/ROOT] is not valid

三、处理过程

在 /usr/lib/tmpfiles.d/tmp.conf 文件中增加配置项:

  1. x /tmp/tomcat* 

以上配置表示在清理临时目录时忽略所有以 /tmp/tomcat 开头的目录和文件

详解Centos 7和Centos 6系统的/tmp目录自动清理规则及区别

四、CentOS系统的/tmp目录自动清理规则

1、CentOS 7

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. # This file is part of systemd.  
  2. #  
  3. # systemd is free software; you can redistribute it and/or modify it  
  4. # under the terms of the GNU Lesser General Public License as published by  
  5. # the Free Software Foundation; either version 2.1 of the License, or  
  6. # (at your option) any later version.  
  7. # See tmpfiles.d(5) for details  
  8. # Clear tmp directories separately, to make them easier to override  
  9. v /tmp 1777 root root 10d # 清理/tmp下10天前的目录和文件  
  10. v /var/tmp 1777 root root 30d # 清理/var/tmp下30天前的目录和文件  
  11. # Exclude namespace mountpoints created with PrivateTmp=yes  
  12. x /tmp/systemd-private-%b-*  
  13. X /tmp/systemd-private-%b-*/tmp  
  14. x /var/tmp/systemd-private-%b-*  
  15. X /var/tmp/systemd-private-%b-*/tmp 

也就是CentOS 7 系统有一个默认定时器会每隔 1 天执行一次临时目录清理操作,把 /tmp 目录下所有超过 10 天没有任何变动的子目录全部删除。

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

  1. x /tmp/tomcat.* 

2、CentOS 6

CentOS6以下系统(含)使用watchtmp + cron来实现定时清理临时文件的效果,该目录下的脚本每天执行一次。

如果要修改的话,可以修改此 tmpwatch 脚本(用 root 用户修改或其他用户 sudo 修改):

(编辑:源码网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

热点阅读