Chinaunix首页 | 论坛 | 博客
  • 博客访问: 722867
  • 博文数量: 66
  • 博客积分: 2418
  • 博客等级: 大尉
  • 技术积分: 1659
  • 用 户 组: 普通用户
  • 注册时间: 2009-12-28 10:04
个人简介

keep moving

文章分类

全部博文(66)

文章存档

2015年(2)

2014年(6)

2013年(7)

2011年(7)

2010年(42)

2009年(2)

分类: LINUX

2011-01-06 13:44:13

参考文献:
鸟哥的 Linux 与 ADSL 私房菜 之 
《Red Hat Enterprise Linux 5.0服务器构建与故障排除》

配置:vmware中安装ubuntu10.04
系统:windows XP
连接:开发板通过RS232和交叉网线与PC相连

方法如下:
一、虚拟机设置(如果网络已经设置在桥接方式,跳过这步)
1、在启动ubuntu前,将其Ethernet(网络)连接方式设为Bridge(桥接方式)
2、启动ubuntu,设置静态ip地址(必须与开发板处于同一网段)
lingd@ubuntu:~$ sudo ifconfig eth0 192.168.0.26 netmask 255.255.255.0

二、为ubuntu安装NFS
1、安装NFS
lingd@ubuntu:~$ sudo apt-get install nfs-kernel-server
同时会有两个软件包nfs-common和portmap被安装上
2.修改NFS配置文件
lingd@ubuntu:~$ vi /etc/exports
内容为:
     /home/lingd/arm     192.168.0.*(rw,sync,no_root_squash,no_subtree_check)

     /home/lingd/arm---要共享的目录
     192.168.0.*---允许访问的网段,也可以是ip地址、主机名(能够被服务器解析)、*(所有人都能访问)
     (rw,sync,no_root_squash,no_subtree_check)---rw:读/写权限
                                 sync:数据同步写入内存和硬盘
                                 no_root_squash:服务器允许远程系统以root特权存取该目录
no_subtree_check:关闭子树检查
其他选项可以通过man exports查阅man文档

3、启动服务
重启portmapper(端口映射)服务
lingd@ubuntu:~$ sudo service portmap restart
portmap start/running, process 550
重启NFS服务
lingd@ubuntu:~$ sudo service nfs-kernel-server restart
 * Stopping NFS kernel daemon                                            [ OK ] 
 * Unexporting directories for NFS kernel daemon...                      [ OK ] 
 * Exporting directories for NFS kernel daemon...                        [ OK ] 
 * Starting NFS kernel daemon                                            [ OK ]


三、测试
1、本机挂载
lingd@ubuntu:~$ ls /mnt/nfs/
lingd@ubuntu:~$ sudo mount -t nfs -o nolock localhost:/home/lingd/arm/ /mnt/nfs/
lingd@ubuntu:~$ ls /mnt/nfs/
cross-3.4.1.tar.bz2  linux-2.6.12        upload
download             msap                VMwareTools-8.1.3-203739.tar.gz
DSDT_2[1].8b.zip     ntp                 vmware-tools-distrib
DSDT_2.8b            protocol-converter  安装包
lingd@ubuntu:~$ sudo umount /mnt/nfs 
lingd@ubuntu:~$ ls /mnt/nfs/

2、开发板挂载
lingd@ubuntu:~$ telnet 192.168.0.25 2009
Trying 192.168.0.25...
Connected to 192.168.0.25.
Escape character is '^]'.

(none) login: root
Password: 
~ # ls /mnt                                                 
ext1  ext2
~ # mount -t nfs -o nolock 192.168.0.26:/home/lingd/arm /mnt
~ # ls /mnt
DSDT_2.8b                        msap
DSDT_2[1].8b.zip                 ntp
VMwareTools-8.1.3-203739.tar.gz  protocol-converter
cross-3.4.1.tar.bz2              upload
download                         vmware-tools-distrib
linux-2.6.12                     安装包
~ # umount /mnt
~ # ls /mnt
ext1  ext2
~ # 

四、挂载nfs文件系统失败的原因
1、nfs错误信息
Too many levels of remote in path:试图挂载一个存在的文件系统
Permission denied:NFS服务器不让客户机挂接,也可能是因为用户在服务器上不存在
No such host:通常是DNS配置错误
No such file or directory:通常是访问的目录不存在
NFS server is not responding:通常是NFS已经超过负载或者NFS已经停止工作
Stale file handle:在NFS客户端关闭之前客户端访问的文件被删除
Fake hostname:Forward和reverse的DNS记录在NFS客户端下不存在
2、挂载nfs文件系统失败的原因
(1)主机和网络不通:看看网线连接、主机和开发板ip是否在同一网段、防火墙有没有关闭等。不仅vmware中linux的防火墙要关闭,vmware外xp的防火墙也要关闭,我就因为xp中的eset杀毒软件的防火墙使nfs无法挂载(可以挂本机,无法挂远程),折腾了一天,后来才发现是xp中的防火墙搞的鬼!

(2)使用的mount命令不正确。可以参照上面的例子改一下;或者man nfs查阅一下nfs的man文档,里面有nfs中mount的使用介绍和选项解释

(3)nfs配置文件/etc/exports配置不正确。可以参照上面的例子改一下;或者man exports查阅一下/etc/exports的man文档

(4)必要时重新启动NFS和portmap服务。
sudo service portmap restart
sudo service nfs-kernel-server restart

(5)内核不支持NFS和RPC服务(可能需要重新配置、编译、烧写内核)。
普通的内核应有的选项为CONFIG_NFS_FS=m、CONFIG_NFS_V3=y、CONFIG_ NFSD=m、CONFIG_NFSD_V3=y和CONFIG_SUNRPC=m。
rpcinfo命令用于显示系统的RPC信息,一般使用-p参数列出某台主机的RPC服务。rpcinfo -p命令检查服务器时,应该能看到portmapper、status、mountd、nfs和nlockmgr。用该命令检查客户端时,应该至少能看到portmapper服务(开发板可能不带该命令)。由rpcinfo -p可知,nfs使用的port为2049,portmapper使用111port。

五、nfs相关的配置文件与命令
1、/etc/exports
NFS的主要配置文件,不过系统并没有默认值,所以这个文件不一定会存在(需要自己建立)。

2、/usr/sbin/exportfs
用于维护NFS共享资源的命令,用在nfs server端。修改/etc/exports后,只要使用exportfs重新扫瞄一次 /etc/exports,重新将设定加载即可,并不一定要重启nfs服务
命令格式: exportfs [-aruv]
参数说明如下。
(1)-a:全部挂载或卸载(export or unexpect)/etc/exports文件内的目录。
(2)-r:重新挂载(reexport)/etc/exports中的目录,并将/var/lib/nfs/etab中的内容与/etc/exports同步。
(3)-u:卸载某些目录。
(4)-v:显示exportfs处理信息。

3、/usr/sbin/showmount
用于查看指定主机NFS共享出来的目录资源,主要用在Client端。
命令格式: showmount [-ade] hostname/服务器ip地址
参数说明如下。
(1)-a或-all:以host:dir格式显示客户主机名和挂载的目录。
(2)-d或-directories:仅显示被客户挂载的目录名。
(3)-e或-exports:显示指定NFS服务器的nfs共享目录。

4、/var/lib/nfs/etab
/etc/exports里列举的是用户希望nfs共享的目录,而/var/lib/nfs/etab里面是ubuntu实际共享的目录。它记录了NFS所共享出来的目录的完整权限设定值。/var/lib/nfs/etab由exportfs维护,每次exportfs都会扫描/etc/exports以建立新的/var/lib/nfs/etab,每当nfs客户请求挂载共享目录时mountd都会读取该文件以检测客户和目录的权限。同时/var/lib/nfs/etab中共享的目录会保存在内核nfs共享表(export table)中

5、其他nfs相关文件的解析
/var/lib/nfs/etab contains information about what filesystems should be exported to whom at the moment.
/var/lib/nfs/rmtab contains a list of which filesystems actually are mounted by certain clients at the moment.
/proc/fs/nfs/exports contains information about what filesystems are exported to actual client (individual, not subnet or whatever) at the moment.
/var/lib/nfs/xtab is the same information as /proc/fs/nfs/exports but is maintained by nfs-utils instead of directly by the kernel. It is only used if /proc isn't mounted.
* /var/lib/nfs/etab: the /etc/exports file only contains a wish list. etab is created by exportfs. It contains on each line detailed information about the options used when exporting a file system towards a single client. It's the reference file used by rpc.mountd when started
* /proc/fs/nfs/exports contains the clients list as known by the kernel
* /var/lib/nfs/xtab: Use for accuracy when etab holds client names and machines groups with wildcards. This file only contains explicit machine names.
* /var/lib/nfs/rmtab : each line shows the client's name and the file system imported from this server;


阅读(3646) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~