nfs(網絡文件系統)簡單應用

nfs

網絡文件系統(英語:Network File System,縮寫為NFS)是一種分布式文件系統協議,最初由Sun Microsystems公司開發,并于1984[1]
年發布。其功能旨在允許客戶端主機可以像訪問本地存儲一樣通過網絡訪問服務器端文件。 NFS和其他許多協議一樣,是基于開放網絡運算遠程過程調用(ONC RPC) 協議之上的。

RPC的工作機制

NFS場景描述

  1. 服務端實現 NFS 守護進程, 默認運行 nfsd, 用來使得數據可以被客戶端訪問.

  2. 服務端系統管理員可以決定哪些資源可以被訪問, 導出目錄的名字和參數, 通常使用 /etc/exports配置文件和exportfs命令。

  3. 服務端 安全-管理員 保證它可以組織和認證合法的客戶端.

  4. 服務端網絡配置保證可以跟客戶端透過 防火墻 進行協商.

  5. 客戶端請求導出的數據, 通常調用一個 mount
    命令. (The client asks the server (rpcbind) which port the NFS server is using, the client connects to the NFS server (nfsd), nfsd passes the request to mountd)

  6. 如果一切順利, 客戶端的用戶就可以通過已經掛載的 文件系統 查看和訪問服務端的文件了.

  7. NFS網絡文件系統一般用來存儲共享附件等靜態資源文件,一般是把網站用戶上傳的文件都放到NFS共享里.

讓我們用一個一個示例,更詳細地說明NFS部署細節吧!(暫時關閉iptables selinux等)
1. NFS環境
NFS-Server: 172.18.20.96(CentOS7.2)
NFS-Client: 172.18.20.69(CentOS7.2)

Server端配置

2. 安裝相關軟件包
[root@thinkpad ~]#yum -y install rpcbind nfs-utils   # CentOS6以后用rpcbind 取代了portmapper,謹慎的話可以再測試軟件是否正確安裝
3. 創建共享目錄
[root@thinkpad ~]#mkdir -p /data/nfs_storage
[root@thinkpad ~]#chmod 755 /data/nfs_storage/     # 這個應該默認就是755權限
4. 導出共享目錄設置
[root@thinkpad ~]# vi /etc/exports 
[root@thinkpad ~]# cat /etc/exports 
/data/nfs_storage 172.18.20.69/24(rw,sync,no_root_squash,no_all_squash)
5. 啟動rpcbind nfs服務,[設置其為開機自啟]
[root@thinkpad ~]#systemctl start rpcbind.service
[root@thinkpad ~]#systemctl start nfs-server.service
[root@thinkpad ~]#[systemctl enable rpcbind.service]
[root@thinkpad ~]#[systemctl enable nfs-server.service]
ss -lntu     # 

Client端配置

6. 安裝rpcbind nfs-utils軟件包
yum -y install rpcbind nfs-utils
[root@thinkpad ~]# systemctl enable rpcbind
[root@thinkpad ~]# systemctl start rpcbind
[root@thinkpad ~]# systemctl start nfs 
7. 創建掛載目錄
[root@thinkpad ~]# mkdir -pv /data/nfs_shared
8. 查看Server端的exports 列表內容,如下圖
[root@thinkpad ~]#showmount -e 172.18.20.96
查看Server端export列表內容
9. 掛載NFS-Server
[root@thinkpad ~]# mount -t nfs 172.18.20.96:/data/nfs_storage /data/nfs_shared
[root@thinkpad ~]#mount    # 查看是否掛載成功

此時即可在Client端像訪問本地存儲設備一樣訪問Server端的指定目錄里的內容了.

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容