关于linux:Linux-系统安装-AutoFs-挂载服务

5次阅读

共计 3863 个字符,预计需要花费 10 分钟才能阅读完成。

无论是 Samba 服务还是 NFS 服务,都要把挂载信息写入到 /etc/fstab 中,这样近程共享资源就会主动随服务器开机而进行挂载。尽管这很不便,然而如果挂载的近程资源太多,则会给网络带宽和服务器的硬件资源带来很大负载。如果在资源挂载后长期不应用,也会造成服务器硬件资源的节约。

可能会有读者说,能够在每次应用之前执行 mount 命令进行手动挂载。这是一个不错的抉择,然而每次都须要先挂载再应用,您不感觉麻烦吗?

autofs 主动挂载服务能够帮咱们解决这一问题。与 mount 命令不同,autofs 服务程序是一种 Linux 零碎守护过程,当检测到用户试图拜访一个尚未挂载的文件系统时,将主动挂载该文件系统。

换句话说,咱们将挂载信息填入 /etc/fstab 文件后,零碎在每次开机时都主动将其挂载,而 autofs 服务程序则是在用户须要应用该文件系统时才去动静挂载,从而节约了网络资源和服务器的硬件资源。

[root@localhost ~]# yum install autofs
Loaded plugins: langpacks, product-id, subscription-manager
......
Running transaction
Installing : hesiod-3.2.1-3.el7.x86_64 1/2
Installing : 1:autofs-5.0.7-40.el7.x86_64 2/2
Verifying : hesiod-3.2.1-3.el7.x86_64 1/2
Verifying : 1:autofs-5.0.7-40.el7.x86_64 2/2
Installed:
autofs.x86_64 1:5.0.7-40.el7
Dependency Installed:
hesiod.x86_64 0:3.2.1-3.el7
Complete!

处于生产环境中的 Linux 服务器,个别会同时治理许多设施的挂载操作。如果把这些设施挂载信息都写入到 autofs 服务的主配置文件中,无疑会让主配置文件臃肿不堪,不利于服务执行效率,也不利于日后批改外面的配置内容,因而在 autofs 服务程序的主配置文件中须要依照“挂载目录 子配置文件”的格局进行填写。挂载目录是设施挂载地位的上一级目录。

例如,光盘设施个别挂载到 /media/cdrom 目录中,那么挂载目录写成 /media 即可。对应的子配置文件则是对这个挂载目录内的挂载设施信息作进一步的阐明。子配置文件须要用户自行定义,文件名字没有严格要求,但后缀必须以.misc 完结。具体的配置参数如第 7 行的加粗字所示。

[root@localhost ~]# vim /etc/auto.master
#
# Sample auto.master file
# This is an automounter map and it has the following format
# key [-mount-options-separated-by-comma] location
# For details of the format look at autofs(5).
/media /etc/iso.misc
/misc /etc/auto.misc
#
# NOTE: mounts done from a hosts map will be mounted with the
# "nosuid" and "nodev" options unless the "suid" and "dev"
# options are explicitly given.
/net -hosts
#
# Include /etc/auto.master.d/*.autofs
+dir:/etc/auto.master.d
#
# Include central master map if it can be found using
# nsswitch sources.
#
# Note that if there are entries for /net or /misc (as
# above) in the included master map any keys that are the
# same will not be seen as the first read key seen takes
# precedence.
+auto.master

在子配置文件中,应依照“挂载目录 挂载文件类型及权限 : 设施名称”的格局进行填写。例如,要把光盘设施挂载到 /media/iso 目录中,可将挂载目录写为 iso,而 -fstype 为文件系统格局参数,iso9660 为光盘设施格局,ro、nosuid 及 nodev 为光盘设施具体的权限参数,/dev/cdrom 则是定义要挂载的设施名称。配置实现后再棘手将 autofs 服务程序启动并退出到零碎启动项中:

[root@localhost ~]# vim /etc/iso.misc
iso   -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
[root@localhost ~]# systemctl start autofs
[root@localhost ~]# systemctl enable autofs
ln -s '/usr/lib/systemd/system/autofs.service' '/etc/systemd/system/multi-user.target.wants/autofs.service'

接下来将产生一件十分乏味的事件。咱们先查看以后的光盘设施挂载状况,确认光盘设施没有被挂载上,而且 /media 目录中基本就没有 iso 子目录。然而,咱们却能够应用 cd 命令切换到这个 iso 子目录中,而且光盘设施会被立刻主动挂载上。咱们也就能顺利查看光盘内的内容了。

[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.0G 15G 17% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 140K 914M 1% /dev/shm
tmpfs 914M 8.9M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/sda1 497M 119M 379M 24% /boot
[root@linuxprobe ~]# cd /media
[root@localhost media]# ls
[root@localhost media]# cd iso
[root@localhost iso]# ls -l
total 812
dr-xr-xr-x. 4 root root 2048 May 7 2017 addons
dr-xr-xr-x. 3 root root 2048 May 7 2017 EFI
-r--r--r--. 1 root root 8266 Apr 4 2017 EULA
-r--r--r--. 1 root root 18092 Mar 6 2012 GPL
dr-xr-xr-x. 3 root root 2048 May 7 2017 images
dr-xr-xr-x. 2 root root 2048 May 7 2017 isolinux
dr-xr-xr-x. 2 root root 2048 May 7 2017 LiveOS
-r--r--r--. 1 root root 108 May 7 2017 media.repo
dr-xr-xr-x. 2 root root 774144 May 7 2017 Packages
dr-xr-xr-x. 24 root root 6144 May 7 2017 release-notes
dr-xr-xr-x. 2 root root 4096 May 7 2017 repodata
-r--r--r--. 1 root root 3375 Apr 1 2017 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root 3211 Apr 1 2017 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root 1568 May 7 2017 TRANS.TBL
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 18G 3.0G 15G 17% /
devtmpfs 905M 0 905M 0% /dev
tmpfs 914M 140K 914M 1% /dev/shm
tmpfs 914M 8.9M 905M 1% /run
tmpfs 914M 0 914M 0% /sys/fs/cgroup
/dev/cdrom 3.5G 3.5G 0 100% /media/iso
/dev/sda1 497M 119M 379M 24% /boot

作者: Escape 链接: https://escapelife.github.io/…

正文完
 0