Linux nfs 服务端配置

来源:互联网 发布:洪泽新闻网农村淘宝 编辑:程序博客网 时间:2024/05/01 18:17

Linux nfs 服务端配置

 

我的机器  redhat 9.0

[root@localhost n300]# uname -a

Linux localhost.localdomain 2.6.9-42.EL #1 Sat Aug 12 09:17:58 CDT 2006 i686 athlon i386 GNU/Linux

1:首先确保自己已经安装有nfs服务,测试方式可以为:

#service nfs status

没有unrecognized service之类的错误输出就表示已经安装

2:编辑配置文件/etc/exports,内容简单的可以为:

/home *(rw)

也可以配置更多的参数,如

/home/work 192.168.0.*(rw,sync,no_root_squash)

添加的内容表示:允许ip 地址范围在192.168.0.*的计算机以读写的权限来访问/home/work 目录。

/home也称为服务器输出共享目录。

  括号内的参数意义描述如下:

  rw:读/写权限,只读权限的参数为ro;

  sync:数据同步写入内存和硬盘,也可以使用async,此时数据会先暂存于内存中,而不立即写入硬盘。

  no_root_squash:NFS 服务器共享目录用户的属性,如果用户是 root,那么对于这个共享目录来说就具有 root 的权限。

3:重启或者启动对应的两个服务:

[root@localhost n300]# service portmap restart

Stopping portmap:                                          [  OK  ]

Starting portmap:                                          [  OK  ]

[root@localhost n300]# service nfs restart

Shutting down NFS mountd:                                  [  OK  ]

Shutting down NFS daemon:                                  [  OK  ]

Shutting down NFS quotas:                                  [  OK  ]

Shutting down NFS services:                                [  OK  ]

Starting NFS services:                                     [  OK  ]

Starting NFS quotas:                                       [  OK  ]

Starting NFS daemon:                                       [  OK  ]

Starting NFS mountd:                                       [  OK  ]

[root@localhost n300]#

4:本机测试或者其他客户端的测试:

>: mount -o nolock 10.78.28.103:/usr/n300 /mnt

mount: RPC: Unable to receive; errno = No route to host

mount: nfsmount failed: Bad file descriptor

mount: Mounting 10.78.28.103:/usr/n300 on /mnt failed: Bad file descriptor

如果有上面类似错误,有可能是如下原因

a:先ping客户端能否连通服务器ip

RPC: Unable to receive; errno = No route to host 的原因

    b:nfs服务器是否有防火墙屏蔽了对应端口

    c:/etc/hosts.deny  /etc/hosts.allow 是否屏蔽了客户端ip

Bad file descriptor的原因

d:/etc/exports配置有问题,确保文件中的"()"是英文的,如果你从其他地方copy有可能出现如上问题

解决办法:

[root@localhost n300]# service iptables stop

Flushing firewall rules:                                   [  OK  ]

Setting chains to policy ACCEPT: filter                    [  OK  ]

Unloading iptables modules:                                [  OK  ]

[root@localhost n300]# service iptables status

Firewall is stopped.

[root@localhost n300]# cat /etc/hosts

hosts        hosts.allow  hosts.deny

[root@localhost n300]# cat /etc/hosts.deny

#

# hosts.deny    This file describes the names of the hosts which are

#               *not* allowed to use the local INET services, as decided

#               by the '/usr/sbin/tcpd' server.

#

# The portmap line is redundant, but it is left to remind you that

# the new secure portmap uses hosts.deny and hosts.allow.  In particular

# you should know that NFS uses portmap!

[root@localhost n300]# cat /etc/hosts.allow

#

# hosts.allow   This file describes the names of the hosts which are

#               allowed to use the local INET services, as decided

#               by the '/usr/sbin/tcpd' server.

#

/*

在这里笔者也同样遇到了这样的一个问题,在网上百度过很多,都没有搞定,最后最后我自己写的这篇文章,和自己以前为了能使linux上网,把VM里的Ethernet设置了NAT的原因解决方法就是把它设回Brideged。这是原文没有的,笔者后来添加进去,如果有人遇到了同样的问题,希望能给你帮助。

*/

[root@localhost n300]#

 

5: 解决上面问题后应该可以正确的mount了

>: mount -o nolock 10.78.28.103:/usr /mnt

mount: 10.78.28.103:/usr failed, reason given by server: Permission denied  #还是有错,iptable在作怪

mount: nfsmount failed: Bad file descriptor

mount: Mounting 10.78.28.103:/usr on /mnt failed: Bad file descriptor

>:

>:

>:####自给解决上面的错误

>:

>: mount -o nolock 10.78.28.103:/usr/n300 /mnt   ##正确了

>:

>:

>: df

Filesystem                Size      Used Available Use% Mounted on

/dev/root                 6.6M      6.6M         0 100% /

/dev/mtdblock/5           1.0M     68.0k    956.0k   7% /info

/dev/mtdblock/6          42.0M      3.3M     38.7M   8% /apps

/dev/mtdblock/7           5.0M    196.0k      4.8M   4% /logs

10.78.28.218:/home/webserver      8.4G      7.2G    780.8M  90% /tmp/mnt

10.78.28.103:/usr/n300      9.6G      6.7G      2.4G  73% /mnt

引致:http://blog.chinaunix.net/u1/51980/showart_679640.html

 

总结:

步骤:

1,vi /etc/exports        //编辑配置
      2,service portmap restart       //重启portmap服务
       3,service nfs restart       //重启nfs服务
      4,showmount -e        //显示/etc/exports
       5,mount -t nfs -o nolock 192.168.1.200:/opt/FriendlyARM/Micro2440/ /mnt/ //主机挂载
       6,umount /mnt        //主机卸载
       7,service iptables stop       //关闭防火墙
       8,mount -t nfs -o nolock 192.168.1.200:/opt/FriendlyARM/Micro2440/ /mnt/ //开发板挂载

原创粉丝点击