0

我有一个全新安装的 Centos 7。我似乎无法192.168.254.105:/srv/nfsshare从 Centos 客户端自动挂载 NFS 共享。

但是,手动安装共享可以完美运行。

/etc/auto.master已被完全注释掉以简化问题,保留以下行:

/-       /etc/auto.nfsshare 

/etc/auto.nfsshare 包含以下行:

/tests/nfsshare       -fstype=nfs,credentials=/etc/credentials.txt    192.168.254.105:/srv/nfsshare

/etc/credentials.txt包含:

 user=user
 password=password

预期的行为是,当 I 时ls -l /tests/nfsshare,我将看到我的文件服务器的/srv/nfsshare目录保存的一些文件。

它不是。相反,它什么也没显示。

sudo journalctl --unit=autofs.service的日志在启动时显示(启用调试):

 Nov 20 00:25:38 localhost.localdomain systemd[1]: Starting Automounts filesystems on demand...
 Nov 20 00:25:38 localhost.localdomain automount[21204]: Starting automounter version 5.0.7-48.el7, master map auto.master
 Nov 20 00:25:38 localhost.localdomain automount[21204]: using kernel protocol version 5.02
 Nov 20 00:25:38 localhost.localdomain automount[21204]: lookup_nss_read_master: reading master files auto.master
 Nov 20 00:25:38 localhost.localdomain automount[21204]: parse_init: parse(sun): init gathered global options: (null)
 Nov 20 00:25:38 localhost.localdomain automount[21204]: spawn_mount: mtab link detected, passing -n to mount
 Nov 20 00:25:38 localhost.localdomain automount[21204]: spawn_umount: mtab link detected, passing -n to mount
 Nov 20 00:25:38 localhost.localdomain automount[21204]: lookup_read_master: lookup(file): read entry /-
 Nov 20 00:25:38 localhost.localdomain automount[21204]: master_do_mount: mounting /-
 Nov 20 00:25:38 localhost.localdomain automount[21204]: automount_path_to_fifo: fifo name /run/autofs.fifo--
 Nov 20 00:25:38 localhost.localdomain automount[21204]: lookup_nss_read_map: reading map file /etc/auto.nfsshare
 Nov 20 00:25:38 localhost.localdomain automount[21204]: parse_init: parse(sun): init gathered global options: (null)
 Nov 20 00:25:38 localhost.localdomain automount[21204]: spawn_mount: mtab link detected, passing -n to mount
 Nov 20 00:25:38 localhost.localdomain automount[21204]: spawn_umount: mtab link detected, passing -n to mount
 Nov 20 00:25:38 localhost.localdomain automount[21204]: mounted direct on /tests/nfsshare with timeout 300, freq 75 seconds
 Nov 20 00:25:38 localhost.localdomain automount[21204]: do_mount_autofs_direct: mounted trigger /tests/nfsshare
 Nov 20 00:25:38 localhost.localdomain automount[21204]: st_ready: st_ready(): state = 0 path /-
 Nov 20 00:25:38 localhost.localdomain systemd[1]: Started Automounts filesystems on demand.

当我尝试通过ls -l /tests/nfsshare强制安装 nfs 共享时,我的日志中会出现以下内容:

 Nov 20 00:48:05 localhost.localdomain automount[22030]: handle_packet: type = 5
 Nov 20 00:48:05 localhost.localdomain automount[22030]: handle_packet_missing_direct: token 21, name /tests/nfsshare, request pid 22057
 Nov 20 00:48:05 localhost.localdomain automount[22030]: attempting to mount entry /tests/nfsshare
 Nov 20 00:48:05 localhost.localdomain automount[22030]: lookup_mount: lookup(file): looking up /tests/nfsshare
 Nov 20 00:48:05 localhost.localdomain automount[22030]: lookup_mount: lookup(file): /tests/nfsshare -> -fstype=nfs,credentials=/etc/credenti...fsshare
 Nov 20 00:48:05 localhost.localdomain automount[22030]: parse_mount: parse(sun): expanded entry: -fstype=nfs,credentials=/etc/credentials.tx...fsshare
 Nov 20 00:48:05 localhost.localdomain automount[22030]: parse_mount: parse(sun): gathered options: fstype=nfs,credentials=/etc/credentials.txt  
 Nov 20 00:48:05 localhost.localdomain automount[22030]: [90B blob data]
 Nov 20 00:48:05 localhost.localdomain automount[22030]: dev_ioctl_send_fail: token = 21
 Nov 20 00:48:05 localhost.localdomain automount[22030]: failed to mount /tests/nfsshare
 Nov 20 00:48:05 localhost.localdomain automount[22030]: handle_packet:      type = 5
 Nov 20 00:48:05 localhost.localdomain automount[22030]: handle_packet_missing_direct: token 22, name /tests/nfsshare, request pid 22057
 Nov 20 00:48:05 localhost.localdomain automount[22030]: dev_ioctl_send_fail: token = 22

此外,ls -l /tests/nfsshare实际上会产生错误:

 ls: cannot access nfsshare/: No such file or directory

我该如何解决这个问题?如前所述,手动安装共享工作正常。

4

2 回答 2

0

我认为问题在于目录/tests/nfsshare存在,请尝试:

  • 删除它rm -r /tests/nfsshare
  • 然后强制安装ls -la /tests/nfsshare

从这个链接红帽:21.2.2。使用 autofs 挂载 NFS 文件系统 autofs的目标目录不应该存在,因为它是由 automount 创建的。

希望这可以帮助。

于 2015-11-19T20:05:28.710 回答
0

Autofs 不会安装在直接文件夹中,例如。我们希望将 nfs 路径挂载到 /var/www/test。

/var/www 包含其他文件。因此,该问题的最佳解决方案是将路径映射到单独的文件夹并创建指向相关路径的链接。

在本地机器中创建路径

mkdir /mnt/tests/nfsshare

/etc/auto.master - 制作以下条目以挂载 nfs 路径。

/mnt/tests       /etc/auto.nfsshare 

在 /etc/auto.nfsshare 中输入以下条目

nfsshare       -fstype=nfs,credentials=/etc/credentials.txt    192.168.254.105:/srv/nfsshare

创建指向文件夹 /mnt/tests/nfsshare 的链接

ln -s /mnt/tests/nfsshare /var/www/nfsshare
于 2018-11-24T07:29:39.343 回答