前面内容我讲到了NFS以及autofs自动挂载服务,这一节内容我想针对这两个内容的知识做一个补充,主要是以实验的方式呈现。那么在NFS网络文件系统里面我们可以以NFS客户端通过NFS服务端共享去访问所需要的资源,但是我们需要自己进行手动挂载,在操作的便利性比较繁琐,那么我们这个时候就可以运用autofs自动挂载服务,当NFS客户端想要访问对应文件的时候,autofs会动态挂载信息,我们在顺利访问文件的同时也更加便利了
第一步:我们先将NFS共享目录卸载掉。同时在autofs服务程序的主配置文件中会有一个“/misc/etc/auto.misc”参数,这个auto.misc相当于自动挂载的参考文件,它默认已经存在。
[root@blue ~] umount /nfsfile
[root@blue ~] vim /etc/auto.master
# Sample auto.master file
# This is a 'master' automounter map and it has the following format:
# mount-point [map-type[,format]:]map [options]
# For details of the format look at auto.master(5).
#
/media /etc/iso.misc
/misc /etc/auto.misc
第二步:找到这个对应的auto.misc文件,填写本地挂载的路径和NFS服务器的挂载信息:
[root@blue ~]# vim /etc/auto.misc
# This is an automounter map and it has the following format
# key [ -mount-options-separated-by-comma ] location
# Details may be found in the autofs(5) manpage
nfsfile 172.25.0.254:/nfsfile
cd -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
第三步:重启autofs服务程序,当用户进入到/misc/nfsfile目录时,便会自动挂载共享信息
[root@blue ~]# systemctl restart autofs
[root@blue ~]# cd /misc/nfsfile
[root@blue nfsfile]# df -h
文件系统 容量 已用 可用 已用% 挂载点
devtmpfs 1.9G 0 1.9G 0% /dev
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 2.0G 9.9M 2.0G 1% /run
tmpfs 2.0G 0 2.0G 0% /sys/fs/cgroup
/dev/mapper/rhel-root 17G 4.0G 14G 23% /
/dev/sdb1 2.0G 47M 2.0G 3% /newFS
/dev/sda1 1014M 160M 855M 16% /boot
tmpfs 392M 16K 392M 1% /run/user/42
tmpfs 392M 3.5M 389M 1% /run/user/0
172.25.0.254:/nfsfile 17G 4.0G 14G 24% /misc/nfsfile