NFS(Network File System)即网络文件系统,是FreeBSD支持的文件系统中的一种,它容许网络中的计算机之间经过TCP/IP网络共享资源。在NFS的应用中,本地NFS的客户端应用能够透明地读写位于远端NFS服务器上的文件,就像访问本地文件同样。linux
如下是NFS最显而易见的好处:ubuntu
NFS体系至少有两个主要部分:bash
一台NFS服务器和若干台客户机,如右图所示。
客户机经过TCP/IP网络远程访问存放在NFS服务器上的数据。
在NFS服务器正式启用前,须要根据实际环境和需求,配置一些NFS参数。服务器
NFS 有不少实际应用。下面是比较常见的一些:网络
NFS是运行在应用层的协议。随着NFS多年的发展和改进,NFS既能够用于局域网也能够用于广域网,且与操做系统和硬件无关,能够在不一样的计算机或系统上运行。this
$ sudo apt-get install nfs-kernel-server
打开/etc/exports文件,在末尾加入:操作系统
/home/kevin *(rw,sync,no_root_squash) 注:nfs容许挂载的目录及权限,在文件/etc/exports中进行定义,各字段含义以下: /home/kevin:要共享的目录 * :容许全部的网段访问 rw :读写权限 sync:资料同步写入内在和硬盘 no_root_squash:nfs客户端共享目录使用者权限
重启服务:rest
$sudo /etc/init.d/portmap restart <---重启portmap, 1604更名为rpcbind $sudo /etc/init.d/nfs-kernel-server restart <---重启nfs服务 $showmount -e <---显示共享出的目录
注:nfs是一个RPC程序,使用它前,须要映射好端口,经过portmap设定
命令执行状况以下:code
$sudo /etc/init.d/portmap restart Rather than invoking init scripts through /etc/init.d, use the service(8) utility, e.g. service portmap restart Since the script you are attempting to invoke has been converted to an Upstart job, you may also use the restart(8) utility, e.g. restart portmap portmap start/running, process 474
$sudo /etc/init.d/nfs-kernel-server restart * Stopping NFS kernel daemon [ OK ] * Unexporting directories for NFS kernel daemon... [ OK ] * Exporting directories for NFS kernel daemon... exportfs: /etc/exports [1]: Neither 'subtree_check' or 'no_subtree_check' specified for export "*:/home/xgc". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x [ OK ] * Starting NFS kernel daemon [ OK ]
$showmount -e Export list for xgc-VirtualBox: /home/kevin *
如今能够在本机上试一下:server
$sudo mount -t nfs localhost:/home/kevin /mnt sudo mount –t nfs 共享主机ip:/rootfs 挂载点 注:localhost为本机linux的IP地址
这样就把共享目录挂到了/mnt目录,取消挂载用:
$sudo umount /mnt 卸载 : umount -e 挂载点 // 注意卸载时命令的执行路径不可以是挂载点
若是用在嵌入式设备上挂载,要加上参数-o nolock
我在开发板上使用的挂载命令:
#mount -t nfs -o nolock 192.168.1.8:/home/kevin /mnt