linux autofs自動掛載


autofs:自動掛載器
自動掛載器是一個監視目錄的守護進程,並在目標子目錄被引用時,自動執行預定義的NFS掛載
自動掛載器由autofs服務腳本管理
自動掛載器由auto.master配置文件進行配置,該文件引用了一個按慣例稱作/etc/auto.misc或其他類似名稱的二級配置文件
autofs與NFS兩者之間配后用的還是比較多的
 
mount命令參數非常多,如下為與NFS相關的參數。
(1)-a:把/etc/fstab中列出的路徑全部掛載。
(2)-t:需要mount的類型,如nfs等。
(3)-r:將mount的路徑定為read only。
(4)-v mount:過程的每一個操作都有message傳回到屏幕上。
(5)rsize=n:在NFS服務器讀取文件時NFS使用的字節數,默認值是1 024個字節。
(6)wsize=n:向NFS服務器寫文件時NFS使用的字節數,默認值是1 024個字節。
(7)timeo=n:從超時后到第1次重新傳送占用的1/7秒的數目,默認值是7/7秒。
(8)retry=n:在放棄后台mount操作之前可以嘗試的次數,默認值是7 000次。
(9)soft:使用軟掛載的方式掛載系統,若Client的請求得不到回應,則重新請求並傳回錯誤信息。
(10)hard:使用硬掛載的方式掛載系統,該值是默認值,重復請求直到NFS服務器回應。
(11)intr:允許NFS中斷文件操作和向調用它的程序返回值,默認不允許文件操作被中斷。
(12)fg:一直在提示符下執行重復掛載。
(13)bg:如果第1次掛載文件系統失敗,繼續在后台嘗試執行掛載,默認值是失敗后不在后台處理。
(14)tcp:對文件系統的掛載使用TCP,而不是默認的UDP。
說明:mount NFS服務器的另一個重要參數是hard(硬)mount或soft(軟)mount。
 
采用hard mount,NFS客戶機會不斷地嘗試與NFS服務器連接(在后台一般不會給出任何提示信息),直到掛載上為止。
采用soft mount,會在前台嘗試與NFS服務器連接,當收到錯誤信息后終止mount嘗試,並給出相關信息。
 
######################簡單配置###########################
1、掛載本地分區

 

安裝 yum -y install autofs


[root@pts/0 ~]# rpm -qa autofs
autofs-5.0.1-0.rc2.143.el5
[root@pts/0 ~]#
 
[root@pts/0 ~]# grep -v '^#' /etc/auto.master
/misc  /etc/auto.misc         #/misc是定義的自動mount的掛載點,/etc/auto.misc里定義了mount的動作

/home  /etc/auto.home         #/home是定義的自動mount的掛載點;/etc/auto.home定義了mount的動作,

                                  #此文件系統默認不存在,需要我們手工創建。
/net    -hosts
+auto.master
[root@pts/0 ~]# grep -v '^#' /etc/auto.misc
 
cd              -fstype=iso9660,ro,nosuid,nodev :/dev/cdrom
#cd為目標目錄名稱    中間段則為掛載選項    最后是掛載目錄
[root@pts/0 ~]#
 
[root@pts/0 misc]# ls
[root@pts/0 misc]# grep sda4 /etc/auto.master
/misc/sda4      /etc/auto.sda   --timeout=60
[root@pts/0 misc]# grep sda4 /etc/auto.sda
sda4    -fstype=ext3    :/dev/sda4
[root@pts/0 misc]# service autofs start    //啟動服務
啟動automount:                                           [確定]
[root@pts/0 misc]# ls           //神奇目錄自動出現
sda4
[root@pts/0 misc]# cd sda4/
[root@pts/0 sda4]# ls         //進入之后還是什么都沒有
[root@pts/0 sda4]# cd sda4    //直接cd sda4,神奇的一刻到了,竟然進去了
[root@pts/0 sda4]# pwd
/misc/sda4/sda4
[root@pts/0 sda4]# ls
lost+found
[root@pts/0 sda4]# mount | grep sda4   //mount顯示掛載成功
/dev/sda4 on /misc/sda4/sda4 type ext3 (rw)
[root@pts/0 sda4]#
 
 
2、掛載NFS共享目錄
[root@pts/0 ~]# cat /etc/exports
/tmp    192.168.0.0/24(rw)
[root@pts/0 ~]# service nfs restart
關閉NFS mountd:                                          [失敗]
關閉NFS 守護進程:                                        [失敗]
關閉NFS quotas:                                          [失敗]
關閉NFS 服務:                                            [失敗]
啟動NFS 服務:                                            [確定]
關掉NFS 配額:                                            [確定]
啟動NFS 守護進程:                                        [確定]
啟動NFS mountd:                                          [確定]
[root@pts/0 ~]# showmount -e 127.0.0.1  
Export list for 127.0.0.1:
/tmp 192.168.0.0/24
[root@pts/0 ~]# vi /etc/auto.master
[root@pts/0 ~]# grep tmp /etc/auto.master
/misc/tmp       /etc/auto.nfs
[root@pts/0 ~]# vi /etc/auto.nfs
[root@pts/0 tmp]# grep tmp /etc/auto.nfs
tmp     -typefs=nfs,rw  127.0.0.1:/tmp  
#這里是本地測試,遠程測試的話把IP地址修改為遠程NFS服務端即可
[root@pts/0 ~]# service autofs  restart
停止automount:                                           [確定]
啟動automount:                                           [確定]
[root@pts/0 ~]# cd /misc/tmp/tmp
[root@pts/0 tmp]# ls
gconfd-root   scim-panel-socket:0-root  whatis.Qs3891
mapping-root  setuplog.txt
[root@pts/0 tmp]#
 
3、掛載samba
掛載samba這里就不作演示了,除了在auto.master中加入之前類似語句,再建立一個auto.smb的文件,填入:
windows    -fstype=smbfs,username=admin%password ://hostname/ShareFolder
即可
 
4、掛載本地鏡像
[root@pts/0 ~]# grep iso /etc/auto.master
/misc/iso       /etc/auto.iso
[root@pts/0 ~]# cat /etc/auto.iso
iso             -fstype=iso9660,ro,nosuid,nodev,loop    :/root/rhel5u5.iso
[root@pts/0 ~]# service autofs restart
停止automount:                                           [確定]
啟動automount:                                           [確定]
[root@pts/0 ~]# cd /misc/
[root@pts/0 misc]# ls
iso
[root@pts/0 misc]# cd iso/
[root@pts/0 iso]# ls
[root@pts/0 iso]# cd iso
[root@pts/0 iso]# ls
Cluster            README-te.html            RELEASE-NOTES-U5-en
ClusterStorage     README-zh_CN.html         RELEASE-NOTES-U5-en.html
EULA               README-zh_TW.html         RELEASE-NOTES-U5-es.html
eula.en_US         RELEASE-NOTES-as.html     RELEASE-NOTES-U5-fr.html
GPL                RELEASE-NOTES-bn.html     RELEASE-NOTES-U5-gu.html
------省略------
[root@pts/0 iso]# mount | grep rhel5u5.iso
/root/rhel5u5.iso on /misc/iso/iso type iso9660 (ro,nosuid,nodev,loop=/dev/loop1)
[root@pts/0 iso]#
 
autofs如此便可以結合yum安裝軟件了,不安裝的時候就不掛載,安裝軟件的時候就自動去掛載
[root@pts/0 mnt]# tail -5 /etc/yum.repos.d/rhel-debuginfo.repo
[repo]
name=repo
baseurl=file:///misc/iso/iso/Server
enabled=1
gpgcheck=0
[root@pts/0 mnt]# yum clean all
Loaded plugins: rhnplugin, security
Cleaning up Everything
[root@pts/0 mnt]# yum list
Loaded plugins: rhnplugin, security
This system is not registered with RHN.
RHN support will be disabled.
repo                                                     | 1.3 kB     00:00
repo/primary                                             | 753 kB     00:00
repo                                                                  2348/2348
------省略------
 
 
#####################################

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM