Linux file deleted, but disk space is not released after DF

Source: Internet
Author: User
Tags apache log

Transfer from https://www.cnblogs.com/xd502djj/p/6668632.html

Linux disk space always alarm, found to large files, after deletion, DF saw disk space is not released.

The following discovery system has been found to alias RM, because Linux does not have a recycle Bin mechanism for delete operations, the RM operation has been customized, the deletion of files moved to the/tmp directory.

I deleted the/temp again, but I still didn't find the disk impact release.

Executive Lsof | grep deleted found that there are a number of processes that have just deleted files, kill the process (or restart the process) OK

Resources

Operation and maintenance of the actual case files have been deleted but the space does not release the problem resolution

1. Error phenomena

Operation and maintenance of the monitoring system to notify, report a server space is full, the login server to view, the root partition does not have space, as shown in:

Here first to explain some of the server's deletion policy, because Linux does not have the Recycle Bin function, our online server all the files to be deleted will first move to the System/TMP directory, and then periodically clear the/tmp directory of data. This strategy itself is not a problem, but by checking that the system partition found on this server does not separate the/TMP partition, so the data in/TMP is actually occupying the space of the root partition. Now that you have found the problem, delete some big data from the/tmp directory, and execute the following command to check the maximum of three data files in/TMP, as shown in:


[Email protected]~]# du-s/tmp/*|sort-nr|head-369206016/tmp/access_log36/tmp/hsperfdata_root36/tmp/ Hsperfdata_mapred

Through the command output found in the/tmp directory has a 66G size file Access_log, this file should be Apache generated access log files, from the log size, it should be a long time no cleanup Apache log files, the basic decision is that this file caused by the root space is full, After confirming that the file can be deleted, perform the following delete operation:

[Email protected] ~]# Rm/tmp/access_log

Then check to see if the system root partition space is freed, as shown in:

From the output you can see that the root partition space is still not released, what's going on?

2, solve the idea

In general, the deletion of files after the space does not release, but there are exceptions, such as the file is locked by the process, or a process has been writing data to this file and so on, to understand this problem, you need to know the Linux file storage mechanism and storage structure.

A file in the file system is divided into two parts: the data part and the pointer part, the pointer is located in the file system Meta-data, the data is deleted, the pointer is removed from the Meta-data, and the data part is stored on the disk, After the data corresponding pointer clears from the Meta-data, the file data portion occupies the space can be overwritten and writes the new content, after the deletion access_log file, the space has not released, is because the httpd process still writes to this file the content, Cause although the Access_log file is deleted, but the corresponding pointer part of the file is locked by the process, not purged from the meta-data, and because the pointer is not deleted, the system kernel thinks the file is not deleted, so it is not surprising to query the space through the DF command.

3. Troubleshooting

Since there is a solution to the problem, then see if there is a process has been writing data to the Acess.log file, here need to use the Linux lsof command, through this command can get a deleted but still be occupied by the application of the file list, command execution as shown:

As you can see from the output,/tmp/ Acess.log file is locked by the process httpd, and the httpd process has been written to this file log data, from the seventh column, the log file size is only 70G, and the total system root partition size is only 100G, it is known that this file is the culprit that causes the system root partition space exhaustion, in the last column of the "deleted" state, indicating that the log file has been deleted, but because the process is still writing data to this file, the space is not released.

4, solve the problem

Here the basic troubleshooting is clear, there are many ways to solve this kind of problem, the simplest way is to shut down or restart the httpd process, of course, can also restart the operating system, but this is not the best way to treat the process of the file write log operations, to free the file occupied disk space, The best way to do this is to empty the file online by completing the following command:

[Email protected] ~]# echo "" >/tmp/acess.log

This way, disk space can not only be released immediately, but also to ensure that the process continues to write to the file log, this method is often used to online clean Apache, Tomcat, Nginx and other Web services generated by the log files.

http://ixdba.blog.51cto.com/2895551/1435781

Linux file deleted, but disk space is not released after DF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.