Network File System
NFS应用场景是:A,B,C三台机器上须要保证被访问到的文件是同样的,A共享数据出来,B和C分别去挂载A共享的数据目录,从而B和C访问到的数据和A上的一致vim
服务端配置
yum install -y nfs-utils rpcbind
vim /etc/exports //加入以下内容
/home/nfstestdir //表示须要共享的目录
192.168.86.0/24(rw,sync,all_squash,anonuid=1000,anongid=1000)
选项含义:
rw 读写
ro 只读
sync 同步模式,内存数据实时写入磁盘
async 非同步模式
no_root_squash 客户端挂载NFS共享目录后,root用户不受约束,权限很大
root_squash 与上面选项相对,客户端上的root用户收到约束,被限定成某个普通用户
all_squash 客户端上全部用户在使用NFS共享目录时都被限定为一个普通用户
anonuid/anongid 和上面几个选项搭配使用,定义被限定用户的uid和gid
保存配置文件后,执行以下准备操做
mkdir /home/nfstestdir
chmod 777 /home/nfstestdir
systemctl start rpcbind
systemctl start nfs
systemctl enable rpcbind
systemctl enable nfsasync
客户端挂载
yum install -y nfs-utils
showmount -e 192.168.86.131 //该ip为NFS服务端ip
mount -t nfs 192.168.86.131:/home/nfstestdir /mnt 挂载到/mnt目录
touch /mnt/slx.txt
ls -l /mnt/slx.txt //能够看到文件的属主和属组都为1000ide