从nfs的原理来看须要的套件有3个,一个是nfs核心,一个是rpc,另一个就是portmap 。
对ubuntu而言,这三个套件包含在两个套件当中,一个是nfs核心,名为nfs-kernel-server,另一个套件是rpcbind,它不只包括RPC还包括portmap套件。
安装:rpcbindubuntu
$sudo apt-get install rpcbind
安装nfs-kernel-server服务器
$sudo apt-get install nfs-kernel-server
在服务器端Linux主机中检查NFS服务状态:async
# service nfs-kernel-server status nfsd running
开始建立NFS的共享文件夹,并修改/etc/exports 文件(有的系统安装rpcbind和nfs-kernel-server以后会自动生成/etc/exports 文件,有的不会):测试
# mkdir /nfsfile # echo "/nfsfile 192.168.1.141(rw,sync,no_root_squash)" > /etc/exports # cat /etc/exports /nfsfile 192.168.1.134(rw,sync,no_root_squash)
这里咱们建立了/nfsfile目录用于NFS共享,并在/etc/exports文件中将共享属性IP设置为192.168.1.141(开发板上的IP,在/dev/eth0-setting里面能够修改IP,修改后重启便可)的用户可读写,而且由no_root_aquash指定信任客户端,这样咱们能够以root权限在开发板上对/nfsfile目录进行可读写操做。rw权限是可擦写,还有ro只读,sync表明数据会同步写入到内存与硬盘中,async则表明数据会先暂存于内存当中,而非直接写入硬盘,开放客户端使用root身份来操做服务器的文件系统,那么开no_root_squash才行,root_squash不容许。(更多配置文件的权限参数和IP(主机名)配置方式请参考鸟哥的私房菜-----Linux服务器架设篇 P400页)。this
服务器启动NFS服务两种方法:
第一种:spa
# service nfs-kernel-server restart/start * 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 "192.168.1.141:/nfsroot/". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x [ OK ] * Starting NFS kernel daemon [ OK ]
第二种:rest
# service nfs-kernel-server status nfsd running root@ubuntu:/home/ice# 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 stop(8) and then start(8) utilities, e.g. stop portmap ; start portmap. The restart(8) utility is also available. portmap stop/waiting portmap start/running, process 31525 # 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 "192.168.1.141:/nfsroot/". Assuming default behaviour ('no_subtree_check'). NOTE: this default has changed since nfs-utils version 1.0.x [ OK ] * Starting NFS kernel daemon [ OK ]
接下来在服务器上mount来测试:code
# touch /nfsfile/test //test 为测试文件 # ls /mfsfile test # mount 192.168.1.140:/nfsfile /mnt/ # ls /mnt test
mount时的ip地址192.168.1.140就是Linux主机的IP地址。开发板的IP地址是192.168.1.141,和服务器在同一网段,连上网线以后它们就能够互相ping通了。server
接着可直接在服务器上经过telnet的方式链接到开发板,并进行Mount操做。注意:telnet时须要开发板的账号、密码。账号默认是root,密码能够在开发板上经过passwd命令修改。
telnet登陆以后就能够挂载了:ip
# mount 192.168.1.140:/nfsfile /mnt # ls /mnt test
这时候可能会出现错误:
mount: mounting 192.168.1.140:/nfsfile on /mnt failed: Connection refused
这时挂载命令改成:
mount -t nfs -o nolock 192.168.1.140:/nfsfile /mnt
其余问题:
1.出现问题:
reason given by server: Permission denied
解决:
服务器端启动必定要sudo启动,否则启动失败,服务拒绝
2.出现问题:
mount: mounting 192.168.1.140:/nfsroot on /mnt failed: Device or resource busy
解决:
mount上以后在进行mount命令会出现此提示,设备正在运行,不用再次mount
若是想再次mount能够先umount /mnt/