1.使用apt-get安装NFS服务
检测是否安装了NFS:dpkg -l |grep -i "nfs"
安装NFS服务:sudo apt-get install nfs-kernel-server
sudo apt-get install nfs-common
2.启动与停止NFS服务
/etc/init.d/nfs-kernel-server start
启动后可以使用ps命令查看进程:ps -aux | grep -i "nfs"
3.设置NFS的主配置文件 /etc/exports
/nfs/public 192.168.0.0/24(rw,sync) *(ro)
说明: /nfs/public:共享目录名
192.168.0.0/24:表示所有主机
sync:设置NFS服务器同步写磁盘
ro: 设置输出的共享目录只读
rw:设置输出的共享目录可读写
例如:/home/tstnfs *(rw,sync,no_root_squash)
4.使用mount命令挂载nfs文件系统
mount -t nfs localhost : /opt/root_fs /mnt -o nolock
例如: mount -t nfs 127.0.0.1:/home/tstnfs /mnt/nfs -o nolock
注意:nfs mount 默认选项包括文件锁,需加上-o nolock
5.错误笔记
执行命令 /etc/init.d/nfs-kernel-server start
出了错误,错误日志为:
Starting NFS daemon: [FAILED]
原因:
原先的nfs 进程乱了,
解决办法:
需要手动全部杀死,然后重启就可以了:
具体操作步骤:
ps -ef | grep nfs
发现好多进程
然后执行:kill -9 xxxx
......
然后再执行:
service portmap start
然后执行
/etc/init.d/nfs-kernel-server start
问题搞定了