「iSCSI」- Internet Small Computer Systems Interface

认识

iSCSI (Internet Small Computer System Interface) 是一种基于 IP 的存储网络标准,它允许通过 TCP/IP 网络传输 SCSI 命令,使远程存储设备看起来像是本地连接的设备。

iSCSI vs. SCSI

Difference between SCSI and iSCSI

SCSI is a layer 2 deterministic channel protocol. It’s initials stand for “Small Computer Systems Interface.” It is a standard protocol for computer systems to connect to storage systems. SCSI protocol runs on Fibre Channel (called fibre channel protocol or FCP), Infiniband, and layer 2 Ethernet.

ANSI, SNIA, and the IEEE working groups mapped the SCSI protocol to TCP/IP to enable the SCSI protocol to work on layer 3 TCP/IP Ethernet. This standard is called iSCSI.

iSCSI is the SCSI protocol mapped to TCP/IP and run over standard Ethernet technologies.

组成

### iSCSI 主要组件

  1. iSCSI Initiator (发起端):客户端设备,发起存储请求
  2. iSCSI Target (目标端):服务器端,提供存储资源
  3. LUN (Logical Unit Number):目标端提供的逻辑存储单元

构造

1. Linux 环境下部署 iSCSI Target

#### 使用 targetcli 工具

# 安装必要的软件包
sudo apt-get install targetcli-fb  # Ubuntu/Debian
sudo yum install targetcli        # CentOS/RHEL

# 启动 target 服务
sudo systemctl start target
sudo systemctl enable target

# 进入 targetcli 配置界面
sudo targetcli

# 在 targetcli 中执行以下命令
/> backstores/block create name=disk1 dev=/dev/sdb  # 使用块设备
/> iscsi/ create iqn.2023-12.com.example:server     # 创建 iSCSI 目标
/> iscsi/iqn.2023-12.com.example:server/tpg1/luns create /backstores/block/disk1  # 创建 LUN
/> iscsi/iqn.2023-12.com.example:server/tpg1/acls create iqn.2023-12.com.example:client  # 设置访问控制
/> iscsi/iqn.2023-12.com.example:server/tpg1/portals create 0.0.0.0  # 监听所有 IP
/> saveconfig  # 保存配置
/> exit

#### 使用 LIO Target

# 安装
sudo apt-get install tgt  # Ubuntu/Debian
sudo yum install scsi-target-utils  # CentOS/RHEL

# 配置
sudo vi /etc/tgt/conf.d/iscsi.conf

# 添加以下内容
<target iqn.2023-12.com.example:server.target1>
	backing-store /dev/sdb
	initiator-address 192.168.1.100  # 允许连接的客户端 IP
	incominguser username password   # 认证信息(可选)
</target>

# 启动服务
sudo systemctl start tgt
sudo systemctl enable tgt

2. Linux 环境下配置 iSCSI Initiator

# 安装 initiator 软件
sudo apt-get install open-iscsi open-iscsi-utils  # Ubuntu/Debian
sudo yum install iscsi-initiator-utils           # CentOS/RHEL

# 配置 initiator 名称
sudo vi /etc/iscsi/initiatorname.iscsi
# 修改为:
InitiatorName=iqn.2023-12.com.example:client

# 发现目标
sudo iscsiadm -m discovery -t st -p 192.168.1.1

# 登录到目标
sudo iscsiadm -m node -T iqn.2023-12.com.example:server.target1 -p 192.168.1.1 -l

# 设置自动登录
sudo iscsiadm -m node -T iqn.2023-12.com.example:server.target1 -p 192.168.1.1 --op update -n node.startup -v automatic

# 查看连接的设备
lsblk

3. Windows 环境下配置 iSCSI Initiator

  1. 打开”iSCSI Initiator” (控制面板 > 管理工具)
  2. 在”发现”选项卡中,点击”发现门户”,输入目标服务器 IP
  3. 在”目标”选项卡中,选择发现的目标,点击”连接”
  4. 在”卷和设备”选项卡中,点击”自动配置”
  5. 打开”磁盘管理”,初始化和格式化新发现的磁盘

安全配置建议

  1. CHAP 认证:配置双向认证

“`bash

# Target 端配置

/> iscsi/iqn.2023-12.com.example:server/tpg1/portals create 0.0.0.0

/> iscsi/iqn.2023-12.com.example:server/tpg1 set attribute authentication=1

/> iscsi/iqn.2023-12.com.example:server/tpg1 set attribute generate_node_acls=1

/> iscsi/iqn.2023-12.com.example:server/tpg1/acls create iqn.2023-12.com.example:client

/> cd iscsi/iqn.2023-12.com.example:server/tpg1/acls/iqn.2023-12.com.example:client

/> set auth userid=username

/> set auth password=password

/> exit

# Initiator 端配置
sudo vi /etc/iscsi/iscsid.conf
# 取消注释并修改以下行:
node.session.auth.authmethod = CHAP
node.session.auth.username = username
node.session.auth.password = password
“`

  1. IP 限制:只允许特定 IP 访问目标
  2. 网络隔离:使用专用 VLAN 或网络进行 iSCSI 通信

性能优化

  1. 使用专用网络进行 iSCSI 通信
  2. 启用 Jumbo Frames (MTU 9000)
  3. 考虑使用多路径 I/O (MPIO)提高可靠性和性能
  4. 对于高性能需求,考虑使用 10GbE 或更高速网络

常见管理命令

“`bash
# 查看已连接的会话
sudo iscsiadm -m session -P 3

# 登出目标
sudo iscsiadm -m node -T iqn.2023-12.com.example:server.target1 -p 192.168.1.1 -u

# 删除目标配置
sudo iscsiadm -m node -T iqn.2023-12.com.example:server.target1 -p 192.168.1.1 -o delete

# 重新扫描目标
sudo iscsiadm -m node –rescan
“`

性质

– 使用现有 IP 网络基础设施,无需专用光纤通道
– 成本低于光纤通道 SAN
– 易于部署和管理
– 支持长距离连接

参考

Debain Wiki/SAN iSCSI
Open-iSCSI
LIO
Wikipedia/LIO
DeepSeek / 介绍 iscsi 以及部署方法