SIGN IN / UP
    opened image

    Clearing inodes

    Inodes (node indexes) represent the number of files that are allowed to be created on the disk. These are special data structures in the file system that contain information about files, directories, and other objects on the disk. Each file or object in the file system occupies one inode. To check the number of available inodes in the file system, use the command:

    df-i

    If the output is similar to the image below and you have run out of inodes for the file system on the server, you should free inodes. This is the process of removing inodes that are no longer in use or that are over the limit set on the disk. This may include deleting temporary files, logs, old backups, and other unnecessary files.

    Running an inode cleanup daily can be justified in cases where you have a large number of sessions that are not properly managed or leave temporary files, causing the inode limit to be exhausted.

    Reasons to clear inodes:

    •      Too many sessions: If your website or your PHP scripts don't properly manage sessions, it can result in a lot of temporary session files being created. Over time, these files can accumulate and take up many inodes. Cleaning will help remove stale session files and prevent exceeding the inode limit.
    •      Misconfigured PHP scripts: Some PHP scripts or web applications may create temporary files or cache data that is not automatically deleted. If these files accumulate over time, it can cause inodes to run out. Daily cleaning will help remove such temporary files and free up inodes.
    •      Error Prevention: Preemptive inode flushing is a proactive precautionary measure to prevent the complexities of running out of inodes. If you know that your site or your scripts may be creating a lot of temporary files or sessions, regular cleanup will help keep it balanced and prevent inode exhaustion problems.
    •      Performance improvement: When inodes are exhausted, it can lead to errors in the functioning of the file system. There may be delays in reading, writing, or accessing files. Performing a daily/weekly cleanup will help keep the file system performance at an optimal level.
    •      Troubleshooting and crashes: Running out of inodes can cause errors and crashes in various system components, especially if the file system is used by many applications or users. Daily/weekly cleaning will help prevent these issues and keep your system running smoothly.

    Analysis.

    To determine the number of inodes and find the corresponding folders, you can use the following commands:

    find / -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort-n

    Clearing inodes for ISPmanager.

    ISPmanager is a hosting control panel that provides tools for managing web servers, domains, mailboxes, databases and other hosting resources. To clear inodes in ISPmanager, run the following commands:

    find /var/www/*/data/mod-tmp -name "sess_*" -type f -exec rm {} \;
    find /var/www/*/data/bin-tmp -name "sess_*" -type f -exec rm {} \;

     

    Clearing inodes for VestaCP.

    VestaCP is a free hosting control panel that offers a simple and intuitive interface to manage your web server, domains, databases and other hosting resources. To clear inodes in VestaCP, use the following command:

    /usr/bin/find /home/admin/tmp/ -type f -name "sess*" -delete

    If there are many users in the VestaCP panel, then you should use the command:

    /usr/bin/find /home/*/tmp/ -type f -name "sess*" -delete

    Clearing inodes by cron with VestaCP. If you have a site that creates a lot of sessions, it is recommended to add the following command to your daily task (cron) to automatically clean up inodes:

    nano /etc/cron

    0 0 * * * /usr/bin/find /home/*/tmp/ -type f -name "sess*" -delete

    Here 0 0 * * * means that the task will be executed every day at midnight. You can set the task execution time to your liking using the cron syntax.

    Skript with a cycle.

    If the directory contains a huge number of files (over 50-100 thousand), and deleting files using standard methods is impossible, you can run a script with a loop to delete files one by one in the `/home/admin/tmp` folder:

    screen
    cd /home/admin/tmp
    for i in `ls`; do rm -f $i; done

    However, this process is lengthy and will take several hours. It is recommended to run in a screen session.

    Or:

    1. Rename the `mod_tmp` folder to `mod_tmp_old`. For new sessions, create a new `mod_tmp` folder.
    2. Clean up the `mod_tmp_old` folder with the command:

    find mod_tmp_old/ -type f -mmin +360 -delete

    The command looks for ordinary files in the directory and tmp that were modified more than 6 hours ago and deletes them.

    Conclusions.

    Cleaning up inodes is an important process for maintaining the efficiency and stability of operating systems with a large number of sites.