部署
yum -y install nfs-utils rpcbind
mkdir /thc/nfs && chmod 777 /thc/nfs
systemctl start rpcbind && systemctl enable rpcbind
systemctl start nfs-server && systemctl enable nfs-server
systemctl start nfs-lock && systemctl enable nfs-lock
systemctl start nfs-idmap && systemctl enable nfs-idmap
/thc/nfs *(inscure,rw,sync,no_root_squash)
exportfs -a
showmount -e
使用 - 客户端
mount -t nfs 192.168.248.79:/thc/nfs /home/nfs/
192.168.248.79:/thc/nfs /home/nfs nfs defaults 0 0
配置文件详解
/thc/nfs *(rw,insecure,sync,no_root_squas)
第一段: 共享目录
第二列: 允许访问主机
192.168.152.13 指定IP地址的主机
nfsclient.test.com 指定域名的主机
192.168.1.0/24 指定网段中的所有主机
*.test.com 指定域下的所有主机
* 所有主机
第三列: 权限参数
ro 只读访问
rw 读写访问
sync 所有数据在请求时写入共享
async NFS在写入数据前可以相应请求
secure NFS通过1024以下的安全TCP/IP端口发送
insecure NFS通过1024以上的端口发送
wdelay 如果多个用户要写入NFS目录,则归组写入(默认)
no_wdelay 如果多个用户要写入NFS目录,则立即写入,当使用async时,无需此设置。
Hide 在NFS共享目录中不共享其子目录
no_hide 共享NFS目录的子目录
subtree_check 如果共享/usr/bin之类的子目录时,强制NFS检查父目录的权限(默认)
no_subtree_check 和上面相对,不检查父目录权限
all_squash 共享文件的UID和GID映射匿名用户anonymous,适合公用目录。
no_all_squash 保留共享文件的UID和GID(默认)
root_squash root用户的所有请求映射成如anonymous用户一样的权限(默认)
no_root_squash root用户具有根目录的完全管理访问权限
anonuid=xxx 指定NFS服务器/etc/passwd文件中匿名用户的UID
/tmp *(rw,no_root_squash)
/home/public 192.168.0.*(rw) *(ro)
/home/test 192.168.0.100(rw)
/home/linux *.the9.com(rw,all_squash,anonuid=40,anongid=40)