Linux system inodes resources are exhausted. How to solve it?

Time:2021-12-26

Linux system inodes resources are exhausted. How to solve it?

Inodes introduction

Under Linux system, the file data is stored in the “block”, and the meta information of the file, such as the creator of the file, the creation date of the file, the size of the file, etc. This area for storing file meta information is called inode, which is translated into Chinese as “index node”. Inode also takes up hard disk space. When the hard disk is formatted, the operating system automatically divides the hard disk into two areas. One is the data area, which stores file data; The other is the inode table, which stores the information contained in the inode.

The size of each inode node is generally 128 bytes or 256 bytes. The total number of inode nodes is given during formatting. Generally, one inode is set every 1KB or 2KB. Assuming that in a 1GB hard disk, the size of each inode node is 128 bytes and an inode is set every 1KB, the size of the inode table will reach 128MB, accounting for 12.8% of the whole hard disk.

Inodes resource exhausted

The use of inodes is similar to the use of storage space. They can’t create files or execute some commands normally. When inodes are used up, there may still be storage space. In this case, a large number of small files are generated and inode tables are full.

In general, inodes only use a few percent when the storage space is used up, so it is easy to ignore the monitoring of inodes usage.

Use the network diagram to illustrate that inodes is exhausted but disk space is not used up: check the disk space usage and use the DF commandLinux system inodes resources are exhausted. How to solve it?To view the usage of inodes, use the DF – I command

Linux system inodes resources are exhausted. How to solve it?

The above two commands can use the – h parameter, and the commands are DF – H and DF – hi. As you can see from the figure, 71% of disk space is used, but 100% of inodes is used.

Inodes depletion resolution

The size of inodes is determined when the partition is formatted. It is related to the size of the partition. The larger the partition, the larger the inodes, and vice versa.

The root directory partition of Linux operating system is generally small. If small files are generated regularly and not cleaned up in time, it is easy to cause inodes to fill up.

Inodes full solution steps:

1. View the directory with the most files

for i in /*; do echo $i; find $i | wc -l; done

If the directory range is determined, write / * to the specific point

Finally, it is found that there are too many small files in the / var / spool / postfix / maildrop directory. The reasons are as follows: when Linux executes cron, it will send the output and warning information in the cron execution script to the cron owner in the form of e-mail. Because sendmail and postfix in the customer’s environment do not work normally and the mail is not sent successfully, all small files are stacked in the maildrop directory. In addition, due to the lack of automatic cleaning mechanism, a large number of files are stacked in this directory.

After investigation, it is found that there is a timing task for clock synchronization every minute under the root user, and the timing task generates a small file every minute.

2. Delete a large number of files

Ls | xargs - n | 1000 # RM - RF # need to use the xargs command, otherwise the deletion will fail.

summary

1. In terms of settings, add mailto = “” in the first line of crontab – E, and no files will be generated

2. Redirect: set a directed output file for scheduled tasks. Scheduled tasks that do not require log output can redirect logs to / dev / null, as follows:

*/10 * * * * /tmp/test.sh >/dev/null 2>&1

3. Scheduled file cleanup

Find Directory - type | F - Mtime + 30 | xargs - n | 1000 | RM - F**

4. Monitoring the use of inodes

Note: you should pay attention to the writing method of crontab and the regular cleaning of generated files

_ Source:https://www.cnblogs.com/cheyu…

Linux system inodes resources are exhausted. How to solve it?