Linux系统如何安装AutoFs挂载服务

导读无论是Samba服务还是NFS服务,都要把挂载信息写入到/etc/fstab中,这样远程共享资源就会自动随服务器开机而进行挂载。

Linux系统如何安装AutoFs挂载服务Linux系统如何安装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子目录中,而且光盘设备会被立即自动挂载上。我们也就能顺利查看光盘内的内容了。Linux就该这么学

[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  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linuxautofs是一个自动挂载文件系统服务。它可以根据需要自动挂载文件系统,而无需手动操作。在安装和配置完成后,可以使用systemctl命令来启动和启用autofs服务。例如,使用以下命令启动和启用autofs服务: \[root@service ~\]# systemctl start autofs \[root@service ~\]# systemctl enable autofs 启用服务后,可以使用systemctl status命令来检查autofs服务的状态。例如,使用以下命令检查autofs服务的状态: \[root@service ~\]# systemctl status autofs 安装autofs服务后,会生成一些配置文件和目录。例如,可以使用ls命令来查看生成的文件和目录: \[root@service ~\]# ls /etc/auto* /etc/autofs.conf /etc/auto.master /etc/auto.net /etc/autofs_ldap_auth.conf /etc/auto.misc /etc/auto.smb /etc/auto.master.d 如果需要手动挂载镜像文件并使用YUM方式安装autofs,可以使用mount命令来挂载镜像文件,并使用yum命令来安装autofs。例如,使用以下命令挂载镜像文件并安装autofs: \[root@service ~\]# mount /dev/sr0 /mnt/ \[root@service ~\]# yum install -y autofs 总结起来,autofs是一个自动挂载文件系统服务,可以通过systemctl命令启动和启用,安装后会生成一些配置文件和目录,可以使用mount命令手动挂载镜像文件并使用yum命令安装autofs。 #### 引用[.reference_title] - *1* *2* *3* [【Linuxautofs自动挂载](https://blog.csdn.net/tianlong1929/article/details/129678976)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值