ubuntu nfs挂载方法

来源:互联网 发布:head first java百度云 编辑:程序博客网 时间:2024/06/03 14:39

环境:ubuntu 12.04

step1:

在使用nfs服务前,我们需要先关闭伟大的防火墙要不然有可能失败。

指令:  ufw disable
step2:

安装nfs,有人说ubuntu12.04已经安装了最新版的,我不信,所以我要试试。。。

指令:sudo apt-get install nfs-kernel-server

step3:

打开/etc/exports文件,在末尾加入: /home/daysmark/nfsdir *(rw,sync,no_root_squash)

注:nfs允许挂载的目录及权限,在文件/etc/exports中进行定义,各字段含义如下:

/home/daysmark/nfsdir:要共享的目录

* :允许所有的网段访问

rw :读写权限

sync:资料同步写入内在和硬盘

no_root_squash:nfs客户端共享目录使用者权限

重启服务:
#sudo /etc/init.d/portmap restart                      //重启portmap
#sudo /etc/init.d/nfs-kernel-server restart       //重启nfs服务
#showmount -e                                                  //显示共享出的目录

step4:

现在可以在本机上试一下:
#sudo mount -t nfs 192.168.0.149: /home/daysmark/nfsdir /mnt

注:192.168.0.149为本机linux的IP地址

这样就把共享目录挂到了/mnt目录,不信?你touch一个文件到nfsdir里,然后cd到/mnt下你看看有木有。^_^

取消挂载用这个指令:
#sudo umount /mnt

如果用在嵌入式设备上挂载,要加上参数-o nolock

我在开发板上使用的挂载命令:

mount -t nfs 192.168.0.149:/home/daysmark/nfsdir /mnt  -o nolock



每次挂在都需要输入这么长的命令?  写个脚本吧!

echo "mount? [yes|no]"read project_noif [ $project_no = "yes" ];thenecho "mount nfs -> /mnt"mount -t nfs 192.168.0.149:/home/daysmark/nfsdir /mnt -o nolockelif [ $project_no = "no" ];thenumount /mntecho "unmount from /mnt"else echo "error please input yes or no"fi



0 0
原创粉丝点击