在含有nfs服务的服务器执行df卡住后的处理办法
简介
当使用 nfs 文件系统时,如果 nfs 服务端出现故障会导致无法通过 df 查看当前磁盘挂载情况。
nfs可以修复
如果挂载了多个 nfs 磁盘,此时需要诊断哪个 nfs 服务出现故障了。此时可以通过 strace 检查 df 程序卡在哪个 API 调用上了。
1 2 3 4 5 6 7 8 9 10 11 | $ strace df -h execve("/bin/df", ["df", "-h"], [/* 27 vars */]) = 0 brk(NULL) = 0x145c000 access("/etc/ld.so.nohwcap", F_OK) = -1 ENOENT (No such file or directory) access("/etc/ld.so.preload", R_OK) = -1 ENOENT (No such file or directory) open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3 ... ... stat("/proc/sys/fs/binfmt_misc", {st_mode=S_IFDIR|0755, st_size=0, ...}) = 0 stat("/pacs1", ^C |
当前例子是卡在了 /pacs1 目录,使用 ctrl+c 结束 strace 命令,调用 mount 检查 /pacs1 挂载的目录信息
1 2 | $ mount | grep pacs1 172.16.100.112:/sync/trans/192.168.10.23/pacs on /pacs1 type nfs4 (rw,relatime,vers=4.0,rsize=1048576,wsize=1048576,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.10.23,local_lock=none,addr=172.16.100.112) |
找到 nfs 对端的远程服务地址即可修改该服务,登录 nfs 服务主机重启 nfs 服务,最终修复故障。
1 2 3 4 5 6 7 8 | $ /etc/init.d/nfs-kernel-server status ● nfs-server.service - NFS server and services Loaded: loaded (/lib/systemd/system/nfs-server.service; enabled; vendor preset: enabled) Active: active (exited) since Thu 2022-06-30 23:10:33 CST; 9 months 27 days ago $ /etc/init.d/nfs-kernel-server restart [ ok ] Restarting nfs-kernel-server (via systemctl): nfs-kernel-server.service. |
nfs不能修复
另一种场景是 nfs 服务无法修复,比如存储故障导致的 nfs 服务一段时间暂时无法访问。此时可以暂时 umount 掉出现故障的 nfs 服务,等 nfs 服务恢复后再重新挂载。正常使用 umount 无法卸载出现故障的 nfs 目录,因为目录正在使用,只有程序从该目录退出后才能 umount。此时可以使用 umount 的 lazy 选项,可以暂时不用考虑程序占用目录的情况。命令为:
1 | $ umount -l /pacs1 |
在无法 umount 时可以尝试 -l -f 等选项,最差的情况是使用 lsof 检查进程占用情况,杀掉进程再执行 umount。umount 的额外选项说明如下:
1 2 3 4 5 6 7 8 9 10 | $ man umount -l, --lazy Lazy unmount. Detach the filesystem from the file hierarchy now, and clean up all references to this filesystem as soon as it is not busy anymore. (Requires kernel 2.4.11 or later.) -f, --force Force an unmount (in case of an unreachable NFS system). (Requires kernel 2.1.116 or later.) |