Linux 如何释放 inode 的使用?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/653096/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to Free Inode Usage?
提问by neversaint
I have a disk drive where the inode usage is 100% (using df -i
command).
However after deleting files substantially, the usage remains 100%.
我有一个磁盘驱动器,其中 inode 使用率为 100%(使用df -i
命令)。但是在大量删除文件后,使用率仍然是100%。
What's the correct way to do it then?
那么正确的做法是什么?
How is it possible that a disk drive with less disk space usage can have higher Inode usage than disk drive with higher disk space usage?
磁盘空间使用率较低的磁盘驱动器如何可能比磁盘空间使用率较高的磁盘驱动器具有更高的 Inode 使用率?
Is it possible if i zip lot of files would that reduce the used inode count?
如果我压缩很多文件会减少使用的 inode 数量吗?
采纳答案by paxdiablo
It's quite easy for a disk to have a large number of inodes used even if the disk is not very full.
即使磁盘不是很满,磁盘也很容易使用大量 inode。
An inode is allocated to a file so, if you have gazillions of files, all 1 byte each, you'll run out of inodes long before you run out of disk.
一个 inode 被分配给一个文件,因此,如果您有无数个文件,每个文件都是 1 个字节,那么在您用完磁盘之前很久就会用完 inode。
It's also possible that deleting files will not reduce the inode count if the files have multiple hard links. As I said, inodes belong to the file, notthe directory entry. If a file has two directory entries linked to it, deleting one will not free the inode.
如果文件有多个硬链接,删除文件也可能不会减少 inode 数量。正如我所说,inode 属于文件,而不是目录条目。如果一个文件有两个链接到它的目录条目,删除一个将不会释放 inode。
Additionally, you can delete a directory entry but, if a running process still has the file open, the inode won't be freed.
此外,您可以删除目录条目,但如果正在运行的进程仍然打开文件,则不会释放 inode。
My initial advice would be to delete all the files you can, then reboot the box to ensure no processes are left holding the files open.
我最初的建议是删除所有可以删除的文件,然后重新启动盒子以确保没有进程保持打开文件。
If you do that and you still have a problem, let us know.
如果您这样做了,但仍有问题,请告诉我们。
By the way, if you're looking for the directories that contain lots of files, this script may help:
顺便说一句,如果您要查找包含大量文件的目录,此脚本可能会有所帮助:
#!/bin/bash
# count_em - count files in all subdirectories under current directory.
echo 'echo $(ls -a "" | wc -l) ' >/tmp/count_em_$$
chmod 700 /tmp/count_em_$$
find . -mount -type d -print0 | xargs -0 -n1 /tmp/count_em_$$ | sort -n
rm -f /tmp/count_em_$$
回答by simon
If you are very unlucky you have used about 100% of all inodes and can't create the scipt.
You can check this with df -ih
.
如果您非常不幸,您已经使用了大约 100% 的所有 inode 并且无法创建 scipt。您可以使用df -ih
.
Then this bash command may help you:
那么这个 bash 命令可能会帮助你:
sudo find . -xdev -type f | cut -d "/" -f 2 | sort | uniq -c | sort -n
And yes, this will take time, but you can locate the directory with the most files.
是的,这需要时间,但您可以找到包含最多文件的目录。
回答by supershwa
eaccelerator could be causing the problem since it compiles PHP into blocks...I've had this problem with an Amazon AWS server on a site with heavy load. Free up Inodes by deleting the eaccelerator cache in /var/cache/eaccelerator if you continue to have issues.
eaccelerator 可能会导致这个问题,因为它将 PHP 编译成块......我在一个负载很重的站点上的 Amazon AWS 服务器上遇到了这个问题。如果问题仍然存在,请通过删除 /var/cache/eaccelerator 中的 eaccelerator 缓存来释放 Inode。
rm -rf /var/cache/eaccelerator/*
(or whatever your cache dir)
(或任何您的缓存目录)
回答by designgroop
We experienced this on a HostGator account (who place inode limits on all their hosting) following a spam attack. It left vast numbers of queue records in /root/.cpanel/comet. If this happens and you find you have no free inodes, you can run this cpanel utility through shell:
在垃圾邮件攻击之后,我们在 HostGator 帐户(他们对所有主机设置 inode 限制)上遇到了这种情况。它在 /root/.cpanel/comet 中留下了大量的队列记录。如果发生这种情况并且您发现没有空闲的 inode,则可以通过 shell 运行此 cpanel 实用程序:
/usr/local/cpanel/bin/purge_dead_comet_files
回答by dardarlt
My solution:
我的解决方案:
Try to find if this is an inodes problem with:
尝试查找这是否是 inode 问题:
df -ih
Try to find root folders with large inodes count:
尝试查找具有大量 inode 计数的根文件夹:
for i in /*; do echo $i; find $i |wc -l; done
Try to find specific folders:
尝试查找特定文件夹:
for i in /src/*; do echo $i; find $i |wc -l; done
If this is linux headers, try to remove oldest with:
如果这是 linux 头文件,请尝试删除最旧的:
sudo apt-get autoremove linux-headers-3.13.0-24
Personally I moved them to a mounted folder (because for me last command failed) and installed the latest with:
我个人将它们移动到一个已安装的文件夹(因为对我来说最后一个命令失败)并安装了最新的:
sudo apt-get autoremove -f
This solved my problem.
这解决了我的问题。
回答by LNamba
My situation was that I was out of inodes and I had already deleted about everything I could.
我的情况是我的 inode 用完了,我已经删除了所有可以删除的内容。
$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 942080 507361 11 100% /
I am on an ubuntu 12.04LTS and could not remove the old linux kernels which took up about 400,000 inodes because apt was broken because of a missing package. And I couldn't install the new package because I was out of inodes so I was stuck.
我在 ubuntu 12.04LTS 上无法删除旧的 linux 内核,这些内核占用了大约 400,000 个 inode,因为 apt 由于缺少软件包而损坏。我无法安装新软件包,因为我的 inode 不足,所以我被卡住了。
I ended up deleting a few old linux kernels by hand to free up about 10,000 inodes
我最终手动删除了一些旧的 linux 内核以释放大约 10,000 个 inode
$ sudo rm -rf /usr/src/linux-headers-3.2.0-2*
This was enough to then let me install the missing package and fix my apt
这足以让我安装丢失的软件包并修复我的 apt
$ sudo apt-get install linux-headers-3.2.0-76-generic-pae
and then remove the rest of the old linux kernels with apt
然后使用 apt 删除其余的旧 linux 内核
$ sudo apt-get autoremove
things are much better now
现在情况好多了
$ df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/sda1 942080 507361 434719 54% /
回答by Anyone_ph
I had the same problem, fixed it by removing the directory sessions of php
我有同样的问题,通过删除php的目录会话来修复它
rm -rf /var/lib/php/sessions/
It may be under /var/lib/php5
if you are using a older php version.
/var/lib/php5
如果您使用的是较旧的 php 版本,它可能会在下面。
Recreate it with the following permission
使用以下权限重新创建它
mkdir /var/lib/php/sessions/ && chmod 1733 /var/lib/php/sessions/
Permission by default for directory on Debian showed drwx-wx-wt
(1733)
显示 Debian 目录的默认权限drwx-wx-wt
(1733)
回答by Razal
We faced similar issue recently, In case if a process refers to a deleted file, the Inode shall not be released, so you need to check lsof /, and kill/ restart the process will release the inodes.
最近我们遇到了类似的问题,如果一个进程引用了一个被删除的文件,inode不会被释放,所以你需要检查lsof /,然后kill/restart进程会释放inode。
Correct me if am wrong here.
如果在这里错了,请纠正我。
回答by VIGNESH
You can use RSYNC to DELETE the large number of files
您可以使用 RSYNC 删除大量文件
rsync -a --delete blanktest/ test/
Create blanktest folder with 0 files in it and command will sync your test folders with large number of files(I have deleted nearly 5M files using this method).
创建包含 0 个文件的空白测试文件夹,命令将同步您的测试文件夹与大量文件(我使用这种方法删除了近 500 万个文件)。
Thanks to http://www.slashroot.in/which-is-the-fastest-method-to-delete-files-in-linux
感谢http://www.slashroot.in/which-is-the-fastest-method-to-delete-files-in-linux