server:192.168.1.1
client:192.168.1.2
服务端
1、安装server端软件:
yum install nfs-utils rpcbind -y
systemctl start nfs && systemctl start rpcbind
systemctl enable nfs && systemctl enable rpcbind
2、创建服务器端需要共享出去的目录
mkdir -p /test/app
3、编辑配置文件
vim /etc/exports
/test/app 192.168.1.0/24(rw,sync,no_root_squash)
说明:
/test/app # 设置共享出去的目录
192.168.1.0 # 设置允许访问的网段
rw 读写
ro 只读
sync 同步模式,内存数据实时写入磁盘 速度很快但是会降低磁盘效率
async 非同步模式 能保证磁盘效率 但是如果服务器断电,会造成数据丢失
no_root_squash 客户端挂载NFS共享目录后,root用户不受约束,权限很大
root_squash 与上面选项相对,客户端上的root用户收到约束,被限定成某个普通用户
all_squash 客户端上所有用户在使用NFS共享目录时都被限定为一个普通用户
anonuid/anongid 和上面几个选项搭配使用,定义被限定用户的uid和gid
4、重启服务
systemctl restart rpcbind && systemctl restart nfs
查看本地挂载点
showmount -e localhost
客户端:
创建用来挂载的目录
mkdir /test
mount -t nfs 192.168.1.1:/test/app /test
df -hT #查看是否挂载成功
开机自动挂载编辑/etc/fstab,添加如下格式语句
192.168.1.1:/test/app /test nfs defaults 0 0
卸载挂载点
umount /test