Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the / tmp directory automatic cleaning rules and differences between Centos 7 and Centos 6 systems

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Centos 7 and Centos 6 system / tmp directory automatic cleaning rules and what is the difference, many novices are not very clear about this, in order to help you solve this problem, the following editor will explain in detail for you, people with this need can come to learn, I hope you can get something.

Overview

Share a strange bug encountered by the app recently. At first, I thought it was a code problem. After looking for it for a period of time, I found that it was caused by an automatic cleaning rule of the system. Let's take a look.

First, the application reports errors:

Logwire.core.exceptions.GeneralUnhandledException: the server side did not handle the exception. Caused by: org.springframework.web.multipart.MultipartException: Failed to parse multipart servlet request; nested exception is java.io.IOException: The temporary upload location [/ tmp/tomcat.5454715517323162300.8031/work/Tomcat/localhost/ROOT] is not valid.... Caused by: java.io.IOException: The temporary upload location [/ tmp/tomcat.5454715517323162300.8031/work/Tomcat/localhost/ROOT] is not valid

Second, train of thought

The CentOS 7 system has a default timer that performs a temporary directory cleanup every other day, deleting all subdirectories in the / tmp directory that have not changed for more than 10 days.

If the user operation of a Logwire system is not very active, the tomcat running temporary directory (such as: / tmp/tomcat.xxx) will be deleted. At this time, if a user tries to upload a file, the server will report an error:

The temporary upload location [/ tmp/tomcat.5454715517323162300.8031/work/Tomcat/localhost/ROOT] is not valid

Third, the processing process

Add configuration items to the / usr/lib/tmpfiles.d/tmp.conf file:

X / tmp/tomcat*

The above configuration means that all directories and files starting with / tmp/tomcat are ignored when cleaning up temporary directories

4. Automatic cleaning rules of / tmp directory in CentOS system

1 、 CentOS 7

Under CentOS7, the system uses systemd to manage volatile and temporary files, and there are three related system services:

Systemd-tmpfiles-setup.service: Create Volatile Files and Directories systemd-tmpfiles-setup-dev.service:Create static device nodes in / dev systemd-tmpfiles-clean.service: Cleanup of Temporary Directories

There are also three places for the relevant configuration files:

/ etc/tmpfiles.d/*.conf / run/tmpfiles.d/*.conf / usr/lib/tmpfiles.d/*.conf

The cleaning rules of the / tmp directory mainly depend on the settings of the / usr/lib/tmpfiles.d/tmp.conf file. The default configuration is as follows:

# 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.1of 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 # clean up directories and files 10 days ago under / tmp v / var/tmp 1777 root root 30d # clean up directories and files 30 days ago under var/tmp # 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

That is, the CentOS 7 system has a default timer that performs a temporary directory cleanup every other day, deleting all subdirectories in the / tmp directory that have not changed for more than 10 days.

You can configure this file. For example, if you don't want the system to automatically clean up directories under / tmp that start with tomcat, you can add the following to the configuration file:

X / tmp/tomcat.*

2 、 CentOS 6

CentOS6 the following systems (included) use watchtmp + cron to achieve the effect of regularly cleaning temporary files, and the scripts in this directory are executed once a day.

If you want to modify it, you can modify this tmpwatch script (with root user or other user sudo):

Find a statement like this:

/ usr/sbin/tmpwatch "$flags"-x / tmp/.X11-unix-x / tmp/.XIM-unix\-x / tmp/.font-unix-x / tmp/.ICE-unix-x / tmp/.Test-unix\-X'/ tmp/hsperfdata_*'-X'/ tmp/.hdb*lock'-X'/ tmp/.sapstartsrv*.log'\ 10d / tmp

Add the-X'/ tmp/tomcat*' parameter to the statement so that all directories and files that start with / tmp/tomcat are ignored during cleanup:

/ usr/sbin/tmpwatch "$flags"-x / tmp/.X11-unix-x / tmp/.XIM-unix\-x / tmp/.font-unix-x / tmp/.ICE-unix-x / tmp/.Test-unix\-X'/ tmp/hsperfdata_*'-X'/ tmp/.hdb*lock'-X'/ tmp/.sapstartsrv*.log'\-X'/ tmp/tomcat*'\ 10d / tmp is it helpful for you to read the above content? If you want to know more about the relevant knowledge or read more related articles, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report