实验搭建NFS,进行挂载。

发现,客户端挂载报错,其实原因很简单,但是博客作者并未有碰到过,所以查了下资料。

主要参考:一个是官方文档,一个是系统日志。

实验环境:

[root@cahou nfs]# cat /etc/issue
CentOS release 5.8 (Final)
Kernel \r on an \m

[root@cahou nfs]# uname -r
2.6.18-308.el5
 

一个服务器 ,两个客户端,其中一个客户端不能挂载共享目录,另外一个正常。

不能挂载的客户端报错如下:

[root@*** nfs]# mount -t nfs  192.168.88.128:/home/toshiba/nfstest  /mnt/nfstest
mount: 192.168.88.128:/home/toshiba/nfstest failed, reason given by server: Permission denied

开始查了些资料,讲的并不是我遇到的问题,最后想了下,看看日志,再加上看官方文档,解决了。

服务器端日志如下,发现了问题所在

Sep 20 17:34:00 nfs kernel: NFSD: Using /var/lib/nfs/v4recovery as the NFSv4 state recovery directory
Sep 20 20:30:17 nfs mountd[5457]: refused mount request from 192.168.88.129 for /home/toshiba/nfstest (/): not exported
Sep 20 20:31:04 nfs mountd[5457]: refused mount request from 192.168.88.129 for /home/toshiba/nfstest (/): not exported
Sep 20 20:35:48 nfs mountd[5457]: refused mount request from 192.168.88.129 for /home/toshiba/nfstest (/): not exported
Sep 20 20:38:40 nfs mountd[5457]: refused mount request from 192.168.88.129 for /home/toshiba/nfstest (/): not exported
Sep 20 20:43:34 nfs mountd[5457]: refused mount request from 192.168.88.129 for /home/toshiba/nfstest (/): not exported
Sep 20 20:48:29 nfs mountd[5457]: authenticated mount request from 192.168.88.130:790 for /home/toshiba/sed_test/nfstest (/home/toshiba/sed_test/nfstest)
Sep 20 20:49:37 nfs mountd[5457]: refused mount request from 192.168.88.129 for /home/toshiba/nfstest (/): not exported
Sep 20 20:50:34 nfs mountd[5457]: refused mount request from 192.168.88.129 for /home/toshiba/nfstest (/): not exported
Sep 20 21:05:19 nfs mountd[5457]: refused mount request from 192.168.88.129 for /home/toshiba/nfstest (/): not exported

 日志说该目录未被导出,也就是该目录并未被共享,仔细查看目录名,发现该目录名敲错了。

在NFS开源项目在sourceforge的网站上,也有专门的troubleshooting文档,

 http://nfs.sourceforge.net/nfs-howto/ar01s07.html

其中,该文档中就专门讲了permission denied的问题。

7.3. Unable to mount a file system

There are two common errors that mount produces when it is unable to mount a volume. These are:

  1. failed, reason given by server: Permission denied

    This means that the server does not recognize that you have access to the volume.

    • Check your /etc/exports file and make sure that the volume is exported and that your client has the right kind of access to it. For example, if a client only has read access then you have to mount the volume with the ro option rather than the rw option.

文档说的很清楚,要确认共享目录已经存在,并确认该目录已经写在/etc/exports里面了,并且有合适的权限去访问。

这个问题并不复杂,从中学到的是解决思路。

排查问题,看日志,看官方文档。