分享

ubuntu10.4 开启 NFS

 oskycar 2010-10-30

ubuntu10.4 开启 NFS(转)

1 setup nfs server:
 "sudo apt-get install nfs-kernel-server"
2 edit the configure file
 "sudo gedit /etc/exports"
 add this line to file:  "/nfs *(sync,rw,no_root_squash)"
 
 /nfs point to the directory which you want clinet to mount.
 * means everyone can access to this nfs, you can replace it with ip marks,like:192.168.1.*
 (sync,rw,no_root_squash) is the parameters used for nfs
3 restart the nfs server
 "sudo  /etc/init.d/nfs-kernel-server restart" 
 notice that we should use sudo before every command, or an error would be caused.
4  test your nfs
 creat a folder to mount the nfs server folder
  "mkdir testNFS"
 then use following command to mount the nfs server folder :
  "sudo mount 192.168.1.101:/nfs  testNFS/"
 this means we will mount  the server's folder "/nfs" to client folder "testNFS/",
 server's is 192.168.1.101
5 umount the folder
   use this command to unmount the server's folder
  "sudo umount /testNFS"
 
 6 close nfs server
if don't need to run the nfs server,we can close it by this command:
 "sudo  /etc/init.d/nfs-kernel-server stop" 

旧版本的安装过程,部分可借鉴

涉及文件
portmap hosts.deny  hosts.allow

涉及操作(按顺序如下)
sudo /etc/init.d/portmap  restart
sudo /etc/init.d/nfs-common restart
sudo /etc/init.d/nfs-kernel-server restart

安装 server 和 client


Ubuntu上默认是没有安装 NFS服务器的,首先要安装NFS服务程序:
$ sudo apt-get install nfs-kernel-server
(安装nfs-kernel-server时,apt会自动安装nfs-common和portmap)
这样,宿主机就相当于NFS Server。

同样地,目标系统作为NFS的客户端,需要安装NFS客户端程序。如果是Debian/Ubuntu系统,则需要安装 nfs-common。
$ sudo apt-get install nfs-commmon
nfs-common和nfs-kernel-server都依赖于portmap!
这样就安装完了,下面进行配置

配置 NFS

配置portmap
方法1: 编辑/etc/default/portmap, 将 最后一行注释掉.
方法2: $ sudo dpkg-reconfigure portmap , 对Should portmap be bound to the loopback address? 选N.

配置/etc/hosts.deny
(禁止任何host(主机)能和你的NFS服务器进行NFS连接),加入:
### NFS DAEMONS
portmap:ALL
lockd:ALL
mountd:ALL
rquotad:ALL
statd:ALL

配 置/etc/hosts.allow
允许那些你想要的主机和你的NFS服务器建立连接。下列步骤将允许任何IP地址以192.168.197开头的主机(连接到NFS服务器上),也可以指定特定的IP地址。参看man页 hosts_access(5), hosts_options(5)。加入:
### NFS DAEMONS
portmap: 192.168.197.
lockd: 192.168.197.
rquotad: 192.168.197.
mountd: 192.168.197.
statd: 192.168.197.

/etc/hosts.deny 和 /etc/hosts.allow 设置对portmap的访问. 采用这两个配置文件有点类似"mask"的意思. 现在/etc/hosts.deny中禁止所有用户对portmap的访问. 再在/etc/hosts.allow 中允许某些用户对portmap的访问.

配置/etc/exports
NFS挂载目录及权限由/etc/exports文件定义  
比如我要将将我的home目录中的/home/liliming/arm2410目录让192.168.197.*的IP共享, 则在该文件末尾添加下列语句:
/home/liliming/arm2410     192.168.197.*(rw,sync,no_root_squash)
或者: /home/liliming/arm2410     192.168.197.0/24(rw,sync,no_root_squash)
注意这里,这样写有可能你的NFS还不能用,你可以允许所以IP共享你的目录,语句如下:
/home/liliming/arm2410    *(rw,sync,no_root_squash)

至此配置完成,下面启动NFS

启动NFS

sudo  /etc/init.d/portmap  restart
sudo  /etc/init.d/nfs-common restart
sudo  /etc/init.d/nfs-kernel-server restart

测试 NFS

Ubuntu 下
sudo mount  localhost:/home/liliming/arm2410  /mnt
ls /mnt
看是否已经挂载成功
开发板 下
mount  192.168.197.75:/home/liliming/arm2410  /mnt
ls /mnt
看是否已经挂载成功(192.168.197.75 是Ubuntu的IP 地址)

可能出现的错误:
1. 挂载不成功,具体提示信息不记得了,可以这样试试
配置/etc/exports
/home/liliming/arm2410     *(rw,sync,no_root_squash)
也就是允许所有的IP 访问
2. 提示 mount rpc unable to receive errno connection refused
说明你的服务器端(Ubuntu )服务没设定好,原因可能如下:
a. NFS 没启动,按照上面的启动步骤 再重新启动一下
b. 看一下 文件 /etc/exports 和文件  /etc/hosts.allow 里面的IP 是不是 包含 你的开发板 IP,
不包含的话,把你的网段写上,重新启动 NFS







NFS安装

nfs原理是通过网络,将远程主机共享的文件系统,挂载到本机。Ubuntu10.04上默认是没有安装NFS服务器的,首先要安装NFS服务程序:

sudo apt-get install nfs-kernel-server

 (安装nfs-kernel-server时,apt会自动安装nfs-common和 portmap) 这样,宿主机就相当于NFS Server。


也可以通过软件管理包来安装nfs-kernel-server


  宿主机NFS的配置

2.1  修改配置文件/etc/exports

在终端下用#  sudo gedit  /etc/exports打开exports文件。

如果你没有配置过这个文件的话此文件应该是空的。在开始部分写入

/hhm   *(rw,sync,no_root_squash)

/hhm  -- 是要与目标板共享的目录;

       -- 表示允许任意用户使用,也可以使用具体IP;
(rw,sync,no_root_squash) 

-- rw,挂载此目录的客户机对此目录有读写权利;
sync,……;
no_root_squash,挂载此目录的客户机享有主机root的权利;

我是将主机的根目录设置为共享目录  *(rw,sync,no_root_squash)

OK,保存,退出。

修改完成之后输入:#  exportfs –rv来使配置文件生效

2.2   配置宿主机的IP

配置宿主机的IP,在命令行中输入 # ifconfig   来查看本机的IP地址。如果没有设置,可以用命令 # ifconfig eth0 192.168.0.18 来设置IP。其中的IP地址可以根据具体情况来设定。设定完成后在通过ifconfig来再次查看是否已经设定成功。

2.3   启动宿主机NFS服务

安装完NFS服务后就可以通过 #  /etc/init.d/nfs-kernel-server restart(/etc/init.d/nfs-kernel-server start)来重新开启网络文件系统服务,以便后面的开发板挂载。也可以通过#  /etc/init.d/nfs-kernel-server stop来停止。

  目标板的挂载操作

给你的目标机上电,目标板上的Linux操作系统起来以后,在PC机上Ubuntu操作系统上打开minicom,通过串口向目标板发送shell命令。

像主机操作一样,首先检查目标板(客户机)的IP是否与宿主机的IP再同一个地址段上,否则用上面用过的命令进行检查和设置本地IP。

设置完IP之后可以ping一下检查网卡、网线是否连接正确。

既在minicom中输入# ping 192.168.0.18  (主机IP地址)连接成功会不断的打印信息。

接下来就是在开发板上进行挂载mount

 # mount -t nfs -o nolock 192.168.0.18:/  /mnt  

其中:后是客户机挂载的共享目录; /mnt是开发板的挂载目录

OK,挂在完成。

通过

# cd  /mnt

# ls

可以发现主机的根目录被挂载进了开发板mnt目录中。

如果你想取消挂在可以使用命令# umount  /mnt就可以了。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多