1、系統環境
查詢當前系統,安裝對應得版本得 nfs相關軟件;本文系統環境爲 Ubuntu 16.04 amd64
# lsb_release -a
2、NFS 服務器端
2.1 軟件安裝
2.1.1 deb安裝
直接 deb安裝
# dpkg -i *.deb
2.1.2 聯網安裝
# apt-get install nfs-kernel-server
3.2 服務配置
3.2.1 防火牆設置
若不需要 防火牆,可直接關閉防火牆
# ufw disable
3.2.2 NFS 配置
3.2.2.1 配置文件
修改配置,重啓服務
# vim /etc/exports
# /etc/init.d/nfs-kernel-server restart
## 或者不需要重啓服務,讓配置生效( exportfs -r),客戶端最好重新掛載
3.2.2.2 配置文件參數
/opt *(rw,async,fsid=0,no_root_squash,no_subtree_check)
參數 | 說明 |
---|---|
/opt | 共享目錄 |
rw | 可擦寫 (read-write) |
async | 數據會先暫存於內存當中,而非直接寫入硬盤 |
no_root_squash | 客戶端使用 NFS 文件系統的賬號若爲 root 時,系統該如何判斷這個賬號的身份?預設的情況下,客戶端 root 的身份會由 root_squash 的設定壓縮成 nfsnobody, 如此對服務器的系統會較有保障開放客戶端使用 root 身份來操作服務器的文件系統 |
no_subtree_check | 默認參數 |
備註 | 詳細參見 "man exports" |
3.2.3 服務基本操作
查看當前服務共享的目錄
# showmount -e
4、NFS 客戶端
4.1 軟件安裝
4.1.1 deb安裝
直接 deb安裝
# dpkg -i *.deb
4.1.2 聯網安裝
# apt-get install nfs-common
4.2 NFS客戶端掛載
# mount -t nfs {nfs_server_ip}:{share_path} {mount_path}
參數 | 說明 |
---|---|
nfs_server_ip | NFS 服務器IP |
share_path | NFS 服務器共享目錄 |
moun_path | NFS客戶端本地掛載目錄 |
4.3 NFS客戶端卸載
# umount {mount_path}