NFS

*******nfs的作用,是将需要共享的目录上传到nfs服务器,然后客户端再从nfs服务器上将共享的目录挂载到本地供自己使用*********

//
!!服务端设置 [root@localhost ~]# yum install -y nfs-utils rpcbind [root@localhost ~]# vim /etc/exports /*加入下列内容 第一段为共享出去的文件夹 第二段ip为client端的ip 第三段括号里的为权限*/ /home/ 192.168.137.0/24(rw,sync,all_squash,anonuid=501,anongid=501) //以下的顺序不可以换 [root@localhost ~]# /etc/init.d/rpcbind start; [root@localhost ~]# /etc/init.d/nfs start //服务端和客户端查看已共享的什么目录 //查看方法1 [root@localhost ~]# showmount -e 192.168.137.10 //此处ip为服务端ip Export list for 192.168.137.10 /home 192.168.137.0/24 //查看方法2 [root@localhost ~]# exportfs -arv exporting 192.168.137.0/24:/home //!!客户端设置 [root@localhost ~]# yum install -y nfs-utils rpcbind //将共享的目录挂载到本地有2种方法,请任选其一 //挂载方法1 [root@localhost ~]# mount -t nfs -o nolock 192.168.137.10:/home/ /mnt/ //挂载方法2 [root@localhost ~]# mkdir /test //创建将挂载下来的目录存储的地方
[root@localhost
~]# vim /etc/fstab //加入 ... ... 192.168.137.10:/home/ /test nfs nolock 0 0 ... ... //让挂载生效 [root@localhost ~]# mount -a //查看是否已挂载上 [root@localhost ~]# df -h

挂载时可能出现的错误!!!!!

1. 挂载时出现“access denied by server while mounting”的错误

解决方法: --》

首先想到的是iptables防火墙问题,于是关闭防火墙,也一样报错。

1、使用了非法端口,也就是使用了大于1024的端口。
这个错误,可以通过查看日志确认:
[root@local~ /]# cat /var/log/messages | grep mount
Jan 2 12:49:04 localhost mountd[1644]: refused mount request from 192.168.0.100 for /home/nfsshare/ (/home/nfsshare): illegal port 1689
 
解决办法:
修改配置文件/etc/exports,加入 insecure 选项,重启nfs服务,再尝试挂载。
/home/nfsshare/  *(insecure,rw,async,no_root_squash)
 
2、NFS版本问题
编辑/etc/sysconfig/nfs文件,找到下面:

#Turn off v2 and v3 protocol support 
#RPCNFSDARGS="-N 2 -N 3" 
#Turn off v4 protocol support 
#RPCNFSDARGS="-N 4"  /*把这句前面的#号去掉*/

最后保存,重启nfs服务,再尝试挂载;如果挂载不上,可尝试在后面加-o nolock参数。
 
3、查看客户端挂载的目录是否具备读写权限,添加相应权限即可。
 
4、nfs服务器上的/etc/hosts中设置了客户端机器IP对应域名,去掉即可。
 
通过以上这几种方法,access denied by server while mounting这个错误应该可以得到解决了。
2.挂载后,需要取消挂载 (umount)时,出现umount.nfs: device is busy 的错误

解决方法: --》


root@ubuntu:/# umount /app/nfs/ 
umount.nfs: /app/nfs: device is busy 
umount.nfs: /app/nfs: device is busy
提示文件系统设置busy

先使用这条命令
root@ubuntu:/# fuser -km /app/nfs/   
/data/nfs/:                     8119c 

这时可能会断掉,请再重新连接
root@ubuntu:/# umount /app/nfs/      在umount 就可以了
root@ubuntu:/#
原文地址:https://www.cnblogs.com/frankielf0921/p/5380293.html