嵌入式NFS启动配置

一.配置客户机(NFS服务器端):

1.创建或修改/etc/exports配置文件:

这个文件的内容非常简单,每一行由抛出路径,客户名列表以及每个客户名后紧跟的访问选项构成: 

        [共享的目录] [主机名或IP(参数,参数)] 

其中参数是可选的,当不指定参数时,nfs将使用默认选项。默认的共享选项是 sync,ro,root_squash,no_delay。 

当主机名或IP地址为空时,则代表共享给任意客户机提供服务。

当将同一目录共享给多个客户机,但对每个客户机提供的权限不同时,可以这样: 

        [共享的目录] [主机名1或IP1(参数1,参数2)] [主机名2或IP2(参数3,参数4)]

下面是一些NFS共享的常用参数: 

        ro                      只读访问 

        rw                      读写访问 

        sync                    所有数据在请求时写入共享 

        async                   NFS在写入数据前可以相应请求 

        secure                  NFS通过1024以下的安全TCP/IP端口发送 

        insecure                NFS通过1024以上的端口发送 

        wdelay                  如果多个用户要写入NFS目录,则归组写入(默认) 

        no_wdelay               如果多个用户要写入NFS目录,则立即写入,当使用async时,无需此设置。 

        hide                    在NFS共享目录中不共享其子目录 

        no_hide                 共享NFS目录的子目录 

        subtree_check           如果共享/usr/bin之类的子目录时,强制NFS检查父目录的权限(默认) 

        no_subtree_check        和上面相对,不检查父目录权限 

        all_squash              共享文件的UID和GID映射匿名用户anonymous,适合公用目录。 

        no_all_squash           保留共享文件的UID和GID(默认) 

        root_squash             root用户的所有请求映射成如anonymous用户一样的权限(默认) 

        no_root_squas           root用户具有根目录的完全管理访问权限 

        anonuid=xxx             指定NFS服务器/etc/passwd文件中匿名用户的UID 

        anongid=xxx             指定NFS服务器/etc/passwd文件中匿名用户的GID 

配置文件/etc/exports内容如下:

        $ cat /etc/exports

 

        /home/terry/wwl/nufront/nfs/ubuntu 192.168.1.100(rw,sync) *(ro)

配置说明: 对192.168.1.100赋予读写权限,其他机器仅有只读权限。

 

3.重启NFS服务:

        # /etc/init.d/nfs-kernel-server restart

 

4.在客户机上查看NFS的资源共享情况:

        # showmount -e 192.168.1.223 

        Export list for 192.168.1.223:

        /home/terry/wwl/nufront/nfs/ubuntu (everyone)

 

5.使用mount命令既可挂载共享资源:

在客户机 192.168.1.223 上加载共享资源 

        # mount 192.168.1.223:/home/terry/wwl/nufront/nfs/ubuntu /mnt

 

        # cd /mnt

        

        # echo '12345'> 123

即可发现对服务器共享目录可写 

        # umount /mnt

在客户机 192.168.1.61 上加载共享资源 

        # mount 192.168.1.223:/home/terry/wwl/nufront/nfs/ubuntu /mnt

 

        # cd /mnt

 

        # ls

        123

 

        # touch 321

 

        touch: cannot touch `321': Permission denied

 

        # echo '123455' >123

 

        -bash: 123: Permission denied

即可发现对服务器共享目录只有读取权限, 

这与我们在服务器端的权限设置是相符的。

是不是我们每次修改了配置文件都需要重启nfs服务呢? 这个时候我们就可以用exportfs命令重新扫描/etc/exports文件,来使改动立刻生效。

比如:

        # exportfs -au 卸载所有共享目录

 

        # exportfs -rv 重新共享所有目录并输出详细信息

exportfs 命令有软件包 nfs-kernel-server 提供,详细的 exportfs 命令说明请查看:

        man exportfs

中文的手册说明可以查看这里:

exportfs联机手册

当完成资源共享, 我们如何知道发布了哪些权限呢?这时我们可以查看 /var/lib/nfs/etab 文件,它是有 exportfs 命令根据 /etc/exports 生成的。

        # cat /var/lib/nfs/etab

 

        /home/share     192.168.102.15(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534)

        /home/share     *(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534)

现在我们来查看服务器上有关NFS服务器启动了哪些端口:

        tonybox:/home/share# lsof -i|grep rpc

        portmap   1931 daemon    3u  IPv4   4289       UDP *:sunrpc

        portmap   1931 daemon    4u  IPv4   4290       TCP *:sunrpc (LISTEN)

        rpc.statd 3206  statd    3u  IPv4   7081       UDP *:1029

        rpc.statd 3206  statd    6u  IPv4   7072       UDP *:838

        rpc.statd 3206  statd    7u  IPv4   7085       TCP *:1031 (LISTEN)

        rpc.mount 3483   root    6u  IPv4   7934       UDP *:691

        rpc.mount 3483   root    7u  IPv4   7937       TCP *:694 (LISTEN)

 

 

二.配置板子uboot的启动参数:

set bootargs 'root=/dev/nfs nfsroot=192.168.1.223:/home/terry/wwl/nufront/nfs/ubuntu ip=192.168.1.100:192.168.1.100:192.168.1.1:255.255.255.0::eth0:off console=ttyS0,38400 mem=320M';

set bootcmd 'ns2416 hdmi;ns2416 wakeup;ns2416 archnum 3216;setenv bootmode nfs;setenv init /linuxrc;tftp 0x80007fc0 uImage;bootm'

 

如果用KGDB则再bootargs里加kgdboc=ttyS0,38400 kgdbwait 如:

set bootargs 'kgdboc=ttyS0,38400 kgdbwait root=/dev/nfs nfsroot=192.168.1.223:/home/terry/wwl/nufront/nfs/ubuntu ip=192.168.1.100:192.168.1.100:192.168.1.1:255.255.255.0::eth0:off console=ttyS0,38400 mem=320M';

 

还需要配置下内核(一般都是配置好的):

Networking  --->
[*] Networking support
Networking options  --->
[*]   IP: kernel level autoconfiguration
[*]     IP: DHCP support
[*]     IP: BOOTP support
[*]     IP: RARP support


Device Drivers  --->
Block devices  --->
<*> Network block device support


File systems  --->
Network File Systems  --->
<*> NFS file system support
[*]   Provide NFSv3 client support
[*]     Provide client support for the NFSv3 ACL protocol extension
[*]   Provide NFSv4 client support (EXPERIMENTAL)
[*]   Allow direct I/O on NFS files
< > NFS server support
[*] Root file system on NFS


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值