Live2D

tomcat临时目录被清理,程序运行出错,多种解决方案

项目正常运行,有一天突然发现,文件上传无法使用。经过查询,说是tomcat缓存文件夹被请清理。

 

 

1、为什么要缓存文件

       因为流取一次消费之后,后面无法再从流中获取数据,所以缓存方便后续复用;这一块后面详细说明

 

2、为什么目录会不存在

        springboot启动时会创建一个/tmp/tomcat.*/work/Tomcat/localhost/ROOT的临时目录作为文件上传的临时目录,但是该目录会在n天之后被系统自动清理掉,这个清理是由linux操作系统完成的,具体的配置如下 vim /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

 

 3、解决方案:

方案一:重启服务(临时目录会自动生成,线上不推荐)

 

方案二:启动时增加参数-Djava.io.tmpdir=自定义目录

 

方案三:自定义tomcat目录

server:
  tomcat:
    basedir: /data/java/config/tmp

 

方案四:使用mkdir -p 命令手动创建该不存在的目录(一般不使用)

 

方案五:设置其不被删除(推荐)

#修改删除配置文件
vim /usr/lib/tmpfiles.d/tmp.conf

#添加一行
x /tmp/tomcat.*

 



 

 

 

 

参考:

1、https://blog.csdn.net/weixin_43675226/article/details/118940013

2、https://www.cnblogs.com/siran/p/14109902.html

 

posted @ 2022-05-17 10:59  -涂涂-  阅读(2789)  评论(0)    收藏  举报