天天看點

autofs rhel7

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個目錄,裡面的内容都是一樣的?

*           -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     #進入另一個目錄,有一模一樣的,。。。無語,就是一樣的,為什麼呢?

-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  classroom.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 ~]$

      本文轉自810105851 51CTO部落格,原文連結:http://blog.51cto.com/4708948/1695456,如需轉載請自行聯系原作者

上一篇: rhel7 samba
下一篇: LVM常用操作