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

How to solve the problem that files have been deleted but space is not released in LINUX

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

This article mainly introduces "how to solve the problem that the file in LINUX has been deleted but the space is not released". In the daily operation, I believe many people have doubts about how to solve the problem that the file in LINUX has been deleted but the space is not released. The editor consulted all kinds of data and sorted out a simple and useful method of operation. I hope it will be helpful for you to answer the question of "how to solve the problem that the file in LINUX has been deleted but the space is not released". Next, please follow the editor to study!

1. Error phenomenon

The monitoring system of OPS sends a notification, reporting that a server is full. Log in to the server to check, and there is really no space in the root partition, as shown in the following figure:

First of all, we will explain some deletion policies of the server. Because Linux does not have the Recycle Bin function, all the files to be deleted on our online server will be moved to the system / tmp directory first, and then the data in the / tmp directory will be cleared regularly. There is nothing wrong with this strategy itself, but it is found that there is no separate / tmp partition in the system partition of this server, so the data under / tmp actually takes up the space of the root partition. Now that the problem is found, delete some big data in the / tmp directory and execute the following command to check the three largest data files under / tmp, as shown below:

[root@localhost~] # du-s / tmp/* | sort-nr | head-369206016 / tmp/access_log36 / tmp/hsperfdata_root36 / tmp/hsperfdata_mapred

Through the command output, it is found that there is a 66g file access_log in the / tmp directory. This file should be an access log file generated by apache. Judging from the log size, the apache log file has not been cleaned for a long time. It is basically determined that the root space caused by this file is full. After confirming that this file can be deleted, perform the following deletion operation:

[root@localhost ~] # rm / tmp/access_log

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

As you can see from the output, the root partition space is still not freed. What's going on?

2. Solution

Generally speaking, space will not be released after deleting a file, but there are exceptions, such as a file is locked by a process, or a process has been writing data to the file, and so on. To understand this problem, you need to know the storage mechanism and storage structure of files under Linux.

The storage of a file in the file system is divided into two parts: the data part and the pointer part. The pointer is located in the meta-data of the file system. After the data is deleted, the pointer is cleared from the meta-data, while the data part is stored on disk. After the pointer corresponding to the data is removed from the meta-data, the space occupied by the file data part can be overwritten and written to the new content. The space has not been released because the httpd process has been writing to this file, resulting in the deletion of the access_log file, but the corresponding pointer part of the file has not been removed from the meta-data due to the process lock, and because the pointer has not been deleted, then the system kernel thinks that the file has not been deleted, so it is not surprising that the query space has not been released through the df command.

3. Troubleshooting

Now that you have a solution to the problem, let's see if any process has been writing data to the acess.log file. Here, you need to use the lsof command under Linux, through which you can get a list of files that have been deleted but are still occupied by the application. The command execution is shown below:

From the output, you can see that the / tmp/acess.log file is locked by the process httpd, and the httpd process has been writing log data to this file. From the seventh column, it can be seen that the log file size is only 70G, while the total system root partition size is only 100G. It can be seen that this file is the main culprit for the system root partition space exhaustion. The "deleted" status in the last column indicates that the log file has been deleted. However, because the process is still writing data to this file, the space has not been released.

4. Solve the problem

At this point, 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, you can also restart the operating system. However, this is not the best way to deal with the constant log operation of files in this process. To free up the disk space occupied by files, the best way is to empty the file online, which can be done with the following command:

[root@localhost ~] # echo "" > / tmp/acess.log

This method not only frees disk space immediately, but also ensures that the process continues to write logs to files. This method is often used to clean up log files generated by Apache, Tomcat, Nginx and other Web services online. Thank you for reading. I hope I can help you. Please stay tuned. We will try our best to share more excellent articles.

At this point, the study on "how to solve the problem that the files in LINUX have been deleted but the space is not released" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

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