首先先要解释什么是inode?node
inode在linux中,每一个文件,无论大小是多少都会对应一个inode,inode就是一个专门用来保存文件属性,权限和指针(指向block)linux
inodex满了会致使什么问题?centos
首先,在linux中,有两个概念,就是block和inode,block:用于存放实际数据,inode:存放文件属性,只要这两个其中一个占满空间了,都会致使提示报错“磁盘空间不足”bash
**inodex故障模拟ide
某年某月某日某时,某人在工做中设置crontab定时任务规则保存时,提示“No space left on device”,此时用df -h检查磁盘,发现还有剩余空间.请问是什么缘由及如何排查?什么会致使这种事情发生测试
1.模拟测试环境
系统:centos 7.4,磁盘空间8G,CPU 4核,内存4G(最好给大点,建立文件须要大内存)spa
[root@xmh ~]# mkdir /test [root@xmh ~]# echo /test/{1..6000000}.txt |xargs touch #建立的文件太多了,只能用这种方式建立
2.进入正题指针
#1.当进入编辑cronta或者建立文件时,直接报错,提示磁盘空间不足 [root@xmh ~]# crontab -e /tmp/crontab.MApBTV: No space left on device [root@xmh ~]# touch xmh.txt touch: cannot touch ‘xmh.txt’: No space left on device 2.查看磁盘空间 [root@xmh ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 8.0G 3.2G 4.9G 39% / ##能够发现磁盘容量是空闲不少的 devtmpfs 1.7G 0 1.7G 0% /dev tmpfs 1.7G 0 1.7G 0% /dev/shm tmpfs 1.7G 8.7M 1.7G 1% /run tmpfs 1.7G 0 1.7G 0% /sys/fs/cgroup tmpfs 332M 0 332M 0% /run/user/0 3.查看inode空间 [root@xmh ~]# df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 4193792 4193792 0 100% / #可是inode空间已满了 devtmpfs 422466 395 422071 1% /dev tmpfs 424923 1 424922 1% /dev/shm tmpfs 424923 473 424450 1% /run tmpfs 424923 16 424907 1% /sys/fs/cgroup tmpfs 424923 1 424922 1% /run/user/0 提示:当磁盘容量或inode容量任意一个不足时就都会提示No space left on device
3.解决办法
使用find命令查找大于10M的目录,能够从df -i看出是在 根 /下容量不足,那么咱们就从 / 下开始排查code
[root@xmh ~]# find / -type d -size +10M |xargs ls -lhd #find查找 drwxr-xr-x. 2 root root 97M Feb 15 14:00 /test [root@xmh ~]# ls /test/ |wc -l #对该目录文件数量统计 4168011 #定位好目录后删除小文件 [root@xmh /]# rm -rf /test/* #直接 rm -rf * 的话是删除不了大量的小文件 -bash: /usr/bin/rm: Argument list too long [root@xmh /]# cd /test/ [root@xmh test]# ls |xargs rm -f#删除大量的小文件,使用该命令删除 [root@xmh /]# ls /test/ |wc -l #小文件已经删除了 #再次查看inode容量 [root@xmh ~]# df -i Filesystem Inodes IUsed IFree IUse% Mounted on /dev/sda1 4193792 25973 4167819 1% / #inode容量已恢复正常 devtmpfs 422466 395 422071 1% /dev tmpfs 424923 1 424922 1% /dev/shm tmpfs 424923 473 424450 1% /run tmpfs 424923 16 424907 1% /sys/fs/cgroup tmpfs 424923 1 424922 1% /run/user/0 #删除小文件所在的目录(删除时注意记录该目录的所属用户和权限) [root@jason /]# rm -rf /test/