阻止损坏的 NFS 挂载锁定目录?

阻止损坏的 NFS 挂载锁定目录?

我有一个有点有趣的设置:在一个文件夹中安装有多个远程 NFS 服务器的服务器,然后通过 Samba 重新导出该文件夹。将其视为共享代理,将所有共享文件夹保存在一个位置。

但我的问题是,每当其中一个挂载发生故障(服务器重新启动、服务重新启动、服务器导出的外部硬盘驱动器被删除等)时,任何读取挂载的尝试都会永久阻止。这也意味着ls在该目录中运行会冻结,通过 Samba 连接的用户也会冻结。这也导致我的 cron 作业多次被阻止,几乎使服务器崩溃,因为它有数百个被阻止的进程。这变得非常烦人,因为我通常必须打开一个不等待ls完成的终端(无法取消它),运行for i in *; do sudo umount -l -f $i; done;,希望它能工作,解决问题,然后重新安装所有内容。

有没有一种方法可以挂载 NFS 共享,并规定如果连接因任何原因失败(最好有重试期),则挂载会自行卸载或至少不会阻塞?

答案1

通常,在安装 NFS 时,最好设置与此类似的标志:

bg,intr,soft
   bg      If  the  first  NFS  mount  attempt times out, retry the mount in the 
           background.  After a mount operation is backgrounded, all subsequent mounts
           on the same NFS  server  will  be  backgrounded immediately, without first
           attempting the mount.  A missing mount point is treated as a timeout, to
           allow for nested NFS mounts.
   soft    If  an  NFS  file operation has a major timeout then report an I/O error
           to the calling program.  The default is to continue retrying NFS file
           operations indefinitely.
   intr    If  an  NFS  file  operation  has  a major timeout and it is hard mounted,
           then allow signals to interupt the file operation and cause it to return
           EINTR to the calling program.  The default is to not allow file operations
           to be interrupted.

您还可以设置:

timeo=5,retrans=5,actimeo=10,retry=5

如果 NFS 服务器断开连接而不是等待重试,这应该允许 NFS 挂载超时并使目录无法访问。

看一眼这个链接有关 NFS 挂载选项的更多信息

相关内容