在ubuntu上配置NFS

来源:互联网 发布:企业seo外包服务 编辑:程序博客网 时间:2024/06/08 01:31
在ubuntu上配置NFS
主机平台:Ubuntu 12.04

1.开始使用命令更新安装最新版本

#sudo apt-get install nfs-kernel-server

ubuntu12.04中的已经是最新版本了

2.配置共享目录的路径和访问权限

安装好nfs-common和portmap后还需配置共享目录的路径和访问权限,NFS的配置文件是/etc/exports。

配置的格式如下:

[共享路径][主机名或IP地址(参数,参数)]

举例:

/home/zhcx/nfs_root192.168.1.111(rw,sync,no_root_squash)

3.重启服务:

#sudo /etc/init.d/portmap restart

#sudo /etc/init.d/portmap stop             

#sudo /etc/init.d/nfs-kernel-server restart     
#showmount -e                                   

#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/zhcx/nfs_root

4.挂载文件 

现在可以在本机上试一下:
#sudo mount -t nfs localhost:/home/zhcx/nfs_root /mnt

注:localhost为本机linux的IP地址

这样就把共享目录挂到了/mnt目录,在目录/mnt中可以看得到目录/home/zhcx/nfs_root中的文件。

取消挂载用:
#sudo umount /mnt

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

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

mount -t nfs -o nolock 192.168.1.8:/home/zhcx/nfs_root /mnt