nfs

nfs类linux操作系统可用

1.nfs
net file system

2.nfs的启用
yum install nfs-utils -y(默认装好的)客户端服务端都叫这个
在服务端
systemctl start nfs-server
systemctl enable nfs-server
systemctl stop firewalld

测试
在客户端
showmount -e 172.25.254.120
Export list for 172.25.254.120:


nfs


3.配置共享


mkdir /nfsdir

vim /etc/exports
/nfsdir *(sync)
名字 共享给谁 sync允许数据同步()方式

测试(1)
服务端
exportfs -rv ##同步上传

exporting *:/nfsdir


nfs


客户端
showmount -e 172.25.254.120
Export list for 172.25.254.120

/nfsdir *


nfs


测试(2)
客户端

mount 172.25.254.120:/nfsdir /mnt/
ls /mnt(没有)
在服务器中touch /nfsdir/file{1..10}
在客户端再次ls /mnt 看见刚才建立的十个文件,即同步成功

4.
在服务端
vim /etc/exports
/nfsdir         172.25.254.0/24(sync)
/nfsdir         172.25.254.220(rw)

exportfs -rv
exporting 172.25.254.220:/nfsdir
exporting 172.25.254.0/24:/nfsdir

chmod 777 /nfsdir

之后在客户端就可以在/mnt下建立文件了,但是用户是nfsnobody


nfs


在服务端
vim /etc/exports
/nfsdir         172.25.254.0/24(sync)

/nfsdir         172.25.254.220(rw,anonuid=1001,anongid=1001) ##westos的uid为1001


nfs


exportfs -rv
exporting 172.25.254.220:/nfsdir
exporting 172.25.254.0/24:/nfsdir

在客户端建立文件,文件用户即为westos,用户组也为westos


nfs


在服务端
vim /etc/exports
/nfsdir         172.25.254.0/24(sync)
/nfsdir         172.25.254.220(rw,anonuid=1001,anongid=1001,no_root_squash) ##用户建立的文件用户和用户组都为该用户自己

exportfs -rv
exporting 172.25.254.220:/nfsdir
exporting 172.25.254.0/24:/nfsdir

在客户端 su - student

在/mnt下建立文件后用户和用户组都是student


nfs


5.用的时候自动挂载,不用自动卸载
首先卸载/mnt
ls -ld /net/(没有这个文件)
yum install autofs.x86_64 -y
systemctl start autofs
systemctl enable autofs
ls -ld /net/(安装之后就有了)
cd /net/172.25.254.120/nfsdir
df ##查看,已经挂载
vim /etc/sysconfig/autofs
TIMEOUT=3 ##更改退出改目录后挂载的时间为三秒

cd退出 等待三秒 之后发现已经卸载。


nfs

重新进入该目录,再次挂载

6.指定挂载点
vim /etc/auto.master
/mnt    /etc/auto.nfs ##这是个没有的文件,需要编辑
vim /etc/auto.nfs
westos   -ro,vers=3.0     172.25.254.120:/nfsdir
最终挂载点 挂载参数 挂载共享
systemctl restart autofs.service
df查看,已经挂载

mount查看挂载状态,已经被更改


nfs