Ubuntu上NFS的安装配置(问题解决版)

来源:互联网 发布:斯皮尔伯格 人工智能 编辑:程序博客网 时间:2024/04/16 20:12
Ubuntu 默认是没有nfs服务的,所以需要自己安装
 
1、安装nfs服务版
           apt-get install nfs-kernel-server
2、修改nsf配置文件
   vi /etc/exports
           在文件中添加nfs的目录格式如下
   /armnfs *(sync,rw)
           存盘退出
3、在根目录下建立nfs的目录
   mkdir /armnfs
           修改该目录的权限
   chmod 777 -R /armnfs
4、从新启动nfs
           /etc/init.d/nfs-kernel-server restart
 
5、测试nfs
 
mount 192.168.1.99:/armnfs/ abc
 
嵌入式要mount 的时候 使用
 mount -o nolock 192.168.1.99:/armnfs/new8120 /mnt/net
 
注:在内核的配置里面的
 Networking options --->选项中
 
启用 TCP/IP networking
 
启用IP: kernel level autoconfiguration
 
General setup       --->     选项中 ,
 
Default kernel command string:            (默认的内核命令行)
 
加入绿色字中的字符
 
root=/dev/nfs rw nfsroot=192.168.1.99:/armnfs/ ip=192.168.1.201 init=/linuxrc console=ttyS0
 
File system ---> Network File System --->选项
 
启用 NFS file system support
 
启用 Provide NFSv3 client support
 
启用 Root file system on NFS
 
nfs配置: 
less /etc/exports 
/home/xx/ 192.168.0.*(rw,sync) 
 
$ sudo /etc/init.d/portmap start 
* Starting portmap daemon... 
* Already running. [ OK ] 
$sudo /etc/init.d/nfs-common start 
* Starting NFS common utilities [ OK ] 
$ sudo /etc/init.d/nfs-kernel-server start 
* Exporting directories for NFS kernel daemon... 
exportfs: /etc/exports [2]: Neither 'subtree_check' or 'no_subtree_check' specified for export "192.168.0.*:/home/xx/".  

Assuming default behaviour ('subtree_check'). 
NOTE: this default will change with nfs-utils version 1.1.0 
[ OK ] 
* Starting NFS kernel daemon [ OK ] 
 
$ showmount -e 
Export list for Qunhome: 
/home/xx 192.168.0.* 
 
似乎都好了,可是 : 
sudo mount 192.168.0.100:/home/xx /mnt 
mount: 192.168.0.100:/home/xx failed, reason given by server: Permission denied 
 
我装的是7.04,和你出现了同样的问题,以前我用6.06的时候是没有问题的 
不知道是不是7.04的bug阿, 
配置portmap的时候,在etc目录下就没有找到host.allow和hosts.deny这俩个文件,我是自己新建的这俩个文件,以前我记得在etc目录下是有的。
 
在/etc/exports下写入你的IP地址,不要有*号。例如:(/home/zwg IP(rw,sync,no_root_squash)) 
原因可能是etc目录下没有hosts.allow和hosts.deny这俩个文件。
 
我装的是7.04,和你出现了同样的问题,以前我用6.06的时候是没有问题的 
不知道是不是7.04的bug阿, 
配置portmap的时候,在etc目录下就没有找到host.allow和hosts.deny这俩个文件,我是自己新建的这俩个文件,以前我记得在etc目录下是有的。 
 
非常感谢! 
我删除了安装文件和所有相关配置文件 
然后一步步重新来,最后成功了 
 
做的改动为: 
在/etc/hosts中用IP lists 代替 *
 
还有一种方法:安装配置的没有大问题。不妨在括号里加上no_subtree_check选项,这是减少文件共享访问检查的,如果你的共享目录在本地没有很多读写请求的话(man exports)。
 
On the master node, edit your /etc/hosts.allow file to allow connections from slave nodes. If your cluster LAN is on 192.168.1.0/24, your hosts.allow will look like:
 
Code Listing 2.10: hosts.allow
 
portmap:192.168.1.0/255.255.255.0
 
Edit the /etc/exports file of the master node to export a work directory structure (/home is good for this).
 
Code Listing 2.11: /etc/exports
 
/home/ *(rw)
 
把hosts.deny删除。子网用掩码的方法表示。
 
NFS(Network File System, 网络文件系统)可以通过网络将分享不同主机(不同的OS)的目录——可以通过NFS挂载远程主机的目录, 访问该目录就像访问本地目录一样!
一般而言, 使用nfs能够方便地使各unix-like系统之间实现共享. 但如果需要在unix-like和windows系统之间共享, 就得使用samba了!
NFS运行在SUN的RPC(Remote Procedure Call, 远程过程调用)基础上, RPC定义了一种与系统无关的方法来实现进程间通信. 由此, NFS server也可以看作是RPC server.
   
正因为NFS是一个RPC服务程序, 所以在使用它之前, 先要映射好端口——通过portmap设定. 比如: 某个NFS client发起NFS服务请求时, 它需要先得到一个端口(port). 所以它先通过portmap得到port number. (不仅NFS, 所有的RPC服务程序启动之前, 都需要设定好portmap)
    与NFS相关的几个文件, 命令
1, /etc/exports
    对NFS卷的访问是由exports来批准, 它枚举了若干有权访问NFS服务器上文件系统的主机名.
 
2, /sbin/exportfs
    维护NFS的资源共享. 可以通过它重新设定 /etc/exports 的共享目录, 卸载NFS Server共享的目录或者重新共享等.
  
3, /usr/sbin/showmount
    用在 NFS Server 端,而 showmount 则主要用在 Client 端. showmount 可以用來查看 NFS 共享的目录资源.
 
4, /var/lib/nfs/xtab
    NFS的记录文档: 通过它可以查看有哪些Client 连接到NFS主机的记录.
 
下面这几个并不直接负责NFS, 实际上它们负责所有的RPC
5, /etc/default/portmap
    实际上, portmap负责映射所有的RPC服务端口, 它的内容非常非常之简单(后面详述)
 
6, /etc/hosts.deny
    设定拒绝portmap服务的主机
 
7, /etc/hosts.allow
    设定允许portmap服务的主机
安装NFS
Debian/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, 将 -i 127.0.0.1 去掉.
 
方法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.2开头的主机(连 接到NFS服务器上),也可以指定特定的IP地址。参看man页 hosts_access(5), hosts_options(5)。加入:
### NFS DAEMONS
 
portmap: 192.168.2.
 
lockd: 192.168.2.
 
rquotad: 192.168.2.
 
mountd: 192.168.2.
 
statd: 192.168.2.
 
/etc/hosts.deny 和 /etc/hosts.allow 设置对portmap的访问. 采用这两个配置文件有点类似"mask"的意思. 现在/etc/hosts.deny中禁止所有用户对portmap的访问. 再在/etc/hosts.allow 中允许某些用户对portmap的访问.
运行 $ sudo /etc/init.d/portmap restart 重启portmap daemon.
 
配置/etc/exports
NFS挂载目录及权限由/etc/exports文件定义
   
比如我要将将我的home目录中的/home/zp/share目录让192.168.2.*的IP共享, 则在该文件末尾添加下列语句:
         /home/zp/share    192.168.2.*(rw,sync,no_root_squash)
或者:/home/zp/share    192.168.2.0/24(rw,sync,no_root_squash)
 
192.168.2.* 网段内的NFS客户端能够共享NFS服务器/home/zp/share目录内容.且有读,写权限, 并且该用户进入/home/zp/share目录后的身份为root
最好加上sync, 否则 $ sudo exportfs -r 时会给出警告, sync是NFS的默认选项.
 
(运行 $ showmount -e 查看NFS server的export list.
 
若更改了/etc/exports, 运行 $ sudo exportfs -r 更新
 
运行 $ sudo /etc/init.d/nfs-kernel-server restart 重启nfs服务)

/etc/exports实际上就是nfs服务器的核心配置文件了. 鸟哥的Linux私房菜列举了一些exports文件的写法.
 
测试NFS
可以尝试一下挂载本地磁盘(假设本地主机IP地址为:192.128.2.1,将/home/zp/share挂载到/mnt)
$ sudo mount 192.168.2.1:/home/zp/share /mnt
运行 $ df 看看结果
$ sudo umount /mnt
 
注意被拷贝文件的读/写权限!
另外, 可以使用一定的参数:
使用加参数的办法:mount -o nolock,rsize=1024,wsize=1024,timeo=15 192.168.2.130:/tmp/ /tmp/


原创粉丝点击