[英]Tomcat: Configuring temp folder
I have some webservices running on tomcat that make tasks on a quite big repository. 我在tomcat上运行了一些Web服务,这些服务在很大的存储库中执行任务。 After a few days of run I realized that the tomcat temp folder ($CATALINA_HOME/temp) contains a huge amount of files which may affect the server behavior. 运行几天后,我意识到tomcat临时文件夹($ CATALINA_HOME / temp)包含大量文件,可能会影响服务器行为。 Is there any way to configure the temp folder in order to delete files older then a certain amount of time or to disable the temp folder if it's not needed? 有什么方法可以配置temp文件夹,以便删除早于一定时间的文件,或者在不需要时禁用temp文件夹?
If your files' life-times are max "10" minutes then you can use below cron job to periodically clean your temp directory. 如果文件的生存时间最长为“ 10”分钟,则可以使用下面的cron作业定期清理您的temp目录。
Let's say your tomcat's temp directory is "/usr/server/tomcat7/temp"
: 假设您的tomcat的临时目录为"/usr/server/tomcat7/temp"
:
Cron job notation: Cron工作符号:
0 1 * * * find /usr/server/tomcat7/temp -type f -mmin +10 -delete
Code description: 代码说明:
0 1 * * *
--> everyday at 1am 0 1 * * *
->每天凌晨1点 find /usr/server/tomcat7/temp
--> find files in directory "/usr/server/tomcat7/temp" find /usr/server/tomcat7/temp
>在目录“ / usr / server / tomcat7 / temp”中查找文件 -type f
--> only the items whiches' types are "file" -type f
>仅其类型为“文件”的项目 -mmin +10
--> only the ones older than "10" minutes -mmin +10
>仅早于“ 10”分钟的那些 -delete
--> delete them -delete
- >删除 For the ones who are new to Cron: 对于Cron的新手:
How to set the Cron job (Centos version): 如何设置Cron作业(Centos版本):
sudo yum install cron
如果未安装,请使用sudo yum install cron
crontab -e
(this will open the config file with vim ) 使用crontab -e
打开cron配置文件(这将使用vim打开配置文件) :x
" and press enter 要保存并退出,请先按“ esc”,然后键入“ :x
”,然后按Enter installing new crontab
" on the command line 您必须在命令行上看到“ installing new crontab
” Now you are completely ready to go. 现在您已经完全准备好出发了。
I think disabling the temp dir makes no sense as it is obvoiusly a requirement for the deployed app. 我认为禁用temp dir是没有意义的,因为这对于已部署的应用程序来说无疑是必需的。 File upload is usually implemented using temp files for example. 例如,通常使用临时文件来实现文件上传。
If I were you I would write a simple shell script for the cleanup and put it into the crontab for example. 如果您是我,我会写一个简单的shell脚本进行清理,然后将其放入crontab中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.