如何在 CentOS/RHEL 中使用“autofs”挂载 NFS 文件系统

这篇文章解释了如何配置“autofs”以便使用“autofs”服务挂载 NFS 文件系统。

  1. 停止'autofs'服务,检查该服务是否正在运行,然后继续停止它。
# service autofs status
automount (pid 25285) is running...
# service autofs stop
Stopping automount: [ OK ]
# service autofs status
automount is stopped
  1. 编辑/etc/auto.master文件设置文件映射:

文件/etc/auto.master是autofs服务的主要配置文件,这个文件包含了autofs控制的系统上挂载点的主映射列表,以及它们对应的配置文件或者已知的网络资源作为“自动挂载地图”。

文件应该是这样的:

# Sample auto.master file
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# For details of the format look at autofs(5).
#
/misc /etc/auto.misc     ---------------------> MAP FILE
#
# 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 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

“映射文件”可以更改为 /etc 下名为“auto.mount”的任何其他文件,以便将导出安装到任何其他所需目录。
有关更多信息,请继续执行第二步。

编辑“auto.master”文件并在“/misc /etc/auto.misc”行前面添加哈希符号,然后继续在文件末尾添加以下行:

/- /etc/auto.mount

更改后,该文件应类似于以下示例:

#
# /misc /etc/auto.misc
#
/- /etc/auto.mount
  1. 创建或者编辑映射文件:

以下是'/etc/auto.misc'文件和新文件'auto.mount'的示例

# This is an automounter map and it has the following format
# key(mount-point) [ -mount-options-separated-by-comma ] location   ===> THIS IS THE GENERAL FORMAT OF THE MAPS
# Details may be found in the autofs(5) manpage
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom  ===> EXAMPLE
# the following entries are samples to pique your imagination
#linux -ro,soft,intr ftp.example.org:/pub/linux
#boot -fstype=ext2 :/dev/hda1
#floppy -fstype=auto :/dev/fd0
#floppy -fstype=ext2 :/dev/fd0
#e2floppy -fstype=ext2 :/dev/fd0
#jaz -fstype=ext2 :/dev/sdc1
#removable -fstype=ext2 :/dev/hdd
mount_point_name      -rw,soft,intr,rsize=8192,wsize=8192       NFS.example.net:/export_name  ===> IP address can be used instead of the FQDN

如果我们不想使用 /misc 目录或者 'auto.misc' 文件,请创建一个名为 'auto.mount' 的新文件,并使用相应的语法添加相同的参数,如下例所示:

# vi /etc/auto.mount

添加以下行:

/mount_point -fstype=nfs,rw NFS.example.net:/export_name

注意:确保我们已编辑“/etc/auto.master”文件并将映射文件更改为所需的文件。

  1. 启动“autofs”服务:
# service autofs start
Starting automount: [ OK ]
  1. 运行 'mount' 命令以检查 NFS 共享现在是否已安装:
# mount
NFS_IP_Address:/export on /mount_point  type nfs (rw,vers=4,addr=NFS_IP_Address,clientaddr=local_IP_Address)
日期:2020-09-17 00:13:44 来源:oir作者:oir