# CentOS/RHEL yum install nfs-utils rpcbind -y # Debian/Ubuntu apt-get install nfs-kernel-server -y
systemctl enable --now rpcbind nfs-server # 或舊版 service rpcbind start service nfs start
netstat -ntpl | grep -E '(111|2049)' # 111: rpcbind (portmapper) # 2049: nfsd
/etc/exports/home/temp *(ro,sync,no_root_squash,all_squash) /mnt/inst *(ro,sync)
格式:<共享路徑> <允許客戶端>(<選項>)
| 選項 | 說明 |
|---|---|
| rw / ro | 讀寫 / 唯讀 |
| sync / async | 同步寫入磁碟 / 非同步(效能較好但掉電風險) |
| no_root_squash | 客戶端 root 保持 root 權限(不安全,慎用) |
| root_squash (預設) | 客戶端 root 映射為匿名用戶 (nfsnobody) |
| all_squash | 所有用戶映射為匿名用戶 |
| anonuid=XXX / anongid=XXX | 指定匿名用戶 UID/GID |
| insecure | 允許非保留埠口(>1024)發起請求 |
exportfs -arv # -a 全部、-r 重新匯出、-v 詳細輸出
showmount -e 127.0.0.1 # 或 exportfs -v
yum install nfs-utils -y # 含 mount.nfs apt-get install nfs-common -y
# 臨時掛載 mount -t nfs 192.168.111.1:/mnt/inst /mnt # 開機自動掛載 (/etc/fstab) 192.168.111.1:/mnt/inst /mnt nfs defaults,_netdev 0 0
mount | grep nfs df -h /mnt ls /mnt
firewall-cmd --add-service=nfs --permanentsetsebool -P nfs_export_all_rw 1 或設定正確 contextrsize=1048576,wsize=1048576,hard,intr,timeo=600/etc/sysconfig/nfs 調整 RPCNFSDCOUNT(執行緒數)