跳转至

网络挂载磁盘 (iSCSi)

网络挂载磁盘 (iSCSI)

iSCSI is an IP-based standard for transferring data that supports host access by carrying SCSI commands over IP networks. The iSCSI standard is defined by RFC 3720. (iSCSI overview - IBM Documentation)

使用 iSCSI 可以将远程服务器上的存储设备映射为本地的一个块设备

服务端 (target)

查了一圈,没有找到在 windows 上开启 iSCSI target 的教程

ubuntu20.04

  1. 安装

    sudo apt install tgt
    

    此时已经可以看到 iSCSI 服务启动了

    systemctl status tgt
    
  2. 配置 target

    新建一个 target1.conf 文件

    vim /etc/tgt/conf.d/target1.conf
    

    配置如下

    <target iqn.2020-05.com:tianyi310.target1>
        # provided devicce as a iSCSI target
        backing-store /dev/sda1
        # iSCSI Initiator's IQN you allow to connect
        initiator-name iqn.2022-02.com:s3-pro
        initiator-name iqn.2022-02.com:ryzen5800x
        # authentication info ( set anyone you like for "username", "password" )
        #incominguser user password
    </target>
    
<target iqn.2023-10.com:ryzen.target1>
     # provided devicce as a iSCSI target
     backing-store /dev/disk/by-id/scsi-0QEMU_QEMU_HARDDISK_drive-scsi4
     # iSCSI Initiator's IQN you allow to connect
     initiator-name iqn.2023-10.com:a1-win10
     # authentication info ( set anyone you like for "username", "password" )
     #incominguser user password
 </target>

其中 iqn.2020-05.com:tianyi310.target1 为 target 名称,有着规范的格式 iqn.1991-05.com.microsoft:kvm-win10

存储设备

backing-store /dev/sda1表示使用 sda1 作为存储设备(第一个磁盘 (sda) 上的第一个分区 (sda1))

支持的存储设备:

  • 块设备
  • 块设备上的一个分区
  • 一个文件作为虚拟的块设备,如

    #create folder and file
    mkdir /var/lib/iscsi_disks
    dd if=/dev/zero of=/var/lib/iscsi_disks/disk01.img count=0 bs=1 seek=10G
    

    授权

    为了简单,以上配置没有配置 authentication。几种常用授权方式:

  • initiator-name:只允许指定 iqn 名称的 initiator
  • initator-address:只允许指定 ip 的 initiator
  • user, password:没试过
  • 相互 CHAP 验证:开启后不知道怎么在 windows initiator 中对应设置,因此没试
  1. 重启 tgt 服务

    sudo systemctl restart tgt
    
  2. 查看 tgt 状态

    sudo tgtadm --mode target --op show
    

    应该可以看到关于 LUN0 和 LUN1 的配置,如果没有 LUN1 则再次重启下

客户端 (initiator)

Windows10

  1. 使用 windows 的搜索功能,搜索 open iSCSI。第一次打开可能会提示开启相关服务,确认即可

  1. 首先在配置栏修改掉默认的名称,注意区分大小写

  1. 然后在目标栏中填入 ip 地址或域名(支持 ipv6),点击快速连接。

4. 如果连接成功后,目标会显示在已发现的目标中,可以断开连接,或下次再次连接

连接成功后,进入磁盘管理,便会出现一个没有使用的磁盘,格式化即可。 image.png

image.png

连接失败

How can I troubleshoot iSCSI connection issues? (DSM 6.x) - Synology Knowledge Center

If the iSCSI Initiator cannot find an iSCSI target:

  1. In Windows iSCSI Initiator, go to
    • Specify the network interface to use for iSCSI connections if you have more than one network interfaces on both the initiator and target.
    • Make sure that Enable CHAP log on is not checked. img

If the iSCSI Initiator finds an iSCSI target but fails to connect to it:

  • Specify the network interface to use for iSCSI connections if you have more than one network interfaces on both the initiator and target.
  • Make sure that you entered identical name and password on DSM as the Name and Target secret in Windows iSCSI Initiator. img