NFS安装使用
服务端
安装 nfs-kernel-server
apt install nfs-kernel-server
创建共享目录
sudo mkdir -p /opt/nfs/share 
sudo chmod 666 /opt/nfs/share
修改 NFS 配置
sudo vim /etc/exports
内容如下:
/opt/nfs/share *(rw,sync,insecure,no_subtree_check,no_wdelay,no_root_squash)
指定ip地址的主机:192.168.0.200
指定子网中的所有主机:192.168.0.0/24 192.168.0.0/255.255.255.0
所有主机:*
| 参数 | 说明 | 
|---|---|
| ro | 只读 | 
| rw | 读写 | 
| sync | 所有数据在请求时写入共享 | 
| async | nfs 在写入数据前可以响应请求 | 
| secure | nfs 通过 1024 以下的安全 TCP/IP 端口发送 | 
| insecure | nfs 通过 1024 以上的端口发送 | 
| wdelay | 如果多个用户要写入 nfs 目录,则归组写入(默认) | 
| no_wdelay | 如果多个用户要写入 nfs 目录,则立即写入,当使用 async 时,无需此设置 | 
| hide | 在 nfs 共享目录中不共享其子目录 | 
| no_hide | 共享 nfs 目录的子目录 | 
| subtree_check | 如果共享 /usr/bin 之类的子目录时,强制 nfs 检查父目录的权限(默认) | 
| all_squash | 共享文件的 UID 和 GID 映射匿名用户 anonymous,适合公用目录 | 
| no_all_squash | 保留共享文件的 UID 和 GID(默认) | 
| root_squash | root 用户的所有请求映射成如 anonymous 用户一样的权限(默认) | 
| no_root_squash | root 用户具有根目录的完全管理访问权限 | 
| anonuid=xxx | 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 UID | 
| anongid=xxx | 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 GID | 
启动 RPC 服务
sudo service rpcbind start
启动 NFS 服务
sudo service nfs-kernel-server start
查看挂载目录
showmount -e localhost
新建挂载目录
sudo echo "/home/nfs *(rw,async,no_root_squash)" >> /etc/exports
sudo exportfs -r
showmount -e localhost
客户端
安装 nfs-common
sudo apt install nfs-common
查看挂载目录
showmount -e 192.168.0.166
远程挂载
mkdir -p /share
mount 192.168.0.166:/opt/nfs/share /share -o proto=tcp -o nolock

                
            
浙公网安备 33010602011771号