天天看點

NFS伺服器配置及用戶端挂載

 NFS(網絡檔案系統)是linux作業系統下的一種特殊的檔案系統,使用這一檔案系統,目前主機可以加載其他提供NFS服務的linux主機,這種

方式可以便捷的實作linux主機之間檔案的互相通路。NFS檔案系統僅占用系統挂載點,NFS用戶端使用者的PC将網絡遠端的NFS主機分享的目錄挂載到本地計

算機中,可以運作相應的程式,共享應用的檔案,但不占用目前的系統資源。

将NFS伺服器的共享檔案夾挂載到用戶端,使用協定RPC(遠端程序排程)

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408434jXpY.png"></a>

NFS使用rpc

1.當伺服器端的nfs和rpc 服務 啟動後會形成很多程序:mountd ,nfs,nlockmgr,status程序。

2. 用戶端有rpc.mountd ,rpciod , nlockmgr,status程序。

3.用戶端需要挂載伺服器端的檔案,使用rpc.mountd程序項伺服器的portmapper 發送請求連接配接。

4.伺服器端的portmapper 收到請求後,向用戶端回應,同時告訴用戶端使用哪個端口與伺服器相連。

5.用戶端使用rpc.mountd 請求伺服器端程序mountd,進行挂載。

6.挂載完畢後,用戶端使用程序rpciod 調用服務端的nfs程序,進行磁盤io操作。

7.兩端都調用nlockmgr鎖機制,當伺服器端在編寫文檔時,禁止用戶端的通路。

8. 為了維持連接配接,兩端都使用status程序。

linux主機伺服器端配置:

[root@lyt ~]# rpm -qa |grep nfs     #檢視nfs的服務是否安裝

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_13484084528vzb.png"></a>

[root@lyt ~]# rpm -ql nfs-utils |less      #分頁檢視nfs-utils軟體包

[root@lyt ~]# rpcinfo –p #檢視本地rpc程序

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408460H9Lz.png"></a>

[root@lyt ~]# rpcinfo -p 192.168.101.36 #檢視192.168.101.36的rpc程序

[root@lyt ~]# service nfs start #啟動nfs服務

[root@lyt ~]# chkconfig nfs on #設定開機自動啟動

[root@lyt ~]# mkdir /public      #建立一個目錄public

[root@lyt ~]# vim /etc/exports       #編輯共享清單exports,該檔案預設是空檔案

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408464L6zZ.png"></a>

[root@lyt ~]# cd /public/

[root@lyt public]# touch p1      #建立一個檔案p1,使用者在用戶端上的測試

[root@lyt ~]#  exportfs –rv       #将設定共享的檔案導出

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408469e2zk.png"></a>

linux主機用戶端配置臨時挂載:

[root@localhost ~]# rpcinfo –p      #檢視本地rpc程序

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408471DLjn.png"></a>

[root@localhost ~]# showmount -e 192.168.101.66     #測試是否具有權限檢視192.168.101.66伺服器上的共享檔案

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408473PrWR.png"></a>

[root@localhost ~]# mkdir /mnt/nfs       #建立一個挂載點nfs

[root@localhost ~]# mount 192.168.101.66:/public /mnt/nfs/      #将伺服器上的共享檔案臨時挂載到本地的挂載點/mnt/nfs上

[root@localhost ~]#  cd /mnt/nfs/      #切換到挂載點

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408476Jcy7.png"></a>

linux主機用戶端配置開機自動挂載:

[root@localhost nfs]# fuser -km /mnt/nfs/      #強制解除安裝,執行完後,再次使用umount  /mnt/nfs進行解除安裝

[root@localhost nfs]# umount /mnt/nfs/         #如果還是不能解除安裝則可以重新開機系統即可

[root@localhost nfs]# vim /etc/fstab      #編輯開機自動挂載檔案

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408485sYOn.png"></a>

[root@localhost nfs]# mount -a

linux主機用戶端配置連接配接自動挂載:

[root@localhost nfs]# umount /mnt/nfs/       #将上一步驟中的開機自動挂載解除安裝掉

[root@localhost nfs]# rpm -qa |grep auto      #檢視與自動挂載相關的軟體包auto

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408487djHS.png"></a>

[root@localhost nfs]# vim /etc/auto.master       #編輯與自動挂載相關的配置檔案

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408490N1Eh.png"></a>

[root@localhost nfs]# cp -p /etc/auto.misc /etc/auto.nfs       #産生auto.nfs檔案

[root@localhost nfs]# vim /etc/auto.nfs       #編輯該檔案

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408492BW81.png"></a>

[root@localhost nfs]# service autofs restart      #重新開機autofs服務

[root@localhost nfs]# mount      #檢視挂載的目錄

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408495fQE9.png"></a>

[root@localhost nfs]# cd server1   #其實在/mnt/nfs下并沒有server1目錄,強制切換到server1中後,會自動産生該目錄,此時已經将伺服器上的

共享檔案挂載到了用戶端

[root@localhost server1]# mount      #使用mount檢視是否挂載成功

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_13484085049wGl.png"></a>

[root@localhost server1]# cd      #離開server1目錄

[root@localhost ~]# mount       #離開一份分鐘後再次檢視挂載情況,此時server1目錄也不存在了

<a href="http://5493845.blog.51cto.com/attachment/201209/23/5493845_1348408508coid.png"></a>

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

繼續閱讀