Analysis of problems with deleted files but not released space in O & M Cases

Source: Internet
Author: User
Tags apache log file apache log


1. Error

The O & M monitoring system sends a notification, reporting that the space of one server is full. log on to the server and check that the root partition does not have space, as shown in:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/3A/45/wKioL1O7cFfxA4-BAAB6s9F7xWE508.jpg "Title =" 1.png" alt = "wKioL1O7cFfxA4-BAAB6s9F7xWE508.jpg"/>


Here, we will first describe some server deletion policies. Because Linux does not have the recycle bin function, all files to be deleted on our online server will first be moved to the system/tmp directory, then, the data in the/tmp directory is cleared regularly. This policy is correct, but check shows that the system partition of this server is not separately divided into/tmp partitions, so the data in/tmp actually occupies the space of the root partition. Now that the problem is found, delete some big data in the/tmp directory and run the following command to check the maximum three data files in/tmp, as shown in:


650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M02/3A/45/wKiom1O7cJSQBV9gAABmZmwuBFw448.jpg "Title =" 2.png" alt = "wkiom1o7cjsqbv9gaabmzmwubfw448.jpg"/>

Command output shows that there is a GB file access_log in the/tmp directory. This file should be an access log file generated by Apache. From the log size perspective, the Apache log file has not been cleared for a long time. It is basically determined that the root space is full due to this file. After confirming that this file can be deleted, perform the following delete operations:

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

Check whether the system root partition space is released, as shown in:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/3A/45/wKioL1O7cHXhiY_EAAB6s9F7xWE440.jpg "Title =" 3.png" alt = "wkiol1o7chxhiy_eaab6s9f7xwew.jpg"/>


The output shows that the root partition space is still not released. Why?


2. Solution

In general, there will be no cases where the space will not be released after the file is deleted, but there are exceptions, such as the file is locked by the process, or a process has been writing data to the file, etc. To understand this problem, you need to know the file storage mechanism and Storage Structure in Linux.

A file is stored in the file system in two parts: the data part and the pointer part. The pointer is located in the meta-data file system. After the data is deleted, this pointer is removed from meta-data, and the data is stored in the disk. After the pointer corresponding to the data is cleared from meta-data, the space occupied by part of the file data can be overwritten and new content can be written. After the access_log file is deleted, the space has not been released, it is because the HTTPd process is still writing content to this file, so although the access_log file is deleted, the pointer of the file is not cleared from meta-data because the process is locked, since the pointer has not been deleted, the system kernel considers that the file has not been deleted, so it is not surprising that the query space through the DF command has not been released.


3. troubleshooting

Now that you have the idea of solving the problem, let's see if there are any processes that are always going to acess. the lsof command in Linux is used to write data in log files. You can use this command to obtain a list of files that have been deleted but are still occupied by the application. The command is executed as follows:

650) This. width = 650; "src =" http://s3.51cto.com/wyfs02/M00/3A/45/wKiom1O7cLfB1_vUAAGEQwwNhWI351.jpg "Title =" 4.png" alt = "wkiom1o7clfb1_vuaageqwwnhwi351.jpg"/>


The output result shows/tmp/acess. the log file is locked by the HTTPd process, and the HTTPd process has been writing log data to the file. From the seventh column, we can see that the log file size is only 70 GB, the total size of the system root partition is only 100 Gb. As a result, this file is the culprit that causes space depletion of the system root partition. In the "deleted" status in the last column, this log file has been deleted, but the space is not released because the process is still writing data to this file.


4. Solve the Problem

The problem has been fixed here. There are many ways to solve this problem. The simplest way is to shut down or restart the HTTPd process. Of course, you can also restart the operating system, however, this is not the best method. The best way for such a process to constantly write logs to files and release the disk space occupied by files is to clear the files online, you can run the following command:

[[Email protected] ~] # Echo "">/tmp/acess. Log

In this way, the disk space can be released immediately, and the process can continue to write logs to files. This method is often used to clean up log files generated by web services such as Apache, tomcat, and nginx online.


This article is from the "Technical Achievement dream" blog and will not be reposted!

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.