精读笔记(RHCA 英文教材)· RH358 Chapter 10 Providing File-based Network Storage
精读笔记(RHCA 英文教材)· RH358 Chapter 10 Providing File-based Network Storage
教材原文:RHCA 官方英文教材(教材第 25~27 页)(OCR 整书版已从本站移除,本页为章节精读) 说明:本手册文字层到第 11 章日程页为止;第 10 章起(NFS/SMB)按“讲义要点 + 必要补充”双语整理(细节参考 RHEL8 官方文档与 smb.conf(5) 手册)。 关联知识:RHCE9 精读存储/服务类章节、RH358 Ch8(服务自动化模块组合)、RH358 Ch1(systemd);注意 RH358 第 10~11 章主题为“文件级/块级网络存储”,与第 12 章复习衔接。
Chapter 10 | Providing File-based Network Storage(提供基于文件的网络存储)
- 一句话目标:Provide simple file-based network shares to clients using the NFS and SMB protocols.(用 NFS 与 SMB 协议向客户端提供简单的文件级网络共享)
Chapter Objectives(本章目标,双语)
By the end of this chapter, students should be able to:
- Export file systems for network clients using the NFS protocol, restricting access based on source IP addresses.(用 NFS 协议导出文件系统给网络客户端,并按源 IP 限制访问)
- Share file systems to network clients using the SMB protocol.(用 SMB 协议向网络客户端共享文件系统)
- Automate configuration of network file systems using NFS and SMB.(用 Ansible 自动化 NFS/SMB 网络文件系统配置)
Chapter Schedule(课时表,共 140 分钟)
| Section | 主题 | 方法(P:Lecture / A:Guided Exercise) |
|---|---|---|
| 1 | Exporting NFS File Systems | P 15 分钟 + A 15 分钟 |
| 2 | Providing SMB File Shares | P 30 分钟 + A 20 分钟 |
| 3 | Automating File-based Storage Provisioning | P 10 分钟 + A 15 分钟 |
| - | Lab Review(Performance Checklist) | 35 分钟 |
Key Takeaways(本章要点 8 条)
NFS exports are declared in /etc/exports or /etc/exports.d/.exports files on the NFS server.(NFS 导出声明写在服务器 /etc/exports 或 /etc/exports.d/.exports) The nfs-utils package is required on both the NFS server and NFS clients.(nfs-utils 在 NFS 服务器与客户端都要装) Directories shared using SMB must have the SELinux samba_share_t context type.(SMB 共享目录的 SELinux 上下文必须是 samba_share_t) The Samba configuration file is /etc/samba/smb.conf.(Samba 配置文件是 /etc/samba/smb.conf) The smbpasswd -a command adds users to the Samba database.(smbpasswd -a 把用户加入 Samba 数据库) The samba package is required on Linux SMB servers. The cifs-utils package is required on Linux clients to mount SMB shares.(Linux SMB 服务器装 samba;客户端挂载 SMB 共享装 cifs-utils) The credentials mount option points to a file that provides the user name and password for SMB authentication.(mount 的 credentials 选项指向一个存用户名/密码的文件) To access an SMB share that uses the multiuser mount option with minimal default credentials, users must run the cifscreds add command to authenticate with their SMB credentials for the current session.(multiuser 挂载 + 最小默认凭据时,用户须用 cifscreds add 以本人 SMB 凭据认证当前会话) 中文归纳考点:① NFS 导出文件 /etc/exports(.d);② 服务端客户端都装 nfs-utils;③ SMB 共享目录 SELinux=samba_share_t;④ Samba 配置 smb.conf;⑤ smbpasswd -a 建 Samba 用户;⑥ 服务端 samba / 客户端 cifs-utils;⑦ 挂载 credentials 文件;⑧ multiuser + cifscreds add。
Instructor Tips and Suggestions(讲师提示原文要点)
- nfsnobody 没了(考点):RHEL8 已不存在
nfsnobody用户,系统改用nobody用户做匿名映射。 - NFSv4 聚焦:本章聚焦 NFS 版本 4,不讲旧版本的防火墙细节(NFSv3 等需要 rpcbind/多端口的配置,学生手册参考区有 KB 链接);Red Hat Customer Portal Labs 提供 NFS 配置工具(access.redhat.com/labs/nfshelper/)。
- nmbd 不再使用(考点):SMB 一节不再讨论/启动
nmbd服务(它提供 NetBIOS 主机名解析;NetBIOS 是过时不安全协议,Windows 2000+ 没有它也能工作)。 - 命名口径:CIFS 等价于 SMB 第一版,现在应叫 SMB 而非 CIFS;
smb.conf(5)手册在server max protocol指令下列出了各 SMB 版本兼容的 Windows 发行版。 - 自动化口径:没有专用 Ansible 模块部署 NFS/SMB;讲义与练习用标准模块(yum、service、firewalld、copy)。(补充:官方另有 rhel-system-roles.nfs 系统角色,课程未展开,可自研参考。)
补充精讲 A:NFS 导出与客户端(Section 1 对应知识)
- 包:服务端与客户端都需 nfs-utils(服务端另由 nfs-server 服务提供)。
- 服务:
systemctl enable --now nfs-server;导出后exportfs -r(重读导出表)。 - 导出文件(Key Takeaway 1):
/etc/exports或/etc/exports.d/*.exports(后者被主文件 include)。语法:# /etc/exports.d/shares.exports /srv/nfs/data 192.168.100.0/24(rw,sync) 10.0.0.5(rw,no_root_squash) /srv/nfs/iso 10.0.0.0/8(ro,sync)- 访问限制=按源 IP写在导出行括号里:主机 IP 或网段;
- 选项:
ro/rw、sync/async、root_squash(默认把 root 压成 nobody)/no_root_squash、no_wdelay等; - nobody 映射(讲师 Tip):匿名访问映射到
nobody(RHEL8 无 nfsnobody)。
- 防火墙:NFSv4 只需放行
nfs服务(2049/tcp)即可(RHEL8 用 nfs-server 内建 rpc 绑定无需额外端口;旧版本才需要更多——讲师 Tip 说明本章不讲)。 - 查看/验证:
exportfs -v(当前导出及选项)、showmount -e server(列出导出);ss -lntp | grep 2049。 - 客户端挂载:fstab 持久化:
dnf install -y nfs-utils # 客户端也要 mkdir -p /mnt/data mount -t nfs4 server:/srv/nfs/data /mnt/data # 或 mount server:/srv/nfs/data /mnt/dataserver:/srv/nfs/data /mnt/data nfs4 defaults,_netdev 0 0;_netdev防止无网络时阻塞开机。 - 排障:
rpcinfo -p server、查看 /var/log/messages、SELinux 布尔(NFS 客户端/服务端布尔如nfs_export_all_rw默认开)。
补充精讲 B:SMB 共享(Section 2 对应知识)
- 包:服务器 samba;Linux 客户端 cifs-utils(Key Takeaway 6)。服务:
systemctl enable --now smb(RHEL8 无需 nmbd——讲师 Tip)。 - 配置文件 /etc/samba/smb.conf(Key Takeaway 4);
testparm校验语法;smbclient -L //server -U user列共享。 - 共享段示例:
[data] path = /srv/samba/data valid users = ops, alice write list = ops read only = no browseable = yes - SELinux(Key Takeaway 3,考点):SMB 共享的目录上下文必须是 samba_share_t:防火墙放行:
semanage fcontext -a -t samba_share_t "/srv/samba/data(/.*)?" restorecon -Rv /srv/samba/datafirewall-cmd --permanent --add-service=samba && firewall-cmd --reload(含 137-138/udp 与 139、445/tcp 的服务集)。 - Samba 用户(Key Takeaway 5):Samba 用自己数据库里的用户认证——用户须先存在于系统(useradd),再用
smbpasswd -a user加入 Samba 数据库并设 SMB 密码。 - 客户端挂载:密码交互输入,或写凭据文件(Key Takeaway 7):
mount -t cifs //server/data /mnt/data -o username=opscredentials=/etc/samba/creds,文件内容两行username=ops、password=xxxx,并chmod 600。 - multiuser(Key Takeaway 8,考点):
multiuser挂载用最小默认凭据先挂上,真正访问时各用户须先认证本人身份:# root 挂载:mount -t cifs //server/data /mnt/data -o multiuser,username=guest,... cifscreds add server # 普通用户输入自己的 SMB 凭据(本会话有效) cifscreds list / cifscreds clear - 术语:CIFS=旧 SMB1 称呼,现在统一叫 SMB(讲师 Tip)。
补充精讲 C:用 Ansible 自动化文件存储(Section 3 对应知识)
- 教学口径(讲师 Tip):没有专用模块“部署 NFS/SMB” → 沿用标准模块组合 yum / service / firewalld / copy(与 RH358 Ch7/Ch8/Ch9 完全同思路):handlers:NFS 用
# 思路示例(非讲义原文) - name: Install NFS / Samba packages dnf: name={{ item }} state=present loop: [nfs-utils, samba] # 客户端场景装 nfs-utils / cifs-utils - name: Deploy /etc/exports.d or smb.conf copy: src: "{{ item.src }}" dest: "{{ item.dest }}" notify: reload storage services - name: Open firewall services firewalld: service={{ item }} permanent=yes state=enabled loop: [nfs, samba]exportfs -r或 reload nfs-server;Samba 用systemctl reload smb。 - 需要 root 级动作的注意点:SMB 用户密码用
smbpasswd -a(无标准模块,走command/expect或预置 smbpasswd 文件);SELinux 上下文用community.general.selinux或 semanage 命令 + restorecon 收尾。 - 可选补充(课程外):官方 rhel-system-roles.nfs 角色可声明式配置 exports,红帽支持;本课程练习按 yum/service/firewalld/copy 写法。
- 章节 Lab(推断口径,手册仅给 35 分钟计时):配一台 NFS 服务器导出目录(按源 IP 限制)+ 一台 Samba 服务器共享目录(samba_share_t + smbpasswd 用户),客户端分别挂载验证读写;再写 playbook 复现(对应 Objectives 三条)。
命令速查表
| 命令/文件 | 用途 |
|---|---|
dnf install nfs-utils | NFS 服务端+客户端通用包 |
systemctl enable --now nfs-server | 启动 NFS 服务 |
/etc/exports、/etc/exports.d/*.exports | NFS 导出声明(含源 IP 与选项) |
exportfs -v / -r | 查看导出 / 重读导出表 |
showmount -e server | 列出服务器导出的共享 |
mount -t nfs4 server:/path /mnt | 客户端挂载 NFSv4 |
dnf install samba / cifs-utils | SMB 服务器 / 客户端包 |
/etc/samba/smb.conf + testparm | Samba 配置与语法校验 |
smbpasswd -a user | 把系统用户加入 Samba 数据库 |
semanage fcontext -a -t samba_share_t ... + restorecon | 共享目录 SELinux 上下文 |
firewall-cmd --add-service={nfs,samba} | 放行 NFS(2049)/Samba 服务集 |
mount -t cifs //server/share /mnt -o credentials=/path | 客户端挂载 SMB(凭据文件) |
-o multiuser + cifscreds add/list/clear | multiuser 挂载与会话级认证 |
smbclient -L //server -U user | 列 SMB 共享 |
| yum/service/firewalld/copy(+handler) | 文件存储自动化标准模块组合 |
核心词汇表
| 英文 | 中文速记 |
|---|---|
| NFS | 网络文件系统(v4 为本课程焦点) |
| export / /etc/exports(.d) | 导出声明(目录 + 源 IP + 选项) |
| nfs-utils | NFS 服务端/客户端通用包 |
| nfs-server | systemd 服务名 |
| nobody | RHEL8 匿名映射用户(nfsnobody 已取消) |
| root_squash / no_root_squash | root 是否压成 nobody |
| exportfs -v / showmount -e | 查看导出 / 列服务器共享 |
| SMB(CIFS 旧称) | 文件共享协议族(Windows/Linux 互通) |
| samba / cifs-utils | SMB 服务器包 / Linux 客户端挂载包 |
| /etc/samba/smb.conf | Samba 主配置([share] 段) |
| smbpasswd -a | 加入 Samba 用户数据库 |
| samba_share_t | SMB 共享目录 SELinux 上下文 |
| testparm / smbclient | 配置校验 / 客户端工具 |
| credentials= | 挂载选项:指向含 username/password 的文件 |
| multiuser | 多用户挂载(最小默认凭据 + 按用户认证) |
| cifscreds add | multiuser 下用户会话级 SMB 认证 |
| nmbd / NetBIOS | 已弃用服务/协议(不再启动) |
| yum/service/firewalld/copy | 自动化部署标准模块组合 |
本章自测
- NFS 导出声明写在哪两个文件?按源 IP 限制访问是在哪一部分写的、举例一个含网段与选项的导出行?
- nfs-utils 装一边够吗?为什么?RHEL8 上匿名 root 请求被映射成哪个用户?
- NFSv4 在防火墙只需放行什么?讲师为什么说“不讲旧版本防火墙细节”?
- SMB 服务器/客户端分别装什么包?RHEL8 为什么不再启动 nmbd?
- Samba 共享目录为什么必须标 samba_share_t?写出 semanage+restorecon 两条命令。
- Samba 用户认证与系统用户是什么关系?smbpasswd -a 做了什么?
- 客户端用凭据文件挂载 SMB 的完整命令?凭据文件里写什么、权限建议多少?
- multiuser 挂载的机制是什么?普通用户访问前必须执行哪条命令?
- “CIFS 与 SMB”是什么关系?现在的正确叫法?
- 自动化 NFS/SMB 用什么模块组合?为什么没有专用部署模块?对照 Objectives 三条列出 Lab 推断要做的三件事。
