概述
Network File System,网络文件系统
用途:为客户机提供共享使用的文件夹
协议:nfs(2049)、rpc(111)
所需软件包:nfs-utils
系统服务:nfs-server
服务端
[root@server ~]# rpm -q nfs-utils
nfs-utils-1.3.0-0.54.el7.x86_64
[root@server ~]# mkdir /abc # 创建共享文件夹
[root@server ~]# echo haha > /abc/h.txt
[root@server ~]# echo xixi > /abc/x.txt
[root@server ~]# ls /abc/
[root@server ~]# vim /etc/exports
文件夹路径 客户机地址(权限) 客户机地址(权限) .. ..
/abc *(ro) # 允许所有客户端进行只读访问
[root@server ~]# systemctl start nfs-server
[root@server ~]# systemctl status nfs-server
### 使用 exportfs 可以重载更新过的配置
exportfs -r
客户端
[root@pc2 ~]# rpm -q nfs-utils
nfs-utils-1.3.0-0.54.el7.x86_64
[root@pc2 ~]# showmount -e 192.168.88.240 # 列出有哪些NFS共享资源
Export list for 192.168.88.240:
/abc *
[root@pc2 ~]# mkdir /mnt/mynfs
[root@pc2 ~]# mount 192.168.88.240:/abc /mnt/mynfs
[root@pc2 ~]# ls /mnt/mynfs
[root@pc2 ~]# df -h /mnt/mynfs # 查看正在挂载的设备信息
实现nfs的开机自动挂载
_netdev:声明网络设备,系统在具备网络参数后,再进行挂载本设备
[root@pc2 ~]# vim /etc/fstab
……此处省略
192.168.88.240:/abc /mnt/mynfs nfs _netdev 0 0
[root@pc2 ~]# umount /mnt/mynfs
[root@pc2 ~]# ls /mnt/mynfs
[root@pc2 ~]# mount -a
[root@pc2 ~]# ls /mnt/mynfs
触发挂载
一、概述
由 autofs 服务提供的 “按需访问” 机制
只要访问挂载点就会触发响应,自动挂载指定设备
闲置一段时间后(默认5分钟),会自动卸载
[root@pc2 ~]# yum -y install autofs
[root@pc2 ~]# systemctl restart autofs
[root@pc2 ~]# ls /misc
[root@pc2 ~]# ls /misc/cd
二、配置解析
主配置文件
- /etc/auto.master
- 监控点目录 挂载配置文件的路径
挂载配置文件
- /etc/auto.misc
- 触发点子目录 -挂载参数 :设备名
[root@pc2 ~]# yum -y install autofs
[root@pc2 ~]# vim /etc/auto.master
/myauto /opt/xixi.txt
[root@pc2 ~]# vim /opt/xixi.txt
nsd -fstype=iso9660 :/dev/cdrom
[root@pc2 ~]# systemctl restart autofs
[root@pc2 ~]# ls /myauto/
[root@pc2 ~]# ls /myauto/nsd
触发挂载进阶autofs与nfs
[root@pc2 ~]# yum -y install autofs
[root@pc2 ~]# vim /etc/auto.master
/myauto /opt/xixi.txt
[root@pc2 ~]# vim /opt/xixi.txt
nsd -fstype=iso9660 :/dev/cdrom
test -fstype=nfs 192.168.88.240:/abc
[root@pc2 ~]# systemctl restart autofs
[root@pc2 ~]# ls /myauto/test