您的位置:首页 > 运维架构 > Linux

AutoFs自动挂载服务

2017-12-08 16:00 357 查看
刚刚创建了NFS的服务,发现客户端通过网络把共享文件挂载在本地文件来访问共享文档,所以需要把挂载信息写入到/etc/fstab中,这样远程共享资源就会随着服务器开机而进行自动挂载。 虽然很方便,但是也会有些问题: 1,如果挂载的远程资源太多,则会给网络和服务器的硬件资源带来很大的负担。 2,如果资源挂载后长期不使用,也会造成服务器硬件资源的浪费。 3,每次使用前mount自动挂载,很麻烦。 那有没有什么服务可以实现,只有在使用的时候自动挂载资源?autofs可以。 autofs服务程序是linux系统守护进程,当检测到用户试图访问一个尚未挂载的文件系统时候,将自动挂载该文件系统,这样就能节约了网络资源和服务器的硬件资源。 这次实验环境为Redhat 7.0 已经搭建yum。 配置AutoFs服务过程:1 ,安装AutoFs服务,绿色字体部分为添加部分。[root@localhost ~]# yum install autofs2,配置autofs文件[root@localhost etc]# vi 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).#/mnt /etc/auto.nfs 添加此行内容 /mnt 为进入客户端挂载点 的路径 auto.fs是子配置文件。/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 3配置子配置文件,[root@localhost ~]# vi /etc/auto.nfs nfsfile 192.168.245.129:/nfsfile 4重启autofs服务。[root@localhost ~]# systemctl restart autofs测试。通过[root@localhost ~]# cd /mnt/nfsfile这个动作可以看到已经连接上nfs资源,挂载点为/mnt/nfsfile.![](http://i2.51cto.com/images/blog/201712/08/13bca5b564bbb2618352e30b56ed9c11.png?x-oss-process=image/watermark,size_16,text_QDUxQ1RP5Y2a5a6i,color_FFFFFF,t_100,g_se,x_10,y_10,shadow_90,type_ZmFuZ3poZW5naGVpdGk=)PS: 1,挂载时间信息配置。默认挂载时间是300秒,可以修改。```/etc/sysconfig/autofs
#MASTER_MAP_NAME="auto.master" ###主配置文件auto.master# # TIMEOUT - set the default mount timeout in secons. The internal# program default is 10 minutes, but the default installed# configuration overrides this and sets the timeout to 5# minutes to be consistent with earlier autofs releases.#TIMEOUT=300 ###定义的空闲时间300秒,```2 遇到一个问题有知道的大神请帮忙当配置auto.master文件,挂载路径设置为根目录时候,如下:/ /etc/auto.nfs尝试访问的时候,无法自动挂载,是咋回事?
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux 自动挂载