今天遇到一个很奇怪的问题,在一台linux执行df -h查看磁盘使用情况,发现卡成狗,于是着手去解决:


1、通过strace df -h追踪是卡在什么位置

[root@new_web ~]# strace df -h
execve("/bin/df", ["df", "-h"], [/* 22 vars */]) = 0
brk(0)                                  = 0x2307000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd1715f4000
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY)      = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=37353, ...}) = 0
mmap(NULL, 37353, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd1715ea000
close(3)                                = 0
open("/lib64/libc.so.6", O_RDONLY)      = 3
read(3, "\177ELF\2\1\1\3\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0p\356\1\344=\0\0\0"..., 832) = 832
fstat(3, {st_mode=S_IFREG|0755, st_size=1926520, ...}) = 0
mmap(0x3de4000000, 3750152, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_DENYWRITE, 3, 0) = 0x3de4000000
mprotect(0x3de418a000, 2097152, PROT_NONE) = 0
mmap(0x3de438a000, 20480, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_DENYWRITE, 3, 0x18a000) = 0x3de438a000
mmap(0x3de438f000, 18696, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x3de438f000
close(3)                                = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd1715e9000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd1715e8000
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd1715e7000
arch_prctl(ARCH_SET_FS, 0x7fd1715e8700) = 0
mprotect(0x3de438a000, 16384, PROT_READ) = 0
mprotect(0x3de3a1f000, 4096, PROT_READ) = 0
munmap(0x7fd1715ea000, 37353)           = 0
brk(0)                                  = 0x2307000
brk(0x2328000)                          = 0x2328000
open("/usr/lib/locale/locale-archive", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=99158576, ...}) = 0
mmap(NULL, 99158576, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd16b756000
close(3)                                = 0
open("/etc/mtab", O_RDONLY)             = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=366, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd1715f3000
read(3, "/dev/vda1 / ext4 rw,barrier=0 0 "..., 4096) = 366
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x7fd1715f3000, 4096)            = 0
statfs("/", {f_type="EXT2_SUPER_MAGIC", f_bsize=4096, f_blocks=10320720, f_bfree=8614131, f_bavail=8089869, f_files=2621440, f_ffree=2405901, f_fsid={-102338008, -1862172196}, f_namelen=255, f_frsize=4096}) = 0
open("/usr/share/locale/locale.alias", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=2512, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd1715f3000
read(3, "# Locale name alias data base.\n#"..., 4096) = 2512
read(3, "", 4096)                       = 0
close(3)                                = 0
munmap(0x7fd1715f3000, 4096)            = 0
open("/usr/share/locale/en_US.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en_US/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.UTF-8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en.utf8/LC_MESSAGES/coreutils.mo", O_RDONLY) = -1 ENOENT (No such file or directory)
open("/usr/share/locale/en/LC_MESSAGES/coreutils.mo", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=435, ...}) = 0
mmap(NULL, 435, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7fd1715f3000
close(3)                                = 0
statfs("/sys", {f_type="SYSFS_MAGIC", f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
statfs("/dev/pts", {f_type="DEVPTS_SUPER_MAGIC", f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
statfs("/dev/shm", {f_type=0x1021994, f_bsize=4096, f_blocks=2041596, f_bfree=2041596, f_bavail=2041596, f_files=2041596, f_ffree=2041595, f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
statfs("/proc/sys/fs/binfmt_misc", {f_type=0x42494e4d, f_bsize=4096, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={0, 0}, f_namelen=255, f_frsize=4096}) = 0
statfs("/data", {f_type="EXT2_SUPER_MAGIC", f_bsize=4096, f_blocks=129015406, f_bfree=46849538, f_bavail=40295938, f_files=32768000, f_ffree=32749794, f_fsid={346710647, -22441262}, f_namelen=255, f_frsize=4096}) = 0

### 卡在此处
statfs("/opt", {f_type=0xff534d42, f_bsize=0, f_blocks=0, f_bfree=0, f_bavail=0, f_files=0, f_ffree=0, f_fsid={0, 0}, f_namelen=4096, f_frsize=0}) = 0
### 卡在此处

statfs("/data1", {f_type="EXT2_SUPER_MAGIC", f_bsize=4096, f_blocks=129015406, f_bfree=128955560, f_bavail=122401960, f_files=32768000, f_ffree=32767852, f_fsid={1328044912, -550095550}, f_namelen=255, f_frsize=4096}) = 0
statfs("/data2", {f_type="EXT2_SUPER_MAGIC", f_bsize=4096, f_blocks=129015406, f_bfree=128964770, f_bavail=122411170, f_files=32768000, f_ffree=32767982, f_fsid={-1295730252, -1655731663}, f_namelen=255, f_frsize=4096}) = 0
open("/usr/lib64/gconv/gconv-modules.cache", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=26060, ...}) = 0
mmap(NULL, 26060, PROT_READ, MAP_SHARED, 3, 0) = 0x7fd1715ec000
close(3)                                = 0
fstat(1, {st_mode=S_IFCHR|0620, st_rdev=makedev(136, 2), ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fd1715eb000
write(1, "Filesystem      Size  Used Avail"..., 49Filesystem      Size  Used Avail Use% Mounted on
) = 49
write(1, "/dev/vda1        40G  6.6G   31G"..., 40/dev/vda1        40G  6.6G   31G  18% /
) = 40
write(1, "tmpfs           7.8G     0  7.8G"..., 47tmpfs           7.8G     0  7.8G   0% /dev/shm
) = 47
write(1, "/dev/vdb        493G  314G  154G"..., 44/dev/vdb        493G  314G  154G  68% /data
) = 44
write(1, "/dev/vdc        493G  234M  467G"..., 45/dev/vdc        493G  234M  467G   1% /data1
) = 45
write(1, "/dev/vdd        493G  198M  467G"..., 45/dev/vdd        493G  198M  467G   1% /data2
) = 45
close(1)                                = 0
munmap(0x7fd1715eb000, 4096)            = 0
close(2)                                = 0
exit_group(0)                           = ?

观察的时候发现追踪到/opt的时候卡住了


但是df -h的结果来看,确实没有/opt的挂载信息,于是进入/opt,发现也是奇卡无比


于是使用 mount |column -t 查看所有的挂载信息

[root@new_web /]# mount | column -t
/dev/vda1                  on  /                         type  ext4         (rw,barrier=0)
proc                       on  /proc                     type  proc         (rw)
sysfs                      on  /sys                      type  sysfs        (rw)
devpts                     on  /dev/pts                  type  devpts       (rw,gid=5,mode=620)
tmpfs                      on  /dev/shm                  type  tmpfs        (rw)
none                       on  /proc/sys/fs/binfmt_misc  type  binfmt_misc  (rw)
/dev/vdb                   on  /data                     type  ext4         (rw)
//192.168.2.6/replication  on  /opt                      type  cifs         (rw,username=dba,password=0987654)
/dev/vdc                   on  /data1                    type  ext4         (rw)
/dev/vdd                   on  /data2                    type  ext4         (rw)

发现/opt挂载了远程nfs系统,卸载/opt

umount /opt

再次执行df -h 发现秒开!!


问题原因:

此处的NFS系统已经不使用了(挂了),但是它的挂载信息还在,导致文件系统一直在查找,所以就一直卡在那里