1、系统环境

查询当前系统,安装对应得版本得 nfs相关软件;本文系统环境为 Ubuntu 16.04 amd64

# lsb_release -a

 

2、NFS 服务器端

2.1 软件安装

2.1.1 deb安装

直接 deb安装

# dpkg -i *.deb

 

2.1.2 联网安装

# apt-get install nfs-kernel-server

 

3.2 服务配置

3.2.1 防火墙设置

若不需要 防火墙,可直接关闭防火墙

# ufw disable

 

3.2.2 NFS 配置

3.2.2.1 配置文件

修改配置,重启服务

# vim /etc/exports
# /etc/init.d/nfs-kernel-server restart
## 或者不需要重启服务,让配置生效(  exportfs -r),客户端最好重新挂载

 

3.2.2.2 配置文件参数
/opt *(rw,async,fsid=0,no_root_squash,no_subtree_check)
参数 说明
/opt 共享目录
rw 可擦写 (read-write)
async 数据会先暂存于内存当中,而非直接写入硬盘
no_root_squash 客户端使用 NFS 文件系统的账号若为 root 时,系统该如何判断这个账号的身份?预设的情况下,客户端 root 的身份会由 root_squash 的设定压缩成 nfsnobody, 如此对服务器的系统会较有保障开放客户端使用 root 身份来操作服务器的文件系统
no_subtree_check 默认参数
备注 详细参见 "man exports" ; 关于 fsid 设置, 不同挂载目录 不能相同, 小于 等于 32 得正整数即可, fsid = 0 代表 root;

 

3.2.3 服务基本操作

查看当前服务共享的目录

# showmount -e

4、NFS 客户端

4.1 软件安装

4.1.1 deb安装

直接 deb安装

# dpkg -i *.deb

 

4.1.2 联网安装

# apt-get install nfs-common

 

4.2 NFS客户端挂载

# mount -t nfs {nfs_server_ip}:{share_path} {mount_path}
参数 说明
nfs_server_ip NFS 服务器IP
share_path NFS 服务器共享目录
moun_path NFS客户端本地挂载目录

 

4.3 NFS客户端卸载

# umount {mount_path}