Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Ubuntu 上安裝與設定 NFS 服務

一、安裝

apt-get install nfs-kernel-server

二、設定 /etc/exports

/rootfs *(rw,sync,no_root_squash)

/rootfs 是共享目錄;* 代表允許所有網段存取;rw 表示可讀寫;sync 表示資料同步寫入記憶體與硬碟;no_root_squash 則是說,若客戶端使用 root 使用者,對這個共享目錄也會擁有 root 權限。

其他常用參數:

ro 唯讀、rw 讀寫、sync 請求時同步寫入、async 寫入前先回應請求、secure 透過 1024 以下端口傳送、insecure 透過 1024 以上端口傳送、wdelay 多使用者寫入時歸組處理(預設)、no_wdelay 立即寫入(搭配 async 時不需設定)、hide 不共享子目錄、no_hide 共享子目錄、subtree_check 檢查父目錄權限(預設)、no_subtree_check 不檢查父目錄權限、all_squash 把 UID/GID 映射為匿名使用者(適合公用目錄)、no_all_squash 保留 UID/GID(預設)、root_squash 把 root 請求映射為匿名權限(預設)、no_root_squash 保留 root 完整權限、anonuid=xxx 指定匿名使用者 UID、anongid=xxx 指定匿名使用者 GID。

三、重啟服務

$ sudo /etc/init.d/portmap restart
$ sudo /etc/init.d/nfs-kernel-server restart

四、測試

$ showmount -e

也可以掛載到本機目錄測試,例如把 /rootfs 掛到 /mnt:

$ sudo mount -t nfs localhost:/rootfs /mnt

用 df 指令確認是否掛載成功,測試完畢後卸載:

$ sudo umount /mnt

實務上要提醒一句:no_root_squash 等於把 root 權限開放給客戶端,只適合在完全可信的內部網路使用,對外環境請改用 root_squash 並搭配 anonuid/anongid 收斂權限。

Copyright © Linux教程網 All Rights Reserved