現在有兩台伺服器,需要實作檔案共享功能
伺服器1(server):10.10.2.153
伺服器2(client):10.10.1.103
1,軟體安裝:
兩台機器上均上安裝nfs軟體,sudo apt-get install nfs-kernel-server
2,兩台機器上均需呀設定共享路徑:
mkdir -p /www/upload
3,(server)建立服務對象:
vim /etc/exports
添加内容:/www/upload 10.10.1.103(rw,sync,no_subtree_check,no_root_squash)
表示隻有ip是10.10.1.103的能共享
4,重新整理服務對象:
exportfs -ra
5,(server)檢視服務端狀态
service nfs-kernel-server status
如果是not running 就輸入以下指令啟動
service nfs-kernel-server start
6,(server)檢視共享目錄:
showmount –e
7,用戶端(client)挂載解除安裝:
mount -t nfs 10.10.2.153:/www/upload
umount /www/upload
參數說明:
ro 隻讀通路
rw 讀寫通路
sync 所有資料在請求時寫入共享
async nfs在寫入資料前可以響應請求
secure nfs通過1024以下的安全tcp/ip端口發送
insecure nfs通過1024以上的端口發送
wdelay 如果多個使用者要寫入nfs目錄,則歸組寫入(預設)
no_wdelay 如果多個使用者要寫入nfs目錄,則立即寫入,當使用async時,無需此設定
hide 在nfs共享目錄中不共享其子目錄
no_hide 共享nfs目錄的子目錄
subtree_check 如果共享/usr/bin之類的子目錄時,強制nfs檢查父目錄的權限(預設)
no_subtree_check 不檢查父目錄權限
all_squash 共享檔案的uid和gid映射匿名使用者anonymous,适合公用目錄
no_all_squash 保留共享檔案的uid和gid(預設)
root_squash root使用者的所有請求映射成如anonymous使用者一樣的權限(預設)
no_root_squash root使用者具有根目錄的完全管理通路權限
anonuid=xxx 指定nfs伺服器/etc/passwd檔案中匿名使用者的uid
anongid=xxx 指定nfs伺服器/etc/passwd檔案中匿名使用者的gid