---
title: "Ubuntu 14.04下NFS安装配置"
author: "stephen830"
date: "2016-04-13T08:21:43Z"
tags: []
categories: ["操作系统"]
slug: "ubuntu-14-04-nfs"
draft: false
lastmod: "2016-04-18T13:29:02Z"
id: 2290580
url: "https://stephen830.iteye.com/blog/2290580"
---

# Ubuntu 14.04下NFS安装配置

参考：http://www.linuxidc.com/Linux/2013-08/89154.htm

 

***［服务器端要做的工作］***

 

1、执行命令：sudo apt-get install nfs-kernel-server ;

2、执行命令：mkdir /home/jacobxu/nfs-jacoxu 建立一个nfs服务的专有的文件夹;

3、建立好文件夹后，接着执行命令：sudo vi /etc/exports 配置nfs;

4、在文章的最后一行添加：/home/jacobxu/nfs-jacoxu \*(rw,sync,no\_root\_squash,no\_subtree\_check)  
/home/jacobxu/nfs-jacoxu \*(rw,sync,no\_root\_squash,no\_subtree\_check)这一行的含义是：  
/home/jacobxu/nfs-jacoxu：与nfs服务客户端共享的目录，这个路径必须和你前面设置的文件的路径一致！  
\*：允许所有的网段访问，也可以使用具体的IP  
rw：挂接此目录的客户端对该共享目录具有读写权限  
sync：资料同步写入内存和硬盘  
no\_root\_squash：root用户具有对根目录的完全管理访问权限。  
no\_subtree\_check：不检查父目录的权限。

 

可以指定客户端ip地址，如下（允许10.10.86.22，10.10.11.3这2个客户端访问）：

/data/share 10.10.86.22(rw,sync,no\_root\_squash,no\_subtree\_check) 10.10.11.3(rw,sync,no\_root\_squash,no\_subtree\_check)

 

5、修改完上述配置文件保存退出。

6、执行命令：sudo /etc/init.d/rpcbind restart 重启rpcbind 服务。nfs是一个RPC程序，使用它前，需要映射好端口，通过rpcbind 设定。

7、执行命令：sudo /etc/init.d/nfs-kernel-server restart 重启nfs服务。

 

用showmount -e命令查看配置是否正常

root@10-10-228-163:/etc# **showmount -e**  
Export list for 10-10-228-163:  
/data/share 10.10.11.3,10.10.86.22

 

***［客户端要做的工作］***

8、挂载指令：  
sudo mount -t nfs 192.168.111.128:/home/jacobxu/nfs-jacoxu /nfs-jacoxu-node001/  
到任意一台服务器中执行挂载指令，则可以将指定ip服务器上的共享路径，挂载到本地。

注：nfs只是一种文件目录共享模式，以本地方式进行访问。而HDFS是一种分布式的文件系统，能够在服务器中进行数据的负载均衡。

 

mount命令执行报如下错误：

root@10-10-228-163:/# mount -t nfs 10.10.86.22:/data/images /data/mnt  
mount: wrong fs type, bad option, bad superblock on 10.10.86.22:/data/images,  
       missing codepage or helper program, or other error  
       (for several filesystems (e.g. nfs, cifs) you might  
       need a /sbin/mount.&lt;type&gt; helper program)  
       In some cases useful info is found in syslog - try  
       dmesg | tail  or so

那是因为客户端没有安装mount.nfs，用 ls -l /sbin查看下，果然在/sbin目录下没有mount.nfs文件，

因此，在客户端安装下mount.nfs执行命令：

**apt-get install nfs-common**

安装成功后，再执行mount命令就ok了。

 

 

9、开机自动挂载：  
把 上述指令 sudo mount -t nfs 192.168.111.128:/home/jacobxu/nfs-jacoxu /nfs-jacoxu-node001/ 写到 /etc/rc.local 文件中

 

10、取消挂载

sudo umount /nfs-jacoxu-node001/

＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝

附录：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