国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開APP
userphoto
未登錄

開通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開通VIP
詭異的磁盤空間100%報(bào)警分析得出df -h與du -sh *的根本性差別
詭異的磁盤空間100%報(bào)警分析得出df -h與du -sh *的根本性差別 2014-07-30 18:44:15

分類: Linux

前言:
早晨磁盤報(bào)警剛清空完tomcat和nginx日志,使用的命令是類似echo "" > show_web-error.log或者> show_web-debug.log清空語句,然后rm -rf 掉一些tar.gz包,空出來30G空間。而且也關(guān)閉了tomcat的debug信息。剛剛又接到報(bào)警,磁盤100%了。怎么回事?

1,進(jìn)去df -h下,確實(shí)100%了,如下所示:
[root@localhost ~]# df -h
文件系統(tǒng)              容量  已用 可用 已用% 掛載點(diǎn)
/dev/mapper/VolGroup00-LogVol00
                      113G  113G     0 100% /
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 8.8G     0  8.8G   0% /dev/shm
確實(shí)已經(jīng)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
119M logs
16K lost+found
8.0K media
0 misc
8.0K mnt
0 net
0 nohup.out
3.8G opt
15M pcre-8.33
2.1M pcre-8.33.zip
du: 無法訪問 “proc/11575/task/11575/fd/1565”: 沒有那個(gè)文件或目錄
du: 無法訪問 “proc/15403/task/14464/fd/625”: 沒有那個(gè)文件或目錄
0 proc
1.4G product
153M repo
143M root
37M sbin
8.0K selinux
363M soft
8.0K srv
0 sys
20K temp
100K tftpboot
2.1G tmp
8.6G usr
184M var
30M varnish-3.0.3
56M zabbix-2.0.8
[root@localhost /]# 
看到,占據(jù)的磁盤空間所有的加起來也不到30G,可是df -h下來,確實(shí)100%呢?差異在哪里?

3,baidu,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.
以及l(fā)eolein朋友的回復(fù):
謝謝,就是這個(gè)原因。 
我因?yàn)榇疟P快滿了就刪除了一些過期的文件,可能應(yīng)用程序還在使用這些文件句柄,所以導(dǎo)致了我說的問題。 
我把所有的應(yīng)用程序都停止后,du和df的結(jié)果就大致相同了

(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.

如果文件已經(jīng)刪除了,但是還有殘留的進(jìn)程引用它(具體不知道怎么表達(dá)好),則df看到的空間使用量并沒有減去那些已經(jīng)刪除的文件。而創(chuàng)建并寫入一個(gè)文件是,判斷空間是否足夠是依據(jù)df(本人認(rèn)為),所以df 100%的時(shí)候就不能寫入文件了。--但是創(chuàng)建文件是可以的,我做過測(cè)試。查看這些殘留進(jìn)程(姑且這么稱呼,我也不知道那些進(jìn)程叫什么)的方法是lsof
# lsof /home | grep /home/oracle/osinfo | sort +8 | grep '^.*070920.*$'
sadc    17821   root    3w   REG  253,1 326492112 926724 /home/oracle/osinfo/070920sar.data (deleted)
sadc    17861   root    3u   REG  253,1 326492112 926724 /home/oracle/osinfo/070920sar.data (deleted)
sadc    17981   root    3u   REG  253,1 326492112 926724 /home/oracle/osinfo/070920sar.data (deleted)
top     17858   root    1w   REG  253,1 169919916 927111 /home/oracle/osinfo/070920top.data (deleted)
top     17977   root    1w   REG  253,1 169919916 927111 /home/oracle/osinfo/070920top.data (deleted)
注意后面的deleted
然后把這些進(jìn)程都kill掉就可以釋放空間了。

我想起了,我早晨在執(zhí)行echo "" >shop_web.log類似操作的時(shí)候,并沒有停止tomcat應(yīng)用,所以應(yīng)用是一直往log里面寫數(shù)據(jù)的,那么我>的那一刻,是du -sh *可能看到磁盤空間有了,df -h也可以看到磁盤釋放了,但是當(dāng)tomcat應(yīng)用繼續(xù)往shop_web.log里面寫日志的時(shí)候,加載的還是最初打開的那個(gè)執(zhí)行>shop_web.log之前的占據(jù)很大磁盤空間的緩存文件。所以磁盤其實(shí)一直沒有釋放掉,而能堅(jiān)持一天不報(bào)警,是由于我rm了一些tar.gz包所釋放的空間。


4,重啟tomcat和nginx應(yīng)用
所以,我應(yīng)該重啟tomcat和nginx,應(yīng)用不再加載舊的緩存文件,執(zhí)行重啟tomcat命令,由于tomcat應(yīng)用比較多,所以寫了一個(gè)腳本來執(zhí)行
[root@localhost local]# cat /root/start_tomcat_port.sh 
#!/bin/bash
PID=`ps -eaf|grep apache-tomcat-6.0.37_$1 |grep -v grep |grep -v start_tomcat_port |awk '{print $2}'`
echo $1
echo $PID
kill -9 $PID
rm -rf /var/tomcat/$1.pid
/usr/local/apache-tomcat-6.0.37_$1/bin/startup.sh
[root@localhost local]#
執(zhí)行重啟tomcat:
sh /root/start_tomcat_port.sh 6100;
sh /root/start_tomcat_port.sh 6200;
sh /root/start_tomcat_port.sh 6300;
sh /root/start_tomcat_port.sh 6400;
sh /root/start_tomcat_port.sh 6500;
sh /root/start_tomcat_port.sh 6700;
sh /root/start_tomcat_port.sh 7100;
sh /root/start_tomcat_port.sh 7200;
sh /root/start_tomcat_port.sh 7300;
執(zhí)行重啟nginx:
service nginx restart

5,再去check下磁盤空間
[root@localhost local]# df -h
文件系統(tǒng)              容量  已用 可用 已用% 掛載點(diǎn)
/dev/mapper/VolGroup00-LogVol00
                      113G   18G   90G  17% /
/dev/sda1              99M   13M   82M  14% /boot
tmpfs                 8.8G     0  8.8G   0% /dev/shm
[root@localhost local]# 

看到df -h命令正常了,已經(jīng)釋放了90G的磁盤空間,現(xiàn)在磁盤使用率才17%,nagios報(bào)警解除了。


6,匯總一些原理分析
實(shí)現(xiàn)原理:
du -s命令通過將指定文件系統(tǒng)中所有的目錄、符號(hào)鏈接和文件使用的塊數(shù)累加得到該文件系統(tǒng)使用的總塊數(shù);
df命令通過查看文件系統(tǒng)磁盤塊分配圖得出總塊數(shù)與剩余塊數(shù)。
du是用戶級(jí)程序,不考慮Meta Data(系統(tǒng)為自身分配的一些磁盤塊)

ps:應(yīng)用程序打開的文件句柄沒有關(guān)閉的話,會(huì)造成df命令顯示的剩余磁盤空間少。而du則不會(huì)。
例子:
#include <unistd.h>   
#include <stdlib.h>   
#include <stdio.h>   
#include <fcntl.h>   
  
int main(int argc,char **argv)  
{  
    if(open("tempfile",O_RDWR) < 0){  
        fprintf(stderr,"open error");  
        exit(-1);  
    }  
  
    if(unlink("tempfile") < 0){  
        fprintf(stderr,"unlink error");  
        exit(-1);  
    }  
  
    printf("file unlinked\n");  
    sleep(15);  
    printf("done\n");  
    exit(0);  
}
本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
Linux磁盤管理
另類限定磁盤配額
通過實(shí)操掌握 Linux DF 磁盤信息命令
Linux 磁盤管理 | 菜鳥教程
df
NMON 生成文件 字段釋義
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服