环境:centos7.1
server:192.168.0.63
client:192.168.0.64 (centos7.1 客户端)
共享文件的目录用户为:web(uid:1000,gid:1000)
yum -y install nfs-utils rpcbind
nfs 的配置文件 /etc/expots
共享目录赋予权限:chmod 755 /home/data
vim /etc/exports
/home/data 192.168.0.0/24(rw,async,insecure,anonuid=1000,anongid=1000,no_root_squash)
exportfs -rv
配置文件说明:
/opt/test 为共享目录
(以上内容:参考:man nfs)
systemctl enable rpcbind
systemctl start rpcbind
systemctl enable nfs-server
systemctl start nfs-server
确认NFS服务器启动成功:
rpcinfo -p
查看具体目录挂载权限
cat /var/lib/nfs/etab
1、linux客户端挂载:
在从机上安装NFS 客户端
首先是安裝nfs,然后启动rpcbind服务
systemctl enable rpcbind.service
systemctl start rpcbind.service
注意:客户端不需要启动nfs服务
检查 NFS 服务器端是否有目录共享:
showmount -e nfs服务器的IP
showmount -e 192.168.0.63
客户端挂载#开机自动挂载
vim /etc/fstab
192.168.0.63:/home/data /home/data nfs4 rw,hard,intr,proto=tcp,port=2049,noauto 0 0
手工挂载:
mount -t nfs 192.168.0.63:/home/data /home/data
#查看是否挂载成功。
df -h
NFS默认是用UDP协议,换成TCP协议达到稳定传输目的:
mount -t nfs 192.168.0.63:/home/data /home/data -o proto=tcp -o nolock
2、windows客户端挂载:
由于自带的客户端功能少,缺少用户名映射,功能,所以必然会遇到权限的问题。所以需要自行配置权限问题
获取nfs server 用户web的gid和uid,并记录uid和gid,当前为:1000
打开注册表编辑器,找到HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default,添加两个REG_DWORD值,填上uid和gid(10进制)完成后重启电脑
注册表导出是如下格式 :
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\ClientForNFS\CurrentVersion\Default]
"AnonymousGid"=dword:000003e8
"AnonymousUid"=dword:000003e8
mount -o anon mtype=soft lang=ansi \\192.168.0.63\home\data\ Z:\
事项:一定要用软装载模式(mtype=soft),防止资源管理器停止响应,不能用utf-8
参考:http://nfs.sourceforge.net/nfs-howto/index.html