autofs自动挂载

     autofs是根据需要自动挂载,默认5分钟不使用自动卸载挂载点!nfs,smb,iso,sd*的挂载

环境:RHEL6.5/Centos6.5    172.24.0.25

01、安装autofs

       yum install -y autofs

       rpm  -ql  autofs | less   #查看配置文件位置 

 配置文件:

    /etc/auto.master   #主配置

    /etc/auto.misc       #挂载点配置样板

02、测试autofs

vim     /etc/auto.mvp

nfs       -fstype=nfs         172.24.0.24:/share      ###nfs 是挂载点  

vim    /etc/auto.master

/mvp   /etc/auto.mvp       ###加载配置文件  /mvp进入挂载点的路径

service autofs restart

[root@zabbix_proxy etc]# df
Filesystem     1K-blocks     Used Available Use% Mounted on
/dev/sda2       40254272 11193596  28651804  29% /
tmpfs             436668       72    436596   1% /dev/shm      ###未挂载
[root@zabbix_proxy etc]# cd /mvp/
[root@zabbix_proxy mvp]# ll
总用量 0
[root@zabbix_proxy mvp]# cd nfs                                                       ###进入挂载点,看到nfs共享的文件,切压制为nobody
[root@zabbix_proxy nfs]# ll
总用量 4
-rw-rw-rw-. 1 nobody nobody 3 12月 28 11:57 hello
[root@zabbix_proxy nfs]# df
Filesystem         1K-blocks     Used Available Use% Mounted on
/dev/sda2           40254272 11193592  28651808  29% /
tmpfs                 436668       72    436596   1% /dev/shm
172.24.0.24:/share  40051584 20146944  19497728  51% /mvp/nfs      ####显示已挂载
[root@zabbix_proxy nfs]# mkdir go
[root@zabbix_proxy nfs]# touch xiaobang
[root@zabbix_proxy nfs]# ll                                                               ###测试可以新建文件
总用量 8
drwxr-xr-x. 2 nobody nobody 4096 12月 28 12:04 go
-rw-rw-rw-. 1 nobody nobody    3 12月 28 11:57 hello
-rw-r--r--. 1 nobody nobody    0 12月 28 12:04 xiaobang

03、挂载时间等信息配置

/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                                       ###定义的空闲时间5min


###NFS服务端配置

环境:Centos6.5 172.24.0.24

yum install -y nfs-utils rpcbind         ###一般rpcbind都默认安装并开机自启动

vim /etc/exports

/openshare       172.24.0.0/16(rw,sync,all_squash)      ###rw,切压制为nobody, 可写  chmod -R  a+w /openshare

service nfs restart

exportfs         ###刷新nfs共享

showmount   ###查看共享列表

原文地址:https://www.cnblogs.com/xiaochina/p/6201824.html