在 Debian 上挂载 NFS(Network File System)一般分为服务端和客户端两部分。下面分别说明。
sudo apt update
sudo apt install nfs-kernel-server
sudo mkdir -p /srv/nfs/share
sudo chown nobody:nogroup /srv/nfs/share
编辑配置文件:
sudo nano /etc/exports
示例(允许 192.168.1.0/24 网段访问):
/srv/nfs/share 192.168.1.0/24(rw,sync,no_subtree_check)
常用参数说明:
rw:读写ro:只读sync:同步写入no_root_squash:允许 root(不安全,谨慎用)no_subtree_check:提高性能sudo exportfs -a
sudo systemctl restart nfs-kernel-server
sudo apt update
sudo apt install nfs-common
sudo mkdir -p /mnt/nfs
sudo mount -t nfs 192.168.1.100:/srv/nfs/share /mnt/nfs
测试:
df -h
ls /mnt/nfs
编辑:
sudo nano /etc/fstab
添加一行:
192.168.1.100:/srv/nfs/share /mnt/nfs nfs defaults 0 0
可选参数(网络环境):
nfs defaults,timeo=30,retry=10,noauto,x-systemd.automount
使用
noauto,x-systemd.automount可避免开机因网络未就绪导致挂载失败。
showmount -e 192.168.1.100
sudo ufw allow from 192.168.1.0/24 to any port nfs
/etc/exports 允许范围如果你需要 Debian 到 Debian / Debian 到 NAS / Kubernetes NFS 挂载 等具体场景,也可以告诉我。