赞
踩
本文主要介绍当Linux出现磁盘占满时,如何分析是哪些文件引起;
命令: df -h
运行结果:
root@host:~$ df -h
Filesystem Size Used Avail Use% Mounted on
udev 16G 0 16G 0% /dev
tmpfs 3.2G 331M 2.9G 11% /run
/dev/sda2 189G 187G 0 100% /
tmpfs 16G 4.6G 12G 30% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/sda1 511M 3.4M 508M 1% /boot/efi
tmpfs 3.2G 0 3.2G 0% /run/user/1000
关注 / 目录下的使用情况
命令:du -h -d 1 / | sort -hr
运行结果:
root@host:/home# du -h -d 1 / | sort -hr 1.3T /home 1.3T / 13G /var 6.3G /usr 3.8G /dev 3.1G /tmp 742M /etc 348M /opt 331M /run 211M /lib 42M /boot 15M /bin 13M /sbin 2.7M /root 36K /lib64 28K /lib32 16K /lost+found 4.0K /srv 4.0K /snap 4.0K /mnt 4.0K /media 4.0K /iso4install 0 /sys 0 /proc
关注排在前面的目录,进行下一步排查
查找/目录下大于1000M的文件
命令: ll -h `find / -type f -size +1000M`
运行结果:
root@host:/home# ll -h `find / -type f -size +1000M`
find: ‘/proc/5401/task/5401/fdinfo/5’: No such file or directory
find: ‘/proc/5401/fdinfo/6’: No such file or directory
find: ‘/proc/7337’: No such file or directory
find: ‘/proc/7531’: No such file or directory
-r-------- 1 root root 128T Aug 3 03:52 /proc/kcore
-rw-r--r-- 1 root root 1.4G Aug 3 03:52 /tmp/lidar_rim_left.log
-rw-r--r-- 1 root root 1.4G Aug 3 03:52 /tmp/lidar_rim_right.log
-rw-r----- 1 syslog adm 5.8G Aug 3 03:52 /var/log/syslog
-rw-r----- 1 root root 5.8G Aug 3 02:57 /var/log/syslog.bak
重点关注大文件,以及大文件的来源
查找根目录(除了/home/autotest/testdata_stability外)中大于1000M的大文件
命令: ll -h `find / -path “/home/autotest/testdata_stability” -prune -o -type f -size +1000M -print`
运行结果
root@host:/home# ll -h `find / -path "/home/autotest/testdata_stability" -prune -o -type f -size +1000M -print`
find: ‘/proc/24244’: No such file or directory
find: ‘/proc/24548/task/24548/fdinfo/5’: No such file or directory
find: ‘/proc/24548/fdinfo/6’: No such file or directory
find: ‘/proc/24552’: No such file or directory
-r-------- 1 root root 128T Aug 3 04:07 /proc/kcore
-rw-r--r-- 1 root root 1.4G Aug 3 04:07 /tmp/lidar_rim_left.log
-rw-r--r-- 1 root root 1.4G Aug 3 04:07 /tmp/lidar_rim_right.log
-rw-r----- 1 syslog adm 5.8G Aug 3 04:07 /var/log/syslog
-rw-r----- 1 root root 5.8G Aug 3 02:57 /var/log/syslog.bak
查看inode占用情况
命令:df -ih
root@host:/home# df -ih
Filesystem Inodes IUsed IFree IUse% Mounted on
udev 4.0M 435 4.0M 1% /dev
tmpfs 4.0M 779 4.0M 1% /run
/dev/sda2 12M 166K 12M 2% /
tmpfs 4.0M 115 4.0M 1% /dev/shm
tmpfs 4.0M 3 4.0M 1% /run/lock
tmpfs 4.0M 14 4.0M 1% /sys/fs/cgroup
/dev/sda1 0 0 0 - /boot/efi
10.151.239.22:/dataserver1/stability 233M 14K 233M 1% /home/autotest/testdata_stability
tmpfs 4.0M 4 4.0M 1% /run/user/1000
如果inode占用过高,说明存在大量的碎片文件(临时文件,一般在tmp下),将之删除即可;
查看已删除文件被占用情况
命令 lsof | grep deleted
root@ubuntu:/home/yms# lsof | grep deleted
COMMAND PID TID USER FD TYPE DEVICE SIZE/OFF NODE NAME
smbd 1949 root 2w REG 252,0 154 4064119 /var/log/samba/log.smbd.1 (deleted)
smbd 1949 root 9w REG 252,0 154 4064119 /var/log/samba/log.smbd.1 (deleted)
释放被占用文件,杀掉相关进程即可:kill -9 pid
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。