Linux-----NFS共享功能|客户端auto触发式挂载
一、NFS简介:
NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它允许网络中的计算机之间通过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用可以透明地读写位于远端NFS服务器上的文件,就像访问本地文件一样。
节省本地存储空间,将常用的数据存放在一台NFS服务器上且可以通过网络访问,那么本地终端将可以减少自身存储空间的使用。
二、Linux下的NFS配置
服务端(ip:172.25.254.105)
1)装NFS软件
yum install nfs-utils ##装NFS软件
systemctl start nfs ##开启NFS
2)配置NFS相关防火墙策略
systemctl start firewalld ##打开火墙
firewall-cmd --permanent --add-service=nfs ##允许nfs
firewall-cmd --permanent --add-service=rpc-bind ##允许rpc-bind(自动给端口)
firewall-cmd --permanent --add-service=mountd ##允许nfs服务挂载
firewall-cmd --reload ##重新加载
firewall-cmd --list-all ##查看火墙允许服务
3)修改NFS配置文件
man 5 exports ##查询EXAMPLE,看例子怎么写
vim /etc/exports ##nfs 配置文件
/mnt *(ro,sync) ## *对于所有用户,sync同步数据
##分享/mnt目录,所有用户只读
exportfs -rv ##刷新NFS配置文件
为了展示实验效果
服务端在分享目录建立文件
[[email protected] mnt]# ls
file
[[email protected] mnt]# cat file
我爱你!
客户端清空挂载目录
[[email protected] westos]# rm -fr /westos/*
[[email protected] westos]# ls
4)客户端获取共享文件
showmount -e 172.25.254.105 ##展示在服务端的挂载点
mount 172.25.254.205:/mnt /westos ##挂载服务端共享目录
能看到共享文件
[[email protected] westos]# ls
file
[[email protected] westos]# cat file
我爱你!
三、客户端auto触发式挂载
1)安装aotofs软件
yum install autofs -y ##安装aotofs软件
2)设定自动挂载功能
vim /etc/auto.master ##主配置文件
8 /westos /etc/auto.westos ##/westos为上层挂载目录
##/etc/auto.westos为虚拟配置文件
vim /etc/auto.westos ##配置虚拟配置文件
1 westos1 172.25.254.105:/mnt ##westos为隐藏挂载点
##172.25.254.105:/mnt为挂载分享目录
vim /etc/autofs.conf ##aotofs的副配置文件
15 timeout = 5 ##退出隐藏挂载点后挂载时间
systemctl restart autofs ##重启服务
3)测试
[[email protected] ~]# cd /westos/ ##进入上层挂载目录
[[email protected] westos]# ls ##什么都没有
[[email protected] westos]# cd westos1 ##进入隐藏挂载点(自动挂载)
[[email protected] westos1]# ls
file
[[email protected] westos1]# cat file
我爱你!
四、/etc/exports文件
/mnt *(ro,sync) 172.25.254.72(rw,sync) ##设置所有人对目录/mnt只读挂载
##对172.25.254.72读写挂载
##本地文件系统的权限需要777
/mnt *(ro,sync) 172.25.254.72(rw,sync,no_root_squash)
##使172.25.254.72身份显示为root,而不是匿名
/mnt *(ro,sync) 172.25.254.72(rw,sync,anonuid=1000,anongid=1001)
##建立文件的所有人为id=1000
##所有组为gid=1001
用 man 5 expors 查看更多