网站首页 文章专栏 spring boot 内置tomcat 在/tmp的临时文件被莫名删除
spring boot 内置tomcat 在/tmp的临时文件被莫名删除
编辑时间:2018年1月30日 09:58 作者:赵彦昌 浏览量:19725

正在写go 代码正顺手的时候,键盘啪啪啪的在我手下响。“看看某个项目后台日志报的什么错”领导发话了。

tail -f project/path/logs/log.log

“再操作一边,重现一下”

果然报错了


ERROR 30375 --- [io-3356-exec-30] c.m.common.exception.RRExceptionHandler  : Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload locati
on [/tmp/tomcat.1924935092075142164.3356/work/Tomcat/localhost/ROOT] is not valid
org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/tmp/tomcat.1924935092075142164.3356/work/T
omcat/localhost/ROOT] is not valid
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)


ls -l /tmp/ 并没有这个tomcat.192xxxx 目录。怎么就没了呢?有人删了?确认后,最近没人操作啊?

会不会系统把这个目录当成垃圾文件给删了呢?于是从这方面开始查找资料,找到如下系统服务有可能

systemd-tmpfiles-clean.service                                                            loaded    inactive dead      Cleanup of Temporary Directories
  systemd-tmpfiles-setup-dev.service                                                        loaded    active   exited    Create Static Device Nodes in /dev
  systemd-tmpfiles-setup.service                                                            loaded    active   exited    Create Volatile Files and Directories
  systemd-tmpfiles-clean.timer                                                              loaded    active   waiting   Daily Cleanup of Temporary Directories

root@~:# man systemd-tmpfiles

man 一下,确定该服务50% 是凶手了, 该服务有如下几个配置文件存放目录:



/etc/tmpfiles.d/*.conf

/run/tmpfiles.d/*.conf

/usr/lib/tmpfiles.d/*.conf
基中在 /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
v /var/tmp 1777 root root 30d

# 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


就是说/tmp 目录下除了下面排除的文件,都TM 给我删了。擦~!

参考:

1.http://www.jinbuguo.com/systemd/tmpfiles.d.html

2.http://0pointer.de/public/systemd-man/tmpfiles.d.html


解决方案在 /usr/lib/tmpfiles.d/ 新建文件把指定目录添加上并规定不让被清除


root@~:# vi /usr/lib/tmpfiles.d/tomcat.conf
d /tmp/tomcat* 0755 root root -
d /tmp/spring.log 0755 root root -
d /tmp/hsperfdata_root 0755 root root -


OK,重启 systemctl restart systemd-tmpfiles-clean

系统发行版本: Centos 7

uname -a

Linux xxx-name 3.10.0-327.36.3.el7.x86_64 #1 SMP Mon Oct 24 16:09:20 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux



经测试上面的方法,不可用

可直接考虑修改spring boot 内置tomcat 的配置

在application.yml


server:
   tomcat:
      basedir=H:/springboot-tomcat-tmp


来说两句吧
最新评论