通过 autonfs 自动挂载 NFS

通过 autonfs 自动挂载 NFS

上周我一直在努力将 (asustor) nas 添加到我的网络,最后终于到了可以通过 ubuntu 中的 nfs 和运行 rune-audio 的 raspberry-pi 挂载文件夹的地步。

我将它们安装在 root/nfs/“文件夹”中,并将其添加到 nautilus 侧边栏。现在我想在启动时自动安装它们,并已阅读:
https://help.ubuntu.com/community/Autofs和,
如何设置 Automount/Autofs

我已经安装了 autofs。

但是当我手动将其安装到 auto.master 规则时,我似乎不明白如何在终端中转换分配:

使用的手动挂载规则:sudo mount 192.168.0.200:/volume1/Public /nfs/Public

如果能对此“转换”提供帮助,我将不胜感激。

也就是说,我认为将该规则添加到标准 auto.master 中就足够了,还是我应该使用间接规则?合并 auto.nfs?

非常感谢您的帮助。

添加:

在steeldriver的帮助下,我确实挂载了该文件夹。
但我忘了提一下,除了上面提到的规则:
sudo mount 192.168.0.200:/volume1/Public /nfs/Public。

我还需要安装:

sudo mount 192.168.0.200:/share/USB1 /nfs/Music。

我以为这会类似于实现,但是当它尝试以下内容时:
* -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp 192.168.0.200:/volume1/Public*
-fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp 192.168.0.200:/share/USB1

但这只给了我一个包含公共内容的音乐文件夹,而不是 USB1 内容。我在这里做错了什么?

答案1

要挂载 NFS 共享,我们需要安装 nfs-common:

sudo apt-get install nfs-common

为了避免每次重启后都重新输入这些内容,我们将以下行添加到 /etc/fstab:

<nfs-server-IP>:/   /mnt   nfs    auto  0  0

如果挂载后,/proc/mounts 中的条目显示为 ://(带有两个斜杠),那么您可能需要在 /etc/fstab 中指定两个斜杠,否则 umount 可能会抱怨它找不到挂载。

自动选项在启动时安装。然而,如果你的客户端使用 wifi 连接,这将不起作用在用户级别进行管理(登录后),因为网络在启动时不可用。在 Ubuntu 12.04 LTS 及更高版本中,wifi 连接默认在系统级别进行管理,因此在启动时自动挂载 NFS 共享应该可以正常工作

来源:https://help.ubuntu.com/community/SettingUpNFSHowTo

使用 WIFI 时最好使用 Autofs:

我们首先安装 AutoFS:

sudo apt install autofs

我们编辑/etc/auto.master:

sudo nano /etc/auto.master

内容:

#
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
#/misc  /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
#       "nosuid" and "nodev" options unless the "suid" and "dev"
#       options are explicitly given.
#
#/net   -hosts
#
# Include /etc/auto.master.d/*.autofs
# The included files must conform to the format of this file.
#
#+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
#
#+auto.master

/media/nfs /etc/auto.nfs --ghost

注释掉(#)“+auto.master”和“+dir:/etc/auto.master.d”并在底部添加这些行。我花了 2 个小时尝试让它工作,但不知何故,如果不添加 --ghost 选项,它就无法工作。如果有人知道原因,请发表评论。现在 /media/nfs 是包含您的 NFS 共享的目录(您不必创建它,autofs 会为您创建它),而 /etc/auto.nfs 是您的共享的配置文件。我们现在就创建它:

sudo nano /etc/auto.nfs

插入股份:

Backup      10.0.1.100:/Backup
Multimedia  10.0.1.100:/Multimedia

现在备份目录10.0.1.100:/备份将纳入 /media/nfs。

重新启动 autofs:

sudo systemctl restart autofs

就这样吧,享受您的分享吧。

答案2

我已经有一段时间没有这样做了,但我记得通常的配置是auto.master只包含安装位置和特定于协议的名称地图文件例如

/etc/auto.master

# configure nfs automount (for ad-hoc connection to local NAS) 
/nfs   /etc/auto.nfs

地图文件/etc/auto.nfs类似如下:

# configure nfs automount (for ad hoc connection to local NAS)
* -fstype=nfs,soft,intr,rsize=8192,wsize=8192,nosuid,tcp 192.168.0.200:/Volume1/Public

如果你使用的是 Ubuntu 16.04 或更高版本,systemd重新加载autofs地图的方法似乎是

sudo systemctl reload autofs.service

或者(如果这还不够的话)

sudo systemctl restart autofs.service

此后,NAS 卷应按需安装,例如

ls /nfs/Public

请注意,如果 NAS 和本地系统上的数字 UID 不一样,则可能需要在系统之间设置用户映射。

相关内容