| 副标题[/!--empirenews.page--] 概述 分享最近应用碰到的一个奇怪bug,一开始以为是代码上的问题,找了一段时间发现居然是因为系统的一个自动清理规则导致,下面一起来看看吧~ 一、应用报错: logwire.core.exceptions.GeneralUnhandledException: 服务端未处理异常  ...  Caused by: org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is  java.io.IOException: The temporary upload location [/tmp/tomcat.5454715517323162300.8031/work/Tomcat/localhost/ROOT] is not valid  ....  Caused by: java.io.IOException: The temporary upload location [/tmp/tomcat.5454715517323162300.8031/work/Tomcat/localhost/ROOT] is not valid 
 报错截图: 
 
 二、思路 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 文件中增加配置项: x /tmp/tomcat* 
 以上配置表示在清理临时目录时忽略所有以 /tmp/tomcat 开头的目录和文件 
 四、CentOS系统的/tmp目录自动清理规则 1、CentOS 7 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文件的设定,默认配置有: # This file is part of systemd.  #  # systemd is free software; you can redistribute it and/or modify it  # under the terms of the GNU Lesser General Public License as published by  # the Free Software Foundation; either version 2.1 of the License, or  # (at your option) any later version.  # See tmpfiles.d(5) for details  # Clear tmp directories separately, to make them easier to override  v /tmp 1777 root root 10d # 清理/tmp下10天前的目录和文件  v /var/tmp 1777 root root 30d # 清理/var/tmp下30天前的目录和文件  # Exclude namespace mountpoints created with PrivateTmp=yes  x /tmp/systemd-private-%b-*  X /tmp/systemd-private-%b-*/tmp  x /var/tmp/systemd-private-%b-*  X /var/tmp/systemd-private-%b-*/tmp 
 也就是CentOS 7 系统有一个默认定时器会每隔 1 天执行一次临时目录清理操作,把 /tmp 目录下所有超过 10 天没有任何变动的子目录全部删除。 可以配置这个文件,比如你不想让系统自动清理/tmp下以tomcat开头的目录,那么增加下面这条内容到配置文件中即可: x /tmp/tomcat.* 
 2、CentOS 6 CentOS6以下系统(含)使用watchtmp + cron来实现定时清理临时文件的效果,该目录下的脚本每天执行一次。 如果要修改的话,可以修改此 tmpwatch 脚本(用 root 用户修改或其他用户 sudo 修改): (编辑:南平站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |