AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 617610
Accepted
mahmood
mahmood
Asked: 2014-08-04 10:16:18 +0800 CST2014-08-04 10:16:18 +0800 CST 2014-08-04 10:16:18 +0800 CST

重新启动后出现“过时的 NFS 文件句柄”

  • 772

在服务器节点上,可以访问导出的文件夹。但是,在重新启动(服务器和客户端)后,不再可以从客户端访问该文件夹。

在服务器上

# ls /data
Folder1
Forlder2

并且 /etc/exports 文件包含

/data 192.168.1.0/24(rw,no_subtree_check,async,no_root_squash)

在客户端

# ls /data
ls: cannot access /data: Stale NFS file handle

我不得不说客户端的共享文件夹没有问题,但是在重新启动(服务器和客户端)后,我看到了这条消息。

有什么办法可以解决吗?

nfs
  • 4 4 个回答
  • 102640 Views

4 个回答

  • Voted
  1. Best Answer
    BillThor
    2014-08-04T14:43:02+08:002014-08-04T14:43:02+08:00

    重新启动的顺序很重要。在客户端之后重新启动服务器可能会导致这种情况。陈旧的 NFS 句柄表示客户端打开了文件,但服务器不再识别文件句柄。在某些情况下,NFS 会在超时后清理其数据结构。在其他情况下,您需要自己清理 NFS 数据结构,然后重新启动 NFS。这些结构所在的位置在某种程度上取决于 O/S。

    尝试先在服务器上重新启动 NFS,然后在客户端上重新启动。这可能会清除文件句柄。

    不建议使用从其他服务器打开的文件重新启动 NFS 服务器。如果在服务器上删除了打开的文件,这尤其成问题。服务器可能会保持文件打开,直到重新启动,但重新启动将删除服务器端的内存中文件句柄。然后客户端将无法再打开该文件。

    从服务器确定使用了哪些挂载是困难且不可靠的。该showmount -a选项可能会显示一些活动的坐骑,但可能不会报告所有这些坐骑。锁定的文件更容易识别,但需要启用锁定并依赖客户端软件锁定文件。

    您可以lsof在客户端上使用来识别在挂载上打开文件的进程。

    我在我的 NFS 挂载上使用hard和intr挂载选项。该hard选项会导致 IO 无限期重试。该intr选项允许进程在等待 NFS IO 完成时被终止。

    • 27
  2. Birgit Ducarroz
    2015-07-30T00:00:35+08:002015-07-30T00:00:35+08:00

    试试我写的这个脚本:

    #!/bin/bash
    # Purpose:
    # Detect Stale File handle and remove it
    # Script created: July 29, 2015 by Birgit Ducarroz
    # Last modification: --
    #
    
    # Detect Stale file handle and write output into a variable and then into a file
    mounts=`df 2>&1 | grep 'Stale file handle' |awk '{print ""$2"" }' > NFS_stales.txt`
    # Remove : ‘ and ’ characters from the output
    sed -r -i 's/://' NFS_stales.txt && sed -r -i 's/‘//' NFS_stales.txt && sed -r -i 's/’//' NFS_stales.txt
    
    # Not used: replace space by a new line
    # stales=`cat NFS_stales.txt && sed -r -i ':a;N;$!ba;s/ /\n /g' NFS_stales.txt`
    
    # read NFS_stales.txt output file line by line then unmount stale by stale.
    #    IFS='' (or IFS=) prevents leading/trailing whitespace from being trimmed.
    #    -r prevents backslash escapes from being interpreted.
    #    || [[ -n $line ]] prevents the last line from being ignored if it doesn't end with a \n (since read returns a non-zero exit code when it encounters EOF).
    
    while IFS='' read -r line || [[ -n "$line" ]]; do
        echo "Unmounting due to NFS Stale file handle: $line"
        umount -fl $line
    done < "NFS_stales.txt"
    #EOF
    

    同时,上述脚本不适用于所有服务器。这是一个更新:

    #!/bin/bash
    # Purpose:
    # Detect Stale File handle and remove it
    # Script created: July 29, 2015 by Birgit Ducarroz
    # Last modification: 23.12.2020  /bdu
    #
    
    MYMAIL="[email protected]"
    THIS_HOST=`hostname`
    
    # Detect Stale file handle and write output into a variable and then into a file
    mounts=`df 2>&1 | grep 'Stale' |awk '{print ""$2"" }' > NFS_stales.txt`
    sleep 8
    
    # Remove : special characters from the output
    
    sed -r -i 's/://' NFS_stales.txt && sed -r -i 's/‘//' NFS_stales.txt && sed -r -i 's/’//' NFS_stales.txt && sed -r -i 's/`//' NFS_stales.txt  && sed -r -i "s/'//" NFS_stales.txt 
    
    
    # Not used: replace space by a new line
    # stales=`cat NFS_stales.txt && sed -r -i ':a;N;$!ba;s/ /\n /g' NFS_stales.txt`
    
    # read NFS_stales.txt output file line by line then unmount stale by stale.
    #    IFS='' (or IFS=) prevents leading/trailing whitespace from being trimmed.
    #    -r prevents backslash escapes from being interpreted.
    #    || [[ -n $line ]] prevents the last line from being ignored if it doesn't end with a \n (since read returns a non-zero exit code when it encounters EOF).
    
    while IFS='' read -r line || [[ -n "$line" ]]; do
        message=`echo "Unmounting due to NFS Stale file handle: $line"`
        echo echo | mail -s "$THIS_HOST: NFS Stale Handle unmounted" $MYMAIL <<< $message
        umount -f -l $line
    done < "NFS_stales.txt"
    mount -a
    
    #EOF
    
    • 5
  3. Chin
    2018-03-17T13:26:35+08:002018-03-17T13:26:35+08:00

    在 NFS 服务器上 UN-export 并重新导出文件系统:

    exportfs -u nfs-server:/file_system exportfs nfs-server:/file_system

    在客户端挂载文件系统

    mount -t nfs nfs-server:/文件系统 /mount_point

    • 2
  4. sridhar gattu
    2019-02-19T08:53:49+08:002019-02-19T08:53:49+08:00

    检查特定路径的 lsof 并杀死相应的 pid 。然后卸载分区并重新安装。

    • 0

相关问题

  • 在 NFS 文件服务器上获取不规则时间戳

  • 过时的 NFS 句柄

  • sh 脚本:如果未安装远程文件系统,如何安装它?

  • 分析 Linux NFS 服务器性能

  • NFS 缓存导致间歇性滞后

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve