Linux索引節點(Inode:no space for device)用滿導致的一次故障

問題描述

在storm測試環境集羣上上nimbus和supervisor自動掛調,重啓時顯示no space for device,也不能創建,添加文件及目錄,df -h查看


ilesystem            Size  Used Avail Use% Mounted on
/dev/vda1              40G  2.9G   35G   8% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/vdc1             100G  3.1G   92G   4% /home
/dev/vdd1              50G  180M   48G   1% /home/xxx/hard_disk/0
/dev/vde1              50G  180M   48G   1% /home/xxx/hard_disk/1
/dev/vdf1              50G  180M   48G   1% /home/xxx/hard_disk/2
/dev/vdg1              50G  180M   48G   1% /home/xxx/hard_disk/3
/dev/vdh1              50G  180M   48G   1% /home/xxx/hard_disk/4

顯示空間使用很少,空間足夠, df -i 顯示


Filesystem            Inodes   IUsed   IFree IUse% Mounted on
/dev/vda1            2621440   75783 2545657    3% /
tmpfs                1007672       1 1007671    1% /dev/shm
/dev/vdc1             102400   85159   85159  100% /home
/dev/vdd1              51200      13   51187    1% /home/xxx/hard_disk/0
/dev/vde1              51200      18   51182    1% /home/xxx/hard_disk/1
/dev/vdf1              51200      18   51182    1% /home/xxx/hard_disk/2
/dev/vdg1              51200      18   51182    1% /home/xxx/hard_disk/3
/dev/vdh1              51200      18   51182    1% /home/xxx/hard_disk/4

發現inode使用率達到100%,這才找到問題

什麼是inode

一、inode

硬盤的最小存儲單位叫做”扇區”(Sector)。每個扇區儲存512字節(相當於0.5KB)。操作系統讀取硬盤的時候,不會一個個扇區地讀取,這樣效率太低,而是一次性讀取一個”塊”(block),每個”塊”(block)由八個連續的sector組成。這種由多個扇區組成的”塊”,是文件存取的最小單位。”塊”的大小,最常見的是4KB,文件數據都儲存在”塊”中,那麼還必須找到一個地方儲存文件的元信息,比如文件的創建者、文件的創建日期、文件的大小等等。這種儲存文件元信息的區域就叫做inode,中文譯名爲”索引節點”。每一個文件都有對應的inode,裏面包含了與該文件有關的一些信息。

二、inode的內容

inode包含文件的元信息,具體有以下內容:
  * 文件的字節數
  * 文件擁有者的User ID
  * 文件的Group ID
  * 文件的讀、寫、執行權限
  * 文件的時間戳,共有三個:ctime指inode上一次變動的時間,mtime指文件內容上一次變動的時間,atime指文件上一次打開的時間。
  * 鏈接數,即有多少文件名指向這個inode
  * 文件數據block的位置
可以用stat命令查看某個文件的inode信息:

[root@stream-e5s3c home]# stat apps
  File: `apps'
  Size: 4096            Blocks: 8          IO Block: 4096   directory
Device: fd02h/64770d    Inode: 4123        Links: 3
Access: (0700/drwx------)  Uid: (  456/    apps)   Gid: (  456/    apps)
Access: 2015-03-14 04:02:07.069500045 +0800
Modify: 2015-03-13 15:35:57.886985112 +0800
Change: 2015-03-13 15:36:28.209482045 +0800

三、inode的大小

inode也會消耗硬盤空間,所以硬盤格式化的時候,操作系統自動將硬盤分成兩個區域。一個是數據區,存放文件數據;另一個是inode區(inode table),存放inode所包含的信息。
每個inode節點的大小,一般是128字節或256字節。inode節點的總數,在格式化時就給定,一般是每1KB或每2KB就設置一個inode。假定在一塊1GB的硬盤中,每個inode節點的大小爲128字節,每1KB就設置一個inode,那麼inode table的大小就會達到128MB,佔整塊硬盤的12.8%。
使用df -i可以查看每個硬盤分區的inode總數和已經使用的數量

解決辦法

進入到home路徑下,用 ls -i 查看每個路徑所找用的信息:

   71 xxxxxxxx                     83969 xxxxxxxx      79877 xxxxxxxx  
   70 curator-recipes-2.5.0.jar       11 lost+found    86017 xxxxxxxx  
   68 curator.tar.gz               90113 mapred        88065 xxxxxxxx  
94209 xxxxxxxx                     79873 mobilereco    98305 xxxxxxxx  
   69 fds.jar                         55 ro_test       81921 vpp
69633 hdfs                         73729 spark         20481 yarn
92161 xxxxxxxx                     96257 xxxxxxxx  
  129 xxxxxxxx                      8193 storm

會在每個目錄前面顯示該路面所用的inode數目

如何釋放inode信息,情查看下面信息

It’s quite easy for a disk to have a large number of inodes used even if the disk is not very full.
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.
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, not the directory entry. If a file has two directory entries linked to it, deleting one will not free the inode.
Additionally, you can delete a directory entry but, if a running process still has the file open, the inode won’t be freed.
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 "$1" | wc -l) $1' >/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_$$

or

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

list the files and remove these files to free inode.

參考文獻
1. Howto Free Inode Usage
2. Linux索引節點(Inode)用滿導致的一次故障
3. Linux的inode的理解

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章