linux 无法在Centos 7上自动装载NFS共享

wkyowqbh  于 2023-08-03  发布在  Linux
关注(0)|答案(3)|浏览(149)

我有一个新的Centos 7安装。我似乎无法从Centos客户端自动挂载位于192.168.254.105:/srv/nfsshare上的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


预期的行为是,当我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


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

xzlaal3s

xzlaal3s1#

我相信问题在于目录/tests/nfsshare存在,尝试:

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

通过此链接Redhat: 21.2.2. Mounting NFS File Systems using autofs,autofs的目标目录不应该存在,因为是由automount创建的。
希望这对你有帮助。

wz8daaqr

wz8daaqr2#

Autofs不安装在直接文件夹中。我们希望将nfs路径挂载到/var/www/test。
/var/www包含其他文件。因此,最好的解决方案是将路径Map到单独的文件夹,并创建到相关路径的链接。
在本地计算机中创建路径

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

u0njafvf

u0njafvf3#

@Abhinav Aggarwal
在/etc/auto.master文件中,您可以挂载直接文件夹add /-而不是/mnt/tests
''/- /etc/auto.nfsshare ''

相关问题