问题描述
今天有开发同学反馈性能测试平台上传文件失败!
后台报错显示临时文件路径不合法,之前我自己也发现过这个问题,只要重启服务之后就可以恢复正常
由于这个问题出现频率比较低,就一直没有去找原因
今天又遇到,决定彻底解决一下!
问题定位
根据日志报错信息检查了临时目录路径,发现是上传文件时,临时文件目录没有了
这个临时目录是在启动的时候自动创建的,但是为什么会消失呢?
搜寻一番之后发现,目录消失的原因是:centos7
会自动删除/tmp
下超过10天的临时文件
OK,那只要不让临时文件被删除,问题即可解决!
解决步骤:
重启服务,
/tmp
下重新生成了临时文件目录,文件上传恢复正常把不想要被删除的
tomcat
临时文件追加到配置文件tmp.conf
vim /usr/lib/tmpfiles.d/tmp.conf
可以看到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/tomcat.*
x /tmp/tomcat.*