linux清除空间

诡异的磁盘空间100%报警分析得出df -h与du -sh *的根本性差别




1,进去df -h下,确实100%了,如下所示:
[root@localhost ~]# df -h
文件系统              容量  已用 可用 已用% 挂载点
/dev/mapper/VolGroup00-LogVol00
                      113G  113G     0 100% /
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 8.8G     0  8.8G   0% /dev/shm
确实已经100%了,再去/去检查


2,去/根目录check,du -sh *
[root@localhost ~]# cd /
[root@localhost /]# du -sh *
7.8M bin
6.9M boot
131M data
196K dev
111M etc
178M home
131M lib
23M lib64
8.6G usr
184M var
30M varnish-3.0.3
56M zabbix-2.0.8


看到,占据的磁盘空间所有的加起来也不到30G,可是df -h下来,确实100%呢?差异在哪里?


google资料,找到 http://www.chinaunix.net/old_jh/6/465673.html 里面有这么2段话:
(1):
When you open a file, you get a pointer.  Subsequent writes to this file 
references this file pointer.  The write call does not check to see if the file 
is there or not.  It just writes to the specified number of characters starting 
at a predetermined location.  Regardless of whether the file exist or not, disk 
blocks are used by the write operation. 


The df command reports the number of disk blocks used while du goes through the 
file structure and and reports the number of blocks used by each directory.  As 
far as du is concerned, the file used by the process does not exist, so it does 
not report blocks used by this phantom file.  But df keeps track of disk blocks 
used, and it reports the blocks used by this phantom file.
以及leolein朋友的回复:
谢谢,就是这个原因。 
我因为磁盘快满了就删除了一些过期的文件,可能应用程序还在使用这些文件句柄,所以导致了我说的问题。 
我把所有的应用程序都停止后,du和df的结果就大致相同了


(2):
This section gives the technical explanation of why du and df sometimes report
different totals of disk space usage.


When a program that is running in the background writes to a file while the
process is running, the file to which this process is writing is deleted.
Running df and du shows a discrepancy in the amount of disk space usage.  The
df command shows a higher value.




如果文件已经删除了,但是还有残留的进程引用它(具体不知道怎么表达好),
则df看到的空间使用量并没有减去那些已经删除的文件。而创建并写入一个文件是,
判断空间是否足够是依据df(本人认为),所以df 100%的时候就不能写入文件了。
--但是创建文件是可以的,我做过测试。
查看这些残留进程(姑且这么称呼,我也不知道那些进程叫什么)的方法是lsof




lsof |grep /var/log/tomcat8/catalina.out




java       7272           tomcat8    1w      REG                8,1 151420395520    6815774 /var/log/tomcat8/catalina.out (deleted)
java       7272           tomcat8    2w      REG                8,1 151420395520    6815774 /var/log/tomcat8/catalina.out (deleted)
java       7272  7273     tomcat8    1w      REG                8,1 151420395520    6815774 /var/log/tomcat8/catalina.out (deleted)
java       7272  7273     tomcat8    2w      REG                8,1 151420395520    6815774 /var/log/tomcat8/catalina.out (deleted)
java       7272  7274     tomcat8    1w      REG                8,1 151420395520    6815774 /var/log/tomcat8/catalina.out (deleted)
java       7272  7274     tomcat8    2w      REG                8,1 151420395520    6815774 /var/log/tomcat8/catalina.out (deleted)
java       7272  7275     tomcat8    1w      REG                8,1 151420395520    6815774 /var/log/tomcat8/catalina.out (deleted)
java       7272  7275     tomcat8    2w      REG                8,1 151420395520    6815774 /var/log/tomcat8/catalina.out (deleted)
java       7272  7276     tomcat8    1w      REG                8,1 151420395520    6815774 /var/log/tomcat8/catalina.out (deleted)


然后把这些进程都kill掉就可以释放空间了。


http://blog.itpub.net/26230597/viewspace-1242675/
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值