当使用 nfs 文件系统时,如果 nfs 服务端出现故障会导致无法通过 df 查看当前磁盘挂载情况。
如果挂载了多个 nfs 磁盘,此时需要诊断哪个 nfs 服务出现故障了。此时可以通过 strace 检查 df 程序卡在哪个 API 调用上了。
$ strace df -hexecve("/bin/df", ["df", "-h"], [/* 27 vars */]) = 0brk(NULL) = 0x145c000access("/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, ...}) = 0stat("/pacs1", ^C
当前例子是卡在了 pacs1 目录,使用 ctrl+c 结束 strace 命令,调用 mount 检查 pacs1 挂载的目录信息
$ mount | grep pacs1172.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 服务,最终修复故障。
$ /etc/init.d/nfs-kernel-server status● nfs-server.service - NFS server and servicesLoaded: 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 服务一段时间暂时无法访问。此时可以暂时 umount 掉出现故障的 nfs 服务,等 nfs 服务恢复后再重新挂载。正常使用 umount 无法卸载出现故障的 nfs 目录,因为目录正在使用,只有程序从该目录退出后才能 umount。此时可以使用 umount 的 lazy 选项,可以暂时不用考虑程序占用目录的情况。命令为:
$ umount -l /pacs1
在无法 umount 时可以尝试 -l -f 等选项,最差的情况是使用 lsof 检查进程占用情况,杀掉进程再执行 umount。umount 的额外选项说明如下:
$ man umount-l, --lazyLazy unmount. Detach the filesystem from the file hierarchynow, and clean up all references to this filesystem as soon asit is not busy anymore. (Requires kernel 2.4.11 or later.)-f, --forceForce an unmount (in case of an unreachable NFS system).(Requires kernel 2.1.116 or later.)
全文完。
如果转发本文,文末务必注明:“转自微信公众号:生有可恋”。
文章转载自生有可恋,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




