歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux綜合 >> Linux資訊 >> 更多Linux >> 什麼是NFS文件系統

什麼是NFS文件系統

日期:2017/2/27 14:18:22   编辑:更多Linux
  ◎ What is NFS ? Network    File    System     NFS 是由SUN公司發展, 並於1984年推出, NFS是一個RPC service ,它使我們能夠達到檔案的共享, 它的設計是為了在不同的系統間使用, 所以它的通訊協定設計與主機及作業系統無關.當使用者想用遠端檔案時只要用"mount"就可把remote檔案系統掛接在自己的檔案系統之下,使得遠端的檔案使用上和local機器的檔案沒兩樣. machine A machine B / / bin etc usr bin etc usr man man share local 假如我們在機器A上, 要把機器B上的 /usr/man 掛接到machine A 的/usr/man只要下mount machine_name:/usr/man /usr/home 就可mount過來.而我們不只是可以mount目錄,就是一個檔也是可以的.在掛接之後我們只能對檔案做reading (or writing) 的動作,而不能在remote machie上把此檔或目錄move,delete掉 , 但須注意的是如我們mount /usr 後 , 不能再mount /usr底下的目錄, 否則會發生錯誤 □ Servers & Clients NFS就是促使Servers上的檔案能被其他的機器mount,而達到資源共享,享用這些檔案的機器就可稱為Client,一個client可以從server上mount一個檔或是一個層次的目錄(file hierarchies) . 然而事實上任何一台機器都可以做NFS server or NFS client ,甚至同時為NFS server and NFS client 也可以. □ Servers EXPorting & Clients Mounting NFS server 所export 出來的檔案或目錄都記錄在 /etc/exports 這一個檔中,當我們啟動NFS server 時 在 /etc/rc.local 的這一個script會自動的啟動 exportfs 這一個程式 , 搜尋 /etc/exports 這一個檔是否存在, 並且賦予正確的權限給所有export出去的 file hierarchies . 但須注意的是,只有server所export出去的路徑,NFS client才能夠mount, 同樣的當啟動client時 , 系統會自動去mount所有server export的路徑,而mount到的所有路徑都會記錄在 /etc/fstab 下 , 類似如下的fstab檔 /dev/sd0a / 4.2 rw 1 1 /dev/sd0h /tmp 4.2 rw 1 3 /dev/sd0g /usr 4.2 rw 1 2 /dev/fd0 /pcfs pcfs rw,noauto 0 0 sparc20:/swap /swap nfs rw,intr,bg,soft 0 0 sparc17:/home /home nfs rw,intr,bg,soft 0 0 sparc17:/home3 /home3 nfs rw,intr,bg,soft 0 0 sparc14:/home4 /home4 nfs rw,intr,bg,soft 0 0 sparc20:/home2 /home2 nfs rw,intr,bg,soft 0 0 sparc20:/var/spool/mail /var/spool/mail nfs rw,intr,bg,soft 0 0 rs970:/home1 /home1 nfs rw,intr,bg,soft 0 0 ★ Noted : 當client mount 到一個路徑,絕對不是說copy server上的這一個路徑到local的機器上,我們可以用 cd 進入這一個mount到的路徑,就如同是使用local Directory一樣 □ Setting Up a NFS Server 1. 定義機器為 NFS file server 2. 劃分servers disk ,定義哪一些partitions 是要提供出來作為 client 所共享的file system 3. 在 Client Form 上定義每一台client 的參數 4. 寫出 /etc/exports (一般系統都有一個default exports) 5. 重新boot NFS server or 用指令 exportfs -a 輸出所有的directories 並且用 nfsd 8 & 啟動 nfsd守護程式,常駐在背景 ※ ps. 一些細節 檢查 /etc/exports 輸出路徑的權限,確定只有root能修改, all user只能read 2. 用exportfs 去增加或刪除directories exportfs -o Access=engineering,ro=dancer /usr


exportfs -u /usr 3. 假如你的機器沒有NIS(YP server)的服務,當更改資料時記得修改 /etc/passwd /etc/group /etc/hosts /etc/ethers 4. 為你自己的network 設置security exportfs的語法 /usr/etc/exportfs [ -avu ] [ -o option ] [ directory ] -a : 把 /etc/exports 中所有路徑export出去 -u : 把 export出去的路徑卸下 , 如 exportfs -u /usr -o option : 如 exportfs -o ro /usr ,所有人對/usr 都為read only option 還有 root = hostname , access = client access = netgroup For example : exportfs -a 把exports中的路徑全部export出去 exportfs -o access=engineering:other /usr /usr 這路徑export後只有engineering and other 這兩個 group 能夠 read & write exportfs -o access=oak,ro=dancer /usr 設定dancer 這台client 對 /usr 為read only ,且只有oak這一個 group 能做read /etc/exports 檔的□例 ● syntax : directory -option[,option] (設定兩個group能rw) /usr -access=engineering:accounting /home -access=engineering:accounting /var/spool/mail -access=engineering:accounting /export/exec/sun3 -access=engineering:accounting /export/exec/sun3.sunos.4.1 -access=engineering:accounting /export/exec/kvm/sun3.sunos.4.1 -access=engineering:accounting /export/root/birch -access=birch,root=birch /export/swap/birch -access=birch,root=birch /export/root/oak -access=oak,root=oak /export/swap/oak -access=oak,root=oak /export/root/willow -access=willow,root=willow /export/swap/willow -access=willow,root=willow /export/root/pine -accsee=pine,root=pine /export/swap/pine -accsee=pine,root=pine (access=client , root=hostname 如此只有這一台client的superuser有權力rw) □ Setting Up a NFS Client 1. 宣告機器為沒有磁碟機或沒有資料的Client,在使用SunInstall之前 2. 編輯好 /etc/fstab 這一個檔,確定要mount的路徑都在fstab中 3. 依照fstab所設的內容,在Client上設定好Mount points (mount_points 就是用mkdir 設exports所輸出的路徑) 4. 確定我們所要mount的路徑,都有出現在 /etc/exports 中 5. 可以啟動mount去連結server上的directories ( mount -a ) /etc/fstab 檔的□例 ● syntax filesystem directory type options freq pass oak:/export/root/boomer / nfs rw 0 0 ^^^ 因為檔案在server上,not on client 所以client的設定為0 oak:/export/exec/sun3 /usr nfs ro 0 0 oak:/export/exec/kvm/sun3 /usr/kvm nfs ro 0 0 oak:/usr/share /usr/share nfs ro 0 0 oak:/home/oak /home/oak nfs rw,bg 0 0 § mount 的語法 ● syntax : mount -t type [-rv] -o [option] server:pathname /mount_point MOUNT : mount -a 把/etc/fstab 中所列的路徑全部掛上 mount -o ro,soft,bg dancer:/usr/local /usr/local/dancer 把dancer server 的/usr/local mount 到 client的 /usr/local/dancer 並且是read only

-t type : 你所要mount的型別, 如 nfs or 4.2 -r : 所mount的路徑定為read only -v : mount過程的每一個動作,都有messages 傳回到螢幕上 hard : 重復要求,直到server回應為止,但如server一直不回應 the server may be down ! soft : 當client的請求得不到回應,retry one time 後 傳回 error message bg : 當第一次請求不成功,第二次的mount將放到背景執行 fg : retries mount 都一直在提示符號下進行 intr : 當正在進行 NFS 請求時,允許用鍵盤中斷 mount 成功時的message NFS server hostname ok hard mount fail NFS server hostname not responding, still trying soft . . .hostname server not reponding: RPC: Timed out § UNMOUNT : umount mount_point umount -a 卸下所有已經mount上的路徑 ◎ How NFS Work ? 當我們啟動 NFS file server 時,/etc/rc.local 會自動啟動exportfs這一個程式,指定可以export的檔案或目錄,而我們所能mount的也只能是其所指定的目錄. □ NFS 架設在 XDR/RPC的協定之上 XDR : (eXternal Data Representation) 外部資料表示法 XDR(eXternal Data Representation) 提供一種方法把資料從一種格式轉換成另一種標准資料格式表示法,確保在不同的電腦,作業系統及電腦語言中,所有資料代表的意義都是相同的 RPC : (Remote Procedure Calls) 遠端程序呼叫 RPC(Remote Procedure Calls) 遠端程序呼叫, 請求遠端電腦給予服務. 委托器(client)就會透過網路傳送RPC到遠端電腦,請求服務. (一般 local machine : client remote machine : server ) □ NFS 如何運用 RPC 傳送資料 客戶端process 主服務端process ┌————┐ ┌—————┐ │ 客戶端 │ │ 主服務站 │ │routines│ │ routines │ │routines│ │ routines │
Copyright © Linux教程網 All Rights Reserved