准备

Autofs是安装在客户端上的,客户端要用时自动挂载,5分钟不用自动卸载。

服务器端的配置请查看前面的文档

客户端配置

[root@localhost/]# yum -y install autofs

[root@localhost/]# vim /etc/auto.master   #主要autofs配置文件

写入:

/mnt/hr1        /etc/auto.hr1

/mnt/hr1这个目录不需要事先创建,因为autofs会主动创建

[root@localhost/]# cp /etc/auto.misc /etc/auto.hr1   #复制一个数据对应文件的挂载信息与服务器对应的资源

[root@localhost/]# vim /etc/auto.hr1

写入:

hrr1            -fstype=nfs,rw          192.168.222.1:/mnt/hr1

选项与参数:

hrr1                      指在/mnt/hr1(/etc/auto.master里的)目录的子目录

-fstype=nfs,rw           就是rw,bg,sofs等参数,可有可无

192.168.222.1:/mnt/hr1   服务器所提供的目录

[root@localhost/]# systemctl enable autofs

 [root@localhost /]# systemctl start autofs

 

测试

[root@localhost/]# ll -d /mnt/hr1/    #这样看不到挂载的目录的,autofs 是要用的时候才挂载

drwxr-xr-x.2 root root 0 9月  16 19:53 /mnt/hr1/   

[root@localhost/]# cd /mnt/hr1/hrr1  #这样就可以看到了,/mnt/hr1/hrr1这个目录自己打(要事先知道),看不出来的

[root@localhosthrr1]# df -TH

文件系统               类型      容量  已用  可用 已用% 挂载点

/dev/sda2              xfs        11G 3.1G  7.5G   29% /

devtmpfs               devtmpfs  949M    0  949M    0% /dev

tmpfs                  tmpfs     958M 144k  958M    1% /dev/shm

tmpfs                  tmpfs     958M 9.4M  949M    1% /run

tmpfs                  tmpfs     958M    0  958M    0% /sys/fs/cgroup

/dev/sda3              xfs       5.3G 136M  5.1G    3% /var

/dev/sda1              xfs       521M 107M  414M   21% /boot

/dev/sr0               iso9660   3.8G 3.8G     0  100% /mnt/iso

192.168.222.1:/mnt/hr1nfs4       19G  5.1G  14G   27% /mnt/hr1/hrr1

[root@localhosthrr1]#

问题

如果这里写成*号的话,要自己touch 名字,然后进入那个名字目录,才可以,但为什么新那了2个目录,里面的内容都是一样的?

[root@localhost/]# vim /etc/auto.hr1

写入:

*           -fstype=nfs,rw          192.168.222.1:/mnt/hr1

[root@localhost~]# df –TH    #首先可以看到是没有挂载的

Filesystem     Type     Size  Used Avail Use% Mounted on

/dev/sda2      xfs       11G  3.1G  7.5G 29% /

devtmpfs       devtmpfs 949M     0  949M  0% /dev

tmpfs          tmpfs     958M 144k  958M   1% /dev/shm

tmpfs          tmpfs     958M 9.4M  949M   1% /run

tmpfs          tmpfs     958M    0  958M   0% /sys/fs/cgroup

/dev/sda3      xfs      5.3G  136M  5.1G  3% /var

/dev/sda1      xfs      521M  107M  414M 21% /boot

/dev/sr0       iso9660    64M  64M     0 100%/run/media/root/VMware Tools

[root@localhost~]# cd /mnt/hr1   #然后进入挂载的目录

[root@localhosthr1]# ls

[root@localhosthr1]# touch a     #新建2个目录

[root@localhosthr1]# touch b

[root@localhosthr1]# mkdir aa    #用*时新建目录只能touch

mkdir:cannot create directory ‘aa’: Permission denied

[root@localhosthr1]# ll

total0

drwxrwxrwx.3 root root 42 Sep 16 23:33 a

drwxrwxrwx.3 root root 42 Sep 16 23:33 b

[root@localhosthr1]# df –TH    #然后就可以看到自动挂载了

Filesystem             Type      Size Used Avail Use% Mounted on

/dev/sda2              xfs        11G 3.1G  7.5G  29% /

devtmpfs               devtmpfs  949M    0  949M   0% /dev

tmpfs                  tmpfs     958M 144k  958M   1% /dev/shm

tmpfs                  tmpfs     958M 9.4M  949M   1% /run

tmpfs                  tmpfs     958M    0  958M   0% /sys/fs/cgroup

/dev/sda3              xfs       5.3G 136M  5.1G   3% /var

/dev/sda1              xfs       521M 107M  414M  21% /boot

/dev/sr0               iso9660    64M  64M     0 100%/run/media/root/VMware Tools

192.168.222.1:/mnt/hr1nfs4       19G  5.1G  14G  27% /mnt/hr1/a

[root@localhosthr1]# cd a

[root@localhosta]# touch aaa  #然后进入挂载目录,新建一个文件

[root@localhosta]# ls

aa1  aaa b  dd  f1

[root@localhosta]# cd ..

[root@localhosthr1]# cd b

[root@localhostb]# ll     #进入另一个目录,有一模一样的,。。。无语,就是一样的,为什么呢?

total0

-rw-r--r--.1 nfsnobody nfsnobody 0 Sep 16 19:33 aa1

-rw-r--r--.1 nfsnobody nfsnobody 0 Sep 16 23:33 aaa

-rw-r--r--.1 nfsnobody nfsnobody 0 Sep 16 22:57 b

drwxr-xr-x.2 nfsnobody nfsnobody 6 Sep 16 19:15 dd

-rw-r--r--.1 nfsnobody nfsnobody 0 Sep 16 19:15 f1

[root@localhostb]#


配置ldap用户配置autofs自动目录挂载


yum -y install autofs

cp /etc/auto.misc/etc/auto.ldap

vim /etc/auto.master

/home/guests /etc/auto.ldap

vim /etc/auto.ldap

*                -rw,sync  cla***oom.example.com:/home/guests/&

[root@server0 home]# systemctl restart autofs

[root@server0 home]# su - ldapuser0

Last login: Fri Oct  2 15:51:55 CST 2015 on pts/1

[ldapuser0@server0 ~]$ pwd

/home/guests/ldapuser0

[ldapuser0@server0 ~]$ touch a

[ldapuser0@server0 ~]$ ll

total 0

-rw-rw-r--. 1 ldapuser0 ldapuser0 0Oct  2 14:51 a

-rw-rw-r--. 1 ldapuser0 ldapuser0 0Oct  2 14:51 abc

[ldapuser0@server0 ~]$