天天看點

“no space left on device”(磁盤空間不足)問題解決

關于“no space left on device”(磁盤空間不足)問題

1.首先介紹兩個指令

df -h檢視磁盤使用情況

df -i 檢視inode使用情況

2.block滿了

通常解決方法是删除大檔案,不要直接删除,先确認資料是否重要,否則就掉坑裡了。

[[email protected] ~]# cd /app/logs/

[[email protected] logs]# ls -lh /bin/ls

-rwxr-xr-x. 1 root root 107K Mar 23 02:52 /bin/ls

[[email protected] logs]# df -h

Filesystem    Size  Used Avail Use% Mounted on

/dev/sdc        73K  14K  55K  21% /app/logs

[[email protected] logs]# cp /bin/ls .

cp: writing `./ls': No space left on device

[[email protected] logs]# df -h

Filesystem    Size  Used Avail Use% Mounted on

/dev/sdc        73K  70K    0 100% /app/logs

[[email protected] logs]#

3.inode用光了

出現這種情況,是小檔案占用較多的inode,建立檔案或目錄占用一個inode,通常這些小檔案是定時任務引起的,删除需慎重。

 [[email protected]]# df -h  

Filesystem    Size  Used Avail Use% Mounted on

/dev/sdc        73K  14K  55K  21% /app/logs

[[email protected] logs]# df -i

Filesystem    Inodes IUsed  IFree IUse% Mountedon

/dev/sdc          16    11      5  69% /app/logs

[[email protected] logs]# touch a{1..6}txt

touch: cannot touch `a6txt': No space left ondevice

[[email protected] logs]# df -h

Filesystem    Size  Used Avail Use% Mounted on

/dev/sdc        73K  14K  55K  21% /app/logs

[[email protected] logs]# df -i

Filesystem    Inodes IUsed  IFree IUse% Mountedon

/dev/sdc          16    16      0  100% /app/logs

[[email protected] logs]#

-------------------------

1.問題描述

no space left on device(磁盤空間不足)

2.檔案删除原理

(1)硬連結數為0(所有硬連結均被删除)

(2)程序調用數為0(沒有程序在排程檔案)

3.原因分析

硬連結數為0,程序排程數不為0

4.過程示範

(1)建立大檔案

[[email protected] ~]# seq 500000000 > /var/log/messages 

(2)檢視磁盤使用情況

[[email protected] ~]# df -h

Filesystem    Size  Used Avail Use% Mounted on

/dev/sda3      19G  6.1G  12G  35% /

(3)删除日志檔案/var/log/messages

[[email protected] ~]# rm -rf /var/log/messages 

(4)檢視空間是否被釋放

[[email protected] ~]# df -h

Filesystem    Size  Used Avail Use% Mounted on

/dev/sda3      19G  6.1G  12G  35% /

(5)檢視檔案還被哪些程序調用

[[email protected] ~]# lsof | grep delete

rsyslogd 2839      root    1w    REG                8,3 4888888898    393106 /var/log/messages (deleted)

(6)重新開機對應的服務

[[email protected] ~]# /etc/init.d/rsyslog restart

Shutting down system logger:                        [  OK  ]

Starting system logger:                                    [  OK  ]

(7)檢查磁盤使用情況

[[email protected] ~]# df -h

Filesystem    Size  Used Avail Use% Mounted on

/dev/sda3        19G 1.5G  17G  9% /

本文永久更新連結位址:http://www.linuxidc.com/Linux/2017-09/146689.htm

繼續閱讀