安装 NFS 软件包
apt-get install nfs-kernel-server // 安装 NFS服务器端
sudo apt-get install nfs-common //安装 NFS客户端
添加 NFS 共享目录,尾部添加
vim /etc/exports
/home/mao/nfsroot *(rw,sync,no_root_squash) # * 表示允许任何网段 IP 的系统访问该 NFS 目录
启动 NFS 服务
sudo /etc/init.d/nfs-kernel-server start //或者
sudo /etc/init.d/nfs-kernel-server restart
在 NFS 服务已经启动的情况下,如果修改了 “/etc/exports” 文件,需要重启 NFS 服务,以刷新 NFS 的共享目录。
测试 NFS 服务器
mount -t nfs 192.168.1.188:/home/mao/nfsroot /mnt -o nolock//192.168.1.188为主机 ip,/home/mao/nfsroot为主机共享目录,/mnt 为设备挂载目录
如果指令运行没有出错,则 NFS 挂载成功,在主机的 /mnt 目录下应该可以看到 /nfsroot 目录下的内容(可先在 nfsroot 目录下新建测试目录),如需卸载使用
umount /mnt //注意:在 mount 与 umount(解除挂载)操作时,用户的当前路径不能是操作的目标路径。
可以使用df 命令查看是否挂载成功
完。