How to deal with high inode usage in linux
I received a monitoring alarm a few days ago, saying that the Inode node space is insufficient. I have not dealt with this kind of problem before, so I will record the processing process for future reference.
A high Inode usage rate will not affect the normal operation of the system and the creation of new files, but when the usage rate reaches 100%, even though the disk still has space, new files cannot be created.
This is because when a file is stored on the disk, both inode and block are used. The inode stores file attribute information, including file name, size, permission, time, storage location, etc., while the block stores the actual data.
So if the inode runs out, no new files can be created even if the disk still has space.
The reason for this situation is generally that there are too many small files in the system, occupying a large number of inode nodes. Find the corresponding directory and delete some files.
Note: The following execution results are not real alarm values, but just operation examples.
1. View disk partition and inode usage
df -h #View disk partition usage df -ih #View inode node usage
2. Find and delete temporary files
ll -rt /tmp | wc -l find /tmp -type f -exec rm {} \;
3. Delete 0-byte files
find /home -type f -size 0 -exec rm {} \;
4. Find the directory containing a large number of files and delete
for i in /*; do echo $i; find $i |wc -l; done for i in /var/*; do echo $i; find $i |wc -l; done
There is a high probability that there are a large number of files in /var/spool under the /var directory, enter this directory to view
for i in /var/spool/*; do echo $i; find $i |wc -l; done
Found that there are a lot of files in the /var/spool/postfix/ directory, continue to enter the directory to view
Explanation: So many files generated under /var/spool/postfix/ are caused by the crontab timing task. After the timing task is executed, an email is sent to inform the contact person, but if the sending fails, it will be generated under postfix, so so many files are generated. Junk files.
for i in /var/spool/postfix/*; do echo $i; find $i |wc -l; done
It can be seen that the files are mainly concentrated in the /var/spool/postfix/maildrop directory, just enter this directory to clear
Execute the rm command to delete directly, it may report an error that the parameter list is too long, you can delete it in the following ways
ls | xargs -n 500 rm -rf #-n indicates the number of parameters passed at a time
After execution, use df -ih to check the Inode node usage again, and find that it is back to normal.
Category: Linux