1, Problem Description:
Rm/tmp/access_log after deleting large files through RM, the view disk results show that the disk occupation is still 100% and the space is not released.
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 portion is stored on disk, the data corresponding to the pointer from the Meta-data purged , the space occupied by the file data can be overwritten and written to the new content, the reason for the deletion of the Access_log file, the space is not released, because the httpd process is still writing to this file, resulting in the deletion of access_log files, However, the pointer part of the file corresponding to the process lock, not purged from the meta-data, and because the pointer is not deleted, then the system kernel thinks the file has not been deleted, so it is not surprising that the DF command to query the space is not released.
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:
Lsof |grep Delete
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 problem is basically 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 log operation, to free the disk space occupied by the file, the best way is to empty the file online, can be completed by the following command:
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.
This article is from the "Silent Dialogue" blog, please be sure to keep this source http://chbinmile.blog.51cto.com/6085145/1872633
Linux deletes files, but space does not release