Skip to content

主旨

  • NFS搭建配置原理
  • NFS配置详解
  • NFS一键部署整理

基础搭建

环境说明

系统角色 IP 共享目录
服务端 10.1.6.105 /home/nfsdata/
客户端 10.1.6.104 /home/nfsdata/

服务端

安装

# yum install nfs-utils
# rpm -qa | grep nfs
nfs-utils-1.3.0-0.68.el7.2.x86_64
libnfsidmap-0.25-19.el7.x86_64

配置

## 创建共享存放目录
# mkdir -p /home/nfsdata

# cat /etc/exports
## rw 读写
## sync 同步内存和磁盘,rsync数据先存内存,而非直接写入到硬盘中
## no_root_squash nfs服务端如果是root,对于服务分享的目录来说也是root
## no_all_squash 不论服务端什么用户,客户端都不会拥有匿名用户权限
## 
/home/nfsdata 10.1.6.106(rw,sync,no_root_squash)
## 更新配置
# exportfs -r

自启动

# systemctl enable rpcbind
# systemctl start rpcbind
# systemctl enable nfs
# systemctl start nfs

客户端

安装

# yum -y install nfs-utils rpcbind

自启动

# systemctl enable rpcbind --now

验证

# showmount -e 10.1.6.105
Export list for 10.1.6.105:
/home/nfsdata 10.1.6.104

临时挂载

# mount -t nfs 10.1.6.105:/home/nfsdata/ /home/nfsdata/

开机自动挂载

/etc/fstab 追加行
10.1.6.105:/home/nfsdata /home/nfsdata nfs defaults 0 0

## 执行如下命令验证挂载是否正常
# mount -a

配置详解

主要参数

参数 表示含义
10.1.6.104 客户端IP地址
/home/nfsdata/ 是需要共享的目录
/home/nfsdata 是需要共享到客户端的目录
* 表示允许所有客户端访问
rw 表示允许读写访问
sync 表示数据同步写入内存和硬盘中,保证数据的安全性
rsync 数据暂存于内存中,而非直接写入硬盘
no_root_squash 表示允许 root 用户访问共享目录
no_all_squash 不论NFS客户端连接服务端时使用什么用户,对服务端分享的目录来说都不会拥有匿名用户权限。

一键部署