精读笔记(RHCA 英文教材)· RH358 Chapter 11 Accessing Block-based Network Storage
精读笔记(RHCA 英文教材)· RH358 Chapter 11 Accessing Block-based Network Storage
教材原文:RHCA 官方英文教材(教材第 29~30 页)(OCR 整书版已从本站移除,本页为章节精读) 说明:本手册 44 页文字层到第 12 章(复习)目标页为止;本笔记按“讲义要点 + 必要补充”双语整理(iSCSI 细节参考 RHEL8 官方文档与 targetcli/open_iscsi 手册)。 关联知识:RH358 Ch10(文件级 NFS/SMB)与本章(块级 iSCSI)构成“网络存储”两大块;RH358 Ch1(systemd);
02-08-Ansible自动化(storage 系统角色/open_iscsi 模块)。
Chapter 11 | Accessing Block-based Network Storage(访问基于块的网络存储)
- 一句话目标:Configure iSCSI initiators on your servers to access block-based storage devices provided by network storage arrays or Ceph storage clusters.(在服务器上配置 iSCSI initiator(发起端),访问网络存储阵列或 Ceph 集群提供的块设备)
Chapter Objectives(本章目标,双语)
By the end of this chapter, students should be able to:
- Provide block-based storage to network clients using the iSCSI protocol.(用 iSCSI 协议向网络客户端提供块级存储)
- Configure an iSCSI initiator to access a network-based block device, format a new iSCSI device with a file system, configure it for use at boot, and be able to safely discontinue the use of an existing iSCSI block device.(配置 iSCSI 发起端访问网络块设备;给新 iSCSI 设备建文件系统;配置开机挂载;并能安全停用既有 iSCSI 块设备)
- Automate the configuration of an iSCSI initiator on a server.(用 Ansible 自动化服务器上 iSCSI 发起端配置)
Chapter Schedule(课时表,共 100 分钟)
| Section | 主题 | 方法(P:Lecture / A:Guided Exercise) |
|---|---|---|
| 1 | Providing iSCSI Storage | P 20 分钟 + A 10 分钟 |
| 2 | Accessing iSCSI Storage | P 15 分钟 + A 10 分钟 |
| 3 | Automating iSCSI Initiator Configuration | P 10 分钟 + A 15 分钟 |
| - | Lab Review(Performance Checklist) | 20 分钟 |
Key Takeaways(本章要点 6 条)
The targetcli package provides the targetcli tool that you use to create targets.(targetcli 包提供 targetcli 工具,用它创建 target(目标端)) Configuring an iSCSI client initiator requires installing the iscsi-initiator-utils package.(配置 iSCSI 客户端发起端需装 iscsi-initiator-utils 包) The initiator IQN is defined in the /etc/iscsi/initiatorname.iscsi file.(发起端 IQN 定义在 /etc/iscsi/initiatorname.iscsi) The iscsid service must be restarted whenever you modify the /etc/iscsi/initiatorname.iscsi file.(改过 initiatorname.iscsi 后必须重启 iscsid 服务) The Ansible open_iscsi module discovers and logs in to targets.(Ansible 的 open_iscsi 模块负责发现并登录 target) The Ansible storage system role formats and persistently mounts new block devices.(Ansible 的 storage 系统角色负责给新块设备建文件系统并持久挂载) 中文归纳考点:① 服务端 targetcli 建 target;② 客户端 iscsi-initiator-utils;③ initiator IQN 文件;④ 改 IQN 必重启 iscsid;⑤ open_iscsi 模块发现+登录;⑥ rhel-system-roles.storage 格式化+持久挂载。
补充精讲 A:iSCSI 概念与服务端(Section 1 对应知识)
- 架构速记:initiator(发起端)=消费块设备的客户端(本机服务器);target(目标端)=提供块设备的服务端(存储阵列/Ceph/iSCSI server)。协议走 TCP(默认 3260/tcp)。
- RHEL8 服务端提供 iSCSI target:装
targetcli(包名即 targetcli,提供 targetcli 交互工具),用 targetcli 创建 target(backstore 磁盘 → LUN → portal 监听 → ACL 允许 initiator IQN)。 - targetcli 常用(概念,具体以实验为准):
targetcli /> backstores/block create name=disk1 dev=/dev/vdb # 用块设备做 backstore targetcli /> iscsi/ create iqn.2020-09.example.com:server1 # 建 target targetcli /> iscsi/iqn.../tpg1/luns create /backstores/block/disk1 # 挂 LUN targetcli /> iscsi/iqn.../tpg1/acls create iqn.2020-09.example.com:client1 # ACL=允许的发起端 targetcli /> saveconfig # 持久化 - 防火墙:放行 iSCSI target 端口
firewall-cmd --add-service=iscsi-target(或 3260/tcp);systemd 服务为target(rtslib 由 targetcli saveconfig 持久化)。 - 客户端视角:target 对外公布自己的 target IQN 与 IP:3260;发起端要“发现(discovery)→ 登录(login)”后才能看到 /dev/sdX 新盘。
补充精讲 B:客户端访问 iSCSI(Section 2 对应知识)
- 客户端安装:
dnf install -y iscsi-initiator-utils(提供 iscsiadm、iscsid、开机服务)。 - initiator IQN(Key Takeaway 3):写在
/etc/iscsi/initiatorname.iscsi(InitiatorName=iqn....);IQN 即“发起端身份证”,target 的 ACL 按它放行。 - 改完必重启(Key Takeaway 4,考点):修改 initiatorname.iscsi 后必须
systemctl restart iscsid(iscsid 启动时读取该文件)。 - 发现与登录:
iscsiadm -m discovery -t st -p 192.0.2.10 # 发现 target(sendtargets) systemctl enable --now iscsid iscsiadm -m node -T iqn.2020-09.example.com:server1 -p 192.0.2.10 --login # 登录 target lsblk # 出现新的块设备(如 /dev/sda) - 用盘与持久化:对新盘分区/建文件系统(
mkfs.xfs /dev/sda1)、systemctl enable --now iscsi(登录自动恢复)、fstab 持久挂载(注意_netdev);教科书口径是“格式化 + 开机可用 + 安全停用”。 - 安全停用既有 iSCSI 设备(考点流程):先卸载文件系统(umount)→
iscsiadm -m node -T <iqn> -p <ip> --logout登出 → (可选)从 node 记录删除iscsiadm -m node -T <iqn> -p <ip> --op=delete→ 确认 /dev 设备消失;fstab/自动挂载条目同步清理,避免开机失败。 - 相关服务/文件速记:
iscsid(守护)、iscsi(开机自动登录)、/etc/iscsi/、/var/lib/iscsi/(node 记录)。
补充精讲 C:用 Ansible 自动化(Section 3 对应知识)
- 发现/登录(Key Takeaway 5,考点):用 open_iscsi 模块(发现并登录 target,管理 node 记录):
# 思路示例(非讲义原文) - name: Discover and login to target open_iscsi: portal: 192.0.2.10:3260 target: iqn.2020-09.example.com:server1 state: present # login;logout 用 absent node: "{{ ansible_facts['hostname'] }}" # initiatorname 与开机自启可配:initiator_name / auto_node_startup - 格式化 + 持久挂载(Key Takeaway 6,考点):用官方 storage 系统角色(rhel-system-roles.storage / linux-system-roles.storage)给新块设备建文件系统并写进 fstab 持久挂载——声明式声明磁盘/文件系统/mount,角色幂等处理:
# 思路示例(非讲义原文) - hosts: servers roles: - role: rhel-system-roles.storage vars: storage_pools: - name: data disks: [/dev/sda1] volumes: - name: data1 size: 10g format: xfs mount_point: /mnt/data - 自动化全链路:装
iscsi-initiator-utils(dnf)→ 配/etc/iscsi/initiatorname.iscsi(template +systemctl restart iscsid)→ open_iscsi 发现登录 → storage 角色格式化/挂载;卸载场景反向 absent/删除。 - 章节 Lab(推断口径,手册仅给 20 分钟计时):一台服务器当 iSCSI target(targetcli 建 target + ACL),另一台当 initiator(改 IQN/发现/登录/建 xfs/持久挂载/验证重启);再写 playbook 自动化 initiator 配置(对应 Objectives 三条)。
命令速查表
| 命令/文件 | 用途 |
|---|---|
dnf install targetcli | 服务端:安装 iSCSI target 管理工具 |
targetcli(backstores/iscsi/luns/acls/saveconfig) | 服务端建 target 与授权 |
firewall-cmd --add-service=iscsi-target | 放行 3260/tcp |
dnf install iscsi-initiator-utils | 客户端发起端包 |
/etc/iscsi/initiatorname.iscsi | 定义 initiator IQN(InitiatorName=…) |
systemctl restart iscsid | 改 IQN 文件后必须重启 |
iscsiadm -m discovery -t st -p <ip> | 发现 target |
iscsiadm -m node -T <iqn> -p <ip> --login | 登录 target(lsblk 出现新盘) |
systemctl enable --now iscsi | 开机自动重新登录 |
mkfs.xfs /dev/sda1 + fstab(_netdev) | 建文件系统 + 开机持久挂载 |
iscsiadm -m node -T <iqn> -p <ip> --logout(+--op=delete) | 安全停用/删除 node 记录 |
| open_iscsi 模块(portal/target/state) | Ansible 发现并登录/登出 |
| rhel-system-roles.storage(storage_pools) | 格式化并持久挂载(fstab) |
核心词汇表
| 英文 | 中文速记 |
|---|---|
| iSCSI | 基于 TCP(3260) 的块存储协议 |
| initiator | 发起端(客户端,消费块设备) |
| target | 目标端(服务端,提供块设备) |
| targetcli | 服务端建 target 的工具/包 |
| backstore / LUN / portal / ACL | targetcli 概念:后端存储 / 逻辑单元 / 监听口 / 允许的发起端 |
| iscsi-initiator-utils | 客户端包(iscsiadm/iscsid) |
| IQN | iSCSI Qualified Name(发起端/目标端身份证) |
| initiatorname.iscsi | 发起端 IQN 配置文件 |
| iscsid | 客户端守护服务(改 IQN 后重启) |
| discovery / login / logout | 发现 / 登录 / 登出 target |
| node record(/var/lib/iscsi/) | 已发现 target 的记录 |
| iscsi service | 开机自动恢复登录的服务 |
| open_iscsi(模块) | Ansible 发现+登录 target |
| rhel-system-roles.storage | 格式化+持久挂载的系统角色(storage_pools) |
| _netdev | fstab 网络设备挂载选项(开机先等网络) |
本章自测
- iSCSI 里 initiator 与 target 各是谁?默认走哪个端口?
- 服务端建 iSCSI target 的包/工具是什么?targetcli 里“给 target 指定允许的发起端”用哪个命令层级?
- 客户端要装什么包?“发起端 IQN”写在哪?为什么改完必须重启 iscsid?
- 发现与登录 target 的 iscsiadm 命令分别怎么写?登录成功后用什么命令确认新盘出现?
- 新 iSCSI 盘“开机可用”要做哪几件事(文件系统/服务/fstab 选项)?
- 安全停用一块既有 iSCSI 设备的完整顺序?漏删 fstab 会有什么后果?
- 自动化“发现并登录 target”用哪个模块?它能不能管开机自动登录?
- “格式化并持久挂载”推荐用哪个角色?storage_pools 表达哪几层信息?
- 对照 Key Takeaways:哪一条对应“服务端”、哪三条对应“客户端手工”、哪两条对应“自动化”?
- 把 Objectives 三条与 Key Takeaways 六条配对;用自己的话讲“为什么 IQN 是 target 的访问控制依据”。
