使用springboot内置tomcat部署项目到服务器,一段时间后文件上传不了

      SpringBoot项目使用内嵌tomcat jar包方式部署,一段时间后上传文件出现问题,上传不了,查看服务器日志发现是tomcat生成的临时目录tmp不存在,被linux系统机制自动清除了。

最简单的临时解决方案:重新启动项目,如果想要一劳永逸可以采用下面的方案。

方案1> 修改springboot的配置文件
配置参数 server.tomcat.basedir 不在tmp下创建目录。

方案2>修改清理 /tmp 下面的文件的机制
在/usr/lib/tmpfiles.d/tmp.conf/文件末尾追加 x /tmp/tomcat*


找到 usr/lib/tmpfiles.d 打开这个配置文件
[root@bogon tmpfiles.d]# cat 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
Clear tmp directories separately, to make them easier to override
v /tmp 1777 root root 10d #清理tmp下十天没有发生变化的文件
Exclude namespace mountpoints created with PrivateTmp=yes
x /tmp/systemd-private-%b-*     #排除这个目录
X /tmp/systemd-private-%b-*/tmp   #排除这个目录,不排除这个目录包含的子目录/文件

文章参考:https://www.cnblogs.com/operationhome/p/12375003.html

你可能感兴趣的:(笔记,SpringBoot,上传文件错误,内置tomcat,jar包部署)