关于springboot /tmp目录
一、生成机制
默认创建的临时目录/tmp/tomcat.*.端口/… (work/Tomcat/localhost/ROOT)
8086是端口
对于Multipart(form-data)的方式处理请求时,默认就是在tomcat-docbase目录下创建临时文件的。
二、清理原因
CentOS 7 会清理 10 天前的 /tmp 目录的文件。 springboot 框架启动后,创建的 /tmp/tomcat.* 目录正好在清理策略内,所以会被自动清理。
cat /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
三、解决方法
1、配置不删除tmp目录下的tomcat(不推荐)
vi /usr/lib/tmpfiles.d/tmp.conf# 添加一行
x /tmp/tomcat.*重启服务
systemctl restart systemd-tmpfiles-clean
2、修改配置文件
server.tomcat.basedir=/app/xxxx/tmp
原理: 把 tomcat 工作目录指向 jar 的当前目录,这样临时也不会被自动清理.
注意:推荐在启动脚本上,每次启动 jar 服务前,自动删除缓存文件,
类似于启动时自动清理 tomcat 的 work 和 tmp 目录。
server.tomcat.basedir=/tmp/systemd-private-8080-tomcat.service-springboot
原理: /tmp/systemd-private-%b-* 这个目录是不会被自动清理的,所以把临时目录名配置成这样,可以绕过此问题
3、启动时增加参数
指定临时目录为/app/xxx/tmp
-Djava.io.tmpdir=/app/xxx/tmp(自定义路径)
4、代码中增加系统默认目录配置
//1.该处也需要配置下
@SpringBootApplication(exclude = {MultipartAutoConfiguration.class})
public class TestApplication {public static void main(String[] args) {SpringApplication.run(TestApplication .class, args);}/*** 解决文件上传,临时文件夹被程序自动删除问题** 文件上传时自定义临时路径* @return*/@BeanMultipartConfigElement multipartConfigElement() {MultipartConfigFactory factory = new MultipartConfigFactory();//2.该处就是指定的路径(需要提前创建好目录,否则上传时会抛出异常)factory.setLocation("/data/uploadtmp");return factory.createMultipartConfig();}
}
关于springboot /tmp目录相关推荐
- android tmp目录权限不够,/tmp目录下执行脚本失败提示Permission denied
Linux上执行Shell脚本运行失败提示Permission denied一个问题,挺好的问题,切中了知识盲点. 问题现象 Shell脚本在/tmp目录下,执行./test.sh运行失败,提示Per ...
- mysql /tmp目录爆满问题的处理
mysql /tmp目录爆满问题的处理 突然收到zabbix告警,说mysql服务器的/目录磁盘空间不足. 登录到服务器,看了下发现100GB的根目录,居然使用了差不多90GB.这台服务器上只跑了一个 ...
- linux centos7 /tmp目录 自动清理规则
CentOS7下,系统使用systemd管理易变与临时文件,与之相关的系统服务有3个: systemd-tmpfiles-setup.service :Create Volatile Files an ...
- centos7 tmp目录 自动清理规则
CentOS6以下系统(含)使用watchtmp + cron来实现定时清理临时文件的效果,这点在CentOS7发生了变化,在CentOS7下,系统使用systemd管理易变与临时文件,与之相关的系统 ...
- linux的tmp目录不会清空,关于Linux系统中/tmp目录的清除问题
关于Linux系统中/tmp目录的清除问题 相当悲剧的问题是,之前保存在/tmp目录中的一些数据丢了.现在发现已经是第二次发生了,前一次以为是其他人误操作删除的,今天才发现这个和系统有关系.完全是因为 ...
- 目录:SpringBoot学习目录
SpringBoot配套源码地址:gitee.com/hengboy/spr- SpringCloud配套源码地址:gitee.com/hengboy/spr- SpringBoot相关系列文章请访问 ...
- linux下mysql tmp满_MySQL服务器/tmp目录被占满
案例分享-MySQL服务器/tmp目录被占满 描述: MySQL服务器在每天的22点/tmp目录磁盘空间被占满,持续10分钟左右,然后自动恢复./tmp目录大小10G,平时可用空间8G左右.MySQL ...
- CentOS7的/tmp目录自动清理规则(转)
CentOS7的/tmp目录自动清理规则 CentOS6以下系统(含)使用watchtmp + cron来实现定时清理临时文件的效果,这点在CentOS7发生了变化,在CentOS7下,系统使用sys ...
- 删除Linux下/tmp目录引起的不正常登录系统
现象:/tmp占用400M的空间(里面全部是乱七八糟的东西) 动作:删除/tmp目录 后果:造成只能启动到控制台模式 应急: 1 创建目录:#mkdir /tmp 结果系统在控制台模式登录和X win ...
最新文章
- 15crmo焊接后多长时间探伤_15CrMo十五铬钼属于合金钢?、下面来解释一下
- 启动mysqld报 mysql the server quit without updating pid file
- django之Ajax
- T-Sql 递归查询
- python 定时执行 爬虫 模块_浅析python实现scrapy定时执行爬虫
- 16岁上大学,25岁博士毕业,她还是南大医学院最年轻的博导!
- 什么是485转光纤?485光纤转换器功能特点及技术参数详解
- request mysql 接口_TP5接口开发
- IE overflow:hidden失效的解决方法:
- IOS中扩展机制Category和associative
- 解决360 安装补丁智能忽略的问题!
- 关于广州“开四停四“违法逻辑实现
- 计算机语言排行之我见
- java英语apple_apple是什么意思_apple在线翻译_英语_读音_用法_例句_海词词典
- Initializationfailedforhttps://start.spring.ioPleasecheckURLnetwor的解决方法本人亲测
- tp5的时间查询,查询时间戳是否在某一天中
- 什么是RCT实时时钟?(STM32中RTC时钟源)
- 虚拟码号应用行业介绍!
- Riak - 安装运维篇(1)
- 4-10 阶乘计算升级版