How to install AutoFs mount service on Linux system

Regardless of whether it is a Samba service or an NFS service, the mount information must be written to /etc/fstab, so that the remote shared resources will be automatically mounted when the server is turned on.

How to install AutoFs mount service on Linux system How to install AutoFs mount service on Linux system

[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! 

A Linux server in a production environment generally manages the mounting operations of many devices at the same time. If these device mounting information are written into the main configuration file of the autofs service, it will undoubtedly make the main configuration file bloated, which is not conducive to the efficiency of service execution, and it is not conducive to modifying the configuration content in the future. Therefore, in the autofs service program The main configuration file needs to be filled in according to the format of "mount directory sub-configuration file". The mount directory is the upper level directory of the device mount location.

For example, CD-ROM devices are generally mounted in the /media/cdrom directory, then the mounting directory can be written as /media. The corresponding sub-configuration file further explains the information of the mounted device in the mounted directory. The sub-configuration file needs to be defined by the user. The file name is not strictly required, but the suffix must end with .misc. The specific configuration parameters are shown in bold on the 7th line.

[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 

In the sub-configuration file, fill in the format of "File Type and Permission for Mounting Directory: Device Name". For example, to mount the CD-ROM device to the /media/iso directory, you can write the mount directory as iso, and -fstype is the file system format parameter, iso9660 is the CD-ROM device format, ro, nosuid, and nodev are specific to the CD-ROM device Permission parameter, /dev/cdrom defines the name of the device to be mounted. After the configuration is complete, start the autofs service program and add it to the system startup item:

[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' 

A very interesting thing will happen next. Let's first check the current mounting situation of the CD-ROM device and confirm that the CD-ROM device is not mounted, and there is no iso subdirectory in the /media directory at all. However, we can use the cd command to switch to this iso subdirectory, and the CD-ROM device will be automatically mounted immediately. We can also check the contents of the CD smoothly.

[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  

Guess you like

Origin blog.csdn.net/yaxuan88521/article/details/115231287