一、实验背景
在nfsServer共享家某个用户家目录下的目录,mount.nfs: access denied by server 客户端显示权限拒绝。
二、实验环境
操作系统: CentOS7.5 Minimal
nfsServer: 192.168.1.106
nfsClinet: 192.168.1.104
三、安装配置nfsServer
创建用户和共享目录
# groupadd -g 2019 Michael
# useradd -u 2019 -g 2019 Michael
# mkdir /home/Michael/test
# chown -R 2019:2019 /home/Michael/test
关闭selinux
# setenforce 0
# sed -i 's/^SELINUX=.*/SELINUX=permissive/g' /etc/selinux/config
安装nfs软件包
# yum -y install nfs-utils rpcbind
编写配置文件
# vim /etc/exports
#############################################################
/home/Michael/test 192.168.1.104(rw,sync,anonuid=2019,anongid=2019)
##############################################################
启动服务
# systemctl start rpcbind
# systemctl start nfs-server
# systemctl enable rpcbind nfs-server
# exportfs -avr
# showmount -e 127.0.0.1
添加防火墙规则
# firewall-cmd --permanent --add-service=nfs
# firewall-cmd --permanent --add-service=mountd
# firewall-cmd --permanent --add-service=rpc-bind
# firewall-cmd --reload
查看nfs服务版本
# rpcinfo -p | grep -iE "service|NFS"
三、安装配置nfsClient
创建挂载目录
# mkdir -p /opt/client
# chown -R 2019:2019 /opt/client
安装nfs软件包
# yum -y install nfs-utils rpcbind
启动客户端服务
# systemctl start rpcbind
systemctl enable rpcbind
# systemctl status rpcbind
# showmount -e 192.168.1.106
不同版本挂载测试
# mount -t nfs4 192.168.1.106:/home/Michael/test /opt/client
# mount -t nfs -o nfsvers=4 192.168.1.106:/home/Michael/test /opt/client
# man nfs
# man 8 nfsd
现在系统自带的是NFS4,默认并不支持NFS3之前的协议,解决办法:
方法1 在客户端挂载的时候指定协议版本
# mount -t nfs -o nfsvers=3 192.168.1.106:/home/Michael/test /opt/client
mount 一些其他常用option:
# mount -t nfs -o nfsvers=3 -o nosuid,noexec,nodev,rw -o bg,soft,rsize=32768,wsize=32768 192.168.1.106:/home/Michael/test /opt/client
方法2 更改服务端配置文件,关闭NFS4
# vim /etc/sysconfig/nfs
设置 RPCNFSDARGS="-N 4" ,表示关闭 NFS4
# systemctl restart rpcbind nfs-server
# mount -t nfs -vvv 192.168.1.106:/home/Michael/test /opt/client/
四、参考
k8s 使用 nfs 下 pod 无法创建的解决思路
https://zhangguanzhang.github.io/2023/08/18/kubernetes-nfs-waiting-condition/
【NFS】CentOS7.x NFS服务器和客户端设置
https://www.jianshu.com/p/b415da3bb198
【NFS&firewalld】How to correct firewalld in Centos7 to allow NFS access?
https://www.jianshu.com/p/dd285a16928d
NFS 错误的几个原因整理
https://blog.51cto.com/752030200/1825309
How to properly set permissions for NFS folder?
https://serverfault.com/questions/240897/how-to-properly-set-permissions-for-nfs-folder-permission-denied-on-mounting-en
https://serverfault.com/questions/223408/uid-gid-with-nfs-and-zfs#answer-223415
Who’s 4294967294?
https://blogs.msdn.microsoft.com/sfu/2007/04/19/whos-4294967294/
How to resolve “mount.nfs: access denied by server while mounting”
https://www.thegeekdiary.com/mount-nfs-access-denied-by-server-while-mounting-how-to-resolve