环境
CentOS 8
参考
https://wiki.archlinux.org/index.php/NFS_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)
服务端
安装 nfs-utils
1 2 3 4 5 6 7
| yum install nfs-utils
systemctl enable rpcbind.service systemctl enable nfs-server.service
systemctl start rpcbind.service systemctl start nfs-server.service
|
创建共享目录
1 2
| mkdir /nfs chmod 755 /nfs
|
配置 nfs
1 2
| /nfs/ 192.168.0.0/16(rw,sync,no_root_squash,no_all_squash)
|
1 2
| systemctl restart nfs-server.service
|
配置参数
- ro:共享目录只读;
- rw:共享目录可读可写;
- all_squash:所有访问用户都映射为匿名用户或用户组;
- no_all_squash(默认):访问用户先与本机用户匹配,匹配失败后再映射为匿名用户或用户组;
- root_squash(默认):将来访的root用户映射为匿名用户或用户组;
- no_root_squash:来访的root用户保持root帐号权限;
- anonuid=:指定匿名访问用户的本地用户UID,默认为nfsnobody(65534);
- anongid=:指定匿名访问用户的本地用户组GID,默认为nfsnobody(65534);
- secure(默认):限制客户端只能从小于1024的tcp/ip端口连接服务器;
- insecure:允许客户端从大于1024的tcp/ip端口连接服务器;
- sync:将数据同步写入内存缓冲区与磁盘中,效率低,但可以保证数据的一致性;
- async:将数据先保存在内存缓冲区中,必要时才写入磁盘;
- wdelay(默认):检查是否有相关的写操作,如果有则将这些写操作一起执行,这样可以提高效率;
- no_wdelay:若有写操作则立即执行,应与sync配合使用;
- subtree_check(默认) :若输出目录是一个子目录,则nfs服务器将检查其父目录的权限;
- no_subtree_check :即使输出目录是一个子目录,nfs服务器也不检查其父目录的权限,这样可以提高效率;
客户端
挂载
1
| mount -t nfs -o vers=4 servername:/music /mountpoint/on/client
|
通过 fstab 自动挂载
1 2
| servername:/music /mountpoint/on/client nfs defaults 0 0
|