NFS
出自DebianWiki
目錄 |
[編輯] 簡介
NFS(Network File System) 故名思意為網路檔案系統, 可透過網路將遠端或本地端的主機經由NFS掛載進檔案系統內。 多數現代的作業系統支援NFS的功能,除了MS Windows需購買UNIX Tools以外。
同時與Windows內的網路芳鄰除功能類似,在架構跟效能上差異頗大,勿以等號視之。
[編輯] NFS Server
在 debian 下要架設 NFS 伺服器必需安裝以下套件
apt-get install nfs-common nfs-kernel-server portmap
或 User space 的 NFS 伺服器
apt-get install nfs-user-server
接著修改 /etc/exports 以設定要分享的目錄
[root@test root]# nano /etc/exports
[欲分享的目錄] [主機名稱1或IP1(參數1,參數2)] [主機名稱2或IP2(參數3,參數4)]
/tmp *(rw,sync) /home/public 192.168.0.*(rw,sync) *(ro,sync) /home/public 192.168.0.0/24(rw,sync) *(ro,sync) /var 192.168.0.*(rw,async,no_root_squash) /tftpboot/GEEXBOX 192.168.0.0/16(rw,async,all_squash,anonuid=1000,anongid=1000)
設定好後可使用以下兩個方法之一來重新載入 /etc/exports 的設定 重新載入 /etc/exports
/usr/sbin/exportfs -ua --先把之前的設定移除 /usr/sbin/exportfs -a --再重新載入
重新啟動 NFS 伺服器
/etc/init.d/nfs-kernel-server restart
新板的portmap需要設定後才可開放服務
cat /etc/default/portmap By default listen on all interfaces OPTIONS="-i 127.0.0.1"
預設為本地端
[編輯] NFS Client
[編輯] 安裝所需套件
apt-get install nfs-common portmap
[編輯] 測試client與server的連結
showmount -e hostname(orIP)
[編輯] 手動掛載 NFS 目錄
首先在 Client 下建立目錄,例如你要把Server端分享的目錄掛載在 /mnt/nfs/share ,則要先建立此目錄︰
mkdir -p /mnt/nfs/share
接著手動將遠端目錄 mount 上去
mount -t nfs hostname(orIP):/directory /mnt/nfs/share
[編輯] 開機時自動掛載 NFS 目錄
如果要讓 NFS 在開機時自動掛載,必須在 /etc/fstab 中加入一行
hostname(orIP):/directory /mnt/nfs/share nfs rsize=8192,wsize=8192,timeo=14,intr
[編輯] 使用 autofs 掛載
autofs 可以在需要使用時再自動掛載,請先安裝 autofs 套件︰
apt-get install autofs
要掛載遠端機器 hostname 上的 /directory 目錄到您機器的 /mnt/nfs/share 掛載點,請將下列這一行加入到 auto.master 檔案中:
/mnt/nfs /etc/auto.nfs --timeout 60
接著增加下面這一行至 /etc/auto.nfs 檔案中:
share -rw,soft,intr,rsize=8192,wsize=8192 hostname:/directory
之後只要你嘗試進入 /mnt/nfs/share 目錄,autofs 即會自動幫你掛載該 nfs 目錄
[編輯] 除錯參考
當/etc/exports設定的權限,不符合client端的來源時,則會出現錯誤訊息如下
mount: hostname:/dir failed, reason given by server: Permission denied
然而必須注意的是,若在nfs server的/etc/hosts內有設定IP與hostname的對照
則nfs會先把來源IP轉換成hostname,再與/etc/exports內的設定作對照
若此時/etc/exports的設定使用IP而非hostname,則會產生無法匹配的情況
因此而出現,雖然來源IP在/etc/exports已正確設定,卻仍然發生Permission denied的怪異現象
解決方案是在/etc/exports內採用hostname,避免使用IP
[編輯] 參考資料
Linux NFS howto http://nfs.sourceforge.net/nfs-howto/
![[Main Page]](/upload/4/49/Debian_taiwan_out.png)