現象
遠程 NFS 掛載正常,但本機執行 `mount -t nfs localhost:/usr/sharefile /xx/xx` 報錯:
`mount.nfs: an incorrect mount option was specified`
原因分析
- NFS 服務端未導出該路徑:
檢查 `/etc/exports` 是否包含 `/usr/sharefile` 並允許 `localhost` (或 `127.0.0.1`) 訪問。
示例:`/usr/sharefile 127.0.0.1(rw,sync,no_root_squash)`
修改後執行 `exportfs -rv` 重新導出。
- 本機 NFS 客戶端服務未啟動:
`systemctl start rpcbind nfs-client.target` (CentOS 7+) 或 `service rpcbind start; service nfs start` (CentOS 6)。
- 參數格式錯誤:
`-t nfs` 可省略 (默認)。確保路徑無多餘空格:`localhost:/usr/sharefile` (冒號後無空格)。
- 防火牆/SELinux 阻擋:
臨時關閉測試:`systemctl stop firewalld; setenforce 0`。
永久放行:`firewall-cmd --permanent --add-service=nfs; firewall-cmd --permanent --add-service=rpc-bind; firewall-cmd --reload`。
SELinux 策略:`setsebool -P nfs_export_all_rw 1`。
- 權限問題 (題主提到):
若服務端導出時 `root_squash` (默認),本機 root 映射為 `nfsnobody`,無法訪問需 root 權限的文件。
解決:服務端 `/etc/exports` 加 `no_root_squash`,或調整文件權限允許 `nfsnobody` 讀寫。
調試步驟
# 1. 檢查服務端導出列表
showmount -e localhost
# 2. 掛載時加 verbose 參數看詳細錯誤
mount -v -t nfs localhost:/usr/sharefile /mnt/test
# 3. 檢查 RPC 通信
rpcinfo -p localhost
題主代碼中的異常輸出
最佳回答中出現 `` 疑為測試注入或誤粘貼,**非正常 mount 輸出**,請忽略。
總結
本機掛載 NFS 失敗多為 **服務端未導出/導出權限不足**、**客戶端服務未啟**、**防火牆/SELinux 攔截**。按順序排查:`showmount -e` → 服務狀態 → 防火牆/SELinux → `/etc/exports` 權限參數。