Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> 電腦軟體教學 >> 伺服器技術 >> 關於伺服器

Linux NFS 伺服器完整配置指南:從 Server 端匯出到 Client 端掛載與自動化

編輯:關於伺服器

NFS 核心概念

網路檔案系統讓 Client 掛載 Server 目錄如同本地磁碟,嵌入式開發、叢集共享存儲、容器持久化卷常用。

Server 端配置

1. 安裝套件

yum install -y nfs-utils rpcbind  # CentOS/RHEL
apt install -y nfs-kernel-server  # Debian/Ubuntu

2. 編輯匯出表 /etc/exports

/share 192.168.0.0/24(rw,sync,no_root_squash)
/home/haiouc/haioucshare *(rw,sync,all_squash,anonuid=1000,anongid=1000)
/mnt/cdrom 192.168.0.*(ro)

關鍵選項:

  • rw/ro:讀寫/唯讀
  • sync/async:同步寫入/非同步(效能較好但風險高)
  • root_squash/no_root_squash:Root 用戶映射為匿名/保留 Root
  • all_squash:所有用戶映射為匿名
  • anonuid/anongid:指定匿名用戶 UID/GID

3. 啟動服務

systemctl enable --now rpcbind nfs-server
# 或傳統
service rpcbind start
service nfs start

Client 端掛載

1. 安裝客戶端工具

yum install -y nfs-utils

2. 手動掛載

mkdir -p /mnt/localshare
mount -t nfs 192.168.0.1:/share /mnt/localshare

3. 開機自動掛載 /etc/fstab

192.168.1.10:/home/haiouc/haioucshare /mnt/nfs1 nfs defaults 0 0

4. 常用查詢指令

showmount -e 192.168.0.1   # 查看 Server 匯出清單
rpcinfo -p 192.168.0.1     # 查看 RPC 服務

進階:Kerberos 安全掛載

mount -t nfs4 -o sec=krb5p 192.168.0.1:/share /mnt/localshare

需雙端配置 Kerberos KDC,提供加密傳輸與強認證。

故障排查清單

  1. Server 防火牆開放 111 (rpcbind)、2049 (nfs)、以及 mountd 隨機埠(建議固定 MOUNTD_PORT)
  2. Client 能 ping 通 Server
  3. rpcinfo -p 見到 nfs、mountd、status 服務
  4. SELinux/AppArmor 允許 nfs 匯出與掛載
  5. 掛載報 access denied → 檢查 /etc/exports IP/選項、exportfs -rv 重新匯出
Copyright © Windows教程網 All Rights Reserved