This commit is contained in:
2021-11-14 14:32:08 +08:00
parent f75ad8bedd
commit b0f6120151
152 changed files with 22219 additions and 8 deletions

88
content/post/nfs.md Normal file
View File

@@ -0,0 +1,88 @@
---
title: "Nfs 笔记"
date: 2019-10-30T00:51:22+08:00
lastmod: 2019-10-30T00:51:22+08:00
keywords: []
tags: ["nfs"]
categories: ["storage"]
---
# 环境
- 服务端 CentOS7 192.168.1.100
- 客户端 CentOS7 192.168.1.101
# 服务端
- 安装
```bash
yum install nfs-utils
systemctl enable nfs-server
systemctl start nfs-server
# rpcbind 服务自动 start 并 enable
```
- 创建配置文件
```bash
mkdir /nfs_share -p
chown -R nfsnobody.nfsnobody /nfs_share
cat > /etc/exports.d/mynfs.conf <<EOF
/nfs_share 192.168.1.0/24(rw,sync,all_squash)
EOF
```
- 重新载入配置
```bash
exportfs -r
# 查看配置
exportfs
```
# 客户端
- 安装
```bash
yum install nfs-utils
# 客户端就不需要启动 nfs 服务了
# rpcbind 服务自动 start 并 enable
```
- 查看服务端可用的共享目录
```bash
showmount -e 192.168.1.100
```
- 挂载服务端共享目录
```bash
# 先创建本地目录,用于挂载
mkdir /nfs_client
# 挂载远程 nfs 目录
mount -t nfs 192.168.1.100:/nfs_share /nfs_client
```
# 通信过程
- 首先服务器端启动 RPC 服务,并开启 111 端口
- 服务器端启动 NFS 服务,并向 RPC 注册端口信息
- **注:该端口是用来传输数据的,目前不知道 NFS 选择该端口的依据,如果是随机的,防火墙如何放行?**
- 客户端启动 RPC 服务,向服务端的 RPC 服务请求服务端的 NFS 端口
- 服务端的 RPC 服务反馈 NFS 端口信息给客户端
- 客户端通过获取的 NFS 端口来建立和服务端的 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 映射匿名用户 nfsnobody适合公用目录
no_all_squash | 保留共享文件的 UID 和 GID(默认)
root_squash | root 用户的所有请求映射成如 anonymous 用户一样的权限(默认)
no_root_squash | root 用户具有根目录的完全管理访问权限
anonuid=xxxx | 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 UID
anongid=xxxx | 指定 nfs 服务器 /etc/passwd 文件中匿名用户的 GID
# 参考
- [https://www.linuxidc.com/Linux/2019-07/159479.htm](https://www.linuxidc.com/Linux/2019-07/159479.htm)