配置 iSCSI 启动器

要配置 iSCSI Initiator ,需要安装 iscsi-initiator-utils 包。

[root@desktop1 ~]# yum install -y iscsi-initiator-utils

我们可以确认 iSCSI Initiator 的 iqn,我们在 iSCSI Target 配置期间使用来创建 ACL。

[root@desktop1 ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:31532b60ee10

启动并启用 iSCSI 服务。

[root@desktop1 ~]# systemctl enable iscsi ; systemctl start iscsi

在 192.168.1.11 发现可用的 iSCSI 目标。

[root@desktop1 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.11
192.168.1.11:3260,1 iqn.2018-07.com.example.server1:remotedisk1
[root@desktop1 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk
->->sda1   8:1    0  300M  0 part /boot
->->sda2   8:2    0  1.5G  0 part [SWAP]
->->sda3   8:3    0 18.2G  0 part /
sr0     11:0    1  3.5G  0 rom  /mnt/iso
[root@desktop1 ~]# systemctl restart iscsi
[root@desktop1 ~]# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   20G  0 disk
->->sda1   8:1    0  300M  0 part /boot
->->sda2   8:2    0  1.5G  0 part [SWAP]
->->sda3   8:3    0 18.2G  0 part /
sdb      8:16   0   20G  0 disk
sr0     11:0    1  3.5G  0 rom  /mnt/iso

我们的 iSCSI 目标磁盘已成功发现为 /dev/sdb 。
让我们创建一个分区和文件系统。

[root@desktop1 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x08f4940d.
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (8192-41940991, default 8192):
Using default value 8192
Last sector, +sectors or +size{K,M,G} (8192-41940991, default 41940991):
Using default value 41940991
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.

[root@desktop1 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 21.5 GB, 21473787904 bytes, 41940992 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 4194304 bytes
Disk label type: dos
Disk identifier: 0x08f4940d
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            8192    41940991    20966400   83  Linux
[root@desktop1 ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=16, agsize=327600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=5241600, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

现在,将分区永久挂载在 /mnt/remotedisk1 。

[root@desktop1 ~]# echo "/dev/sdb1 /mnt/remotedisk1 xfs _netdev 0 0" >> /etc/fstab
[root@desktop1 ~]# mount -a
[root@desktop1 ~]# mount | grep /mnt/remotedisk1
/dev/sdb1 on /mnt/remotedisk1 type xfs (rw,relatime,seclabel,attr2,inode64,noquota,_netdev)

我们已经成功创建了一个 iSCSI Target,然后将它持久地挂载到我们的 iSCSI Initiator。

配置环境

iSCSI 服务器

主机名: server1.onitroad.com
IP地址:192.168.1.11/24
操作系统: CentOS 7

iSCSI 启动器

主机名:desktop1.onitroad.com
IP地址:192.168.1.12/24
操作系统: CentOS 7

在 CentOS 7 中配置 iSCSI Target/Initiator

在这篇文章中,我们将在 CentOS 7 上配置 iSCSI 目标服务器,然后将该 iSCSI 目标持久地挂载到 iSCSI 启动器上。

iSCSI(Internet 小型计算机系统接口)是一种用于通过 IP 网络基础结构链接数据存储设备的协议。

iSCSI target(目标)

iSCSI target通常是专用的网络连接硬盘存储设备,但也可能是通用计算机。
几乎所有现代主流服务器操作系统(如 BSD、Linux、Solaris 或者 Windows Server)都可以提供 iSCSI 目标功能,作为内置功能或者补充软件。
提供 iSCSI 目标的计算机称为 iSCSI 服务器。

iSCSI initiator(启动器)

iSCSI initiator是 iSCSI 客户端。
iSCSI 启动器通常为计算机提供与 SCSI 总线适配器相同的用途,不同之处在于,iSCSI 启动器通过 IP 网络发送 SCSI 命令,而不是物理连接 SCSI 设备(如硬盘驱动器和磁带转换器)。

on it road .com

配置 iSCSI 目标

我们有一个备用硬盘 (20 GB) 可用。
我们使用 fdisk 其中创建了一个分区 (20GB) 以使其可供 iSCSI Server 使用。

[root@server1 ~]# fdisk -l /dev/sdb
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x94c52e45
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    41943039    20970496   83  Linux

我们需要 targetcli 包来配置 iSCSI Target。

[root@server1 ~]# yum install -y targetcli

现在获取一个 targetcli shell。

[root@server1 ~]# targetcli
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/>

检查当前 iSCSI 目标配置的状态。

/> ls
o- / ..................................................................... [...]
  o- backstores .......................................................... [...]
  | o- block .............................................. [Storage Objects: 0]
  | o- fileio ............................................. [Storage Objects: 0]
  | o- pscsi .............................................. [Storage Objects: 0]
  | o- ramdisk ............................................ [Storage Objects: 0]
  o- iscsi ........................................................ [Targets: 0]
  o- loopback ..................................................... [Targets: 0]
/>

在 targetcli shell 中,使用以下命令创建存储块。

/> cd backstores/block/
/backstores/block> create block1 /dev/sdb1
Created block storage object block1 using /dev/sdb1.
/backstores/block> ls
o- block .................................................. [Storage Objects: 1]
  o- block1 ....................... [/dev/sdb1 (20.0GiB) write-thru deactivated]

创建 TPG(目标portal组)。

/backstores/block> cd /iscsi
/iscsi> create iqn.2018-07.com.example.server1:remotedisk1
Created target iqn.2018-07.com.example.server1:remotedisk1.
Created TPG 1.
/iscsi> ls
o- iscsi .......................................................... [Targets: 1]
  o- iqn.2018-07.com.example.server1:remotedisk1 ..................... [TPGs: 1]
    o- tpg1 ............................................. [no-gen-acls, no-auth]
      o- acls ........................................................ [ACLs: 0]
      o- luns ........................................................ [LUNs: 0]
      o- portals .................................................. [Portals: 0]
/iscsi>

从客户端机器获取客户端 iqn (iSCSI Qualified Name) 并使用它来创建一个 ACL ,以限制 desktop1.onitroad.com 机器对我们的 iSCSI Target 的访问。

/iscsi> cd /iscsi/iqn.2018-07.com.example.server1:remotedisk1/tpg1/acls
/iscsi/iqn.20...sk1/tpg1/acls> create iqn.1994-05.com.redhat:31532b60ee10
Created Node ACL for iqn.1994-05.com.redhat:31532b60ee10
/iscsi/iqn.20...sk1/tpg1/acls> ls
o- acls .............................................................. [ACLs: 1]
  o- iqn.1994-05.com.redhat:31532b60ee10 ...................... [Mapped LUNs: 1]
    o- mapped_lun0 .................................... [lun0 block/block1 (rw)]
/iscsi/iqn.20...sk1/tpg1/acls>

创建 LUN(逻辑单元号)。

/iscsi/iqn.20...sk1/tpg1/acls> cd /iscsi/iqn.2018-07.com.example.server1:remotedisk1/tpg1/luns
/iscsi/iqn.20...sk1/tpg1/luns> create /backstores/block/block1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.1994-05.com.redhat:31532b60ee10
/iscsi/iqn.20...sk1/tpg1/luns> ls
o- luns .............................................................. [LUNs: 1]
  o- lun0 ........................................... [block/block1 (/dev/sdb1)]
/iscsi/iqn.20...sk1/tpg1/luns>

立即创建portal。

/iscsi/iqn.20...sk1/tpg1/luns> cd /iscsi/iqn.2018-07.com.example.server1:remotedisk1/tpg1/portals
/iscsi/iqn.20.../tpg1/portals> create 192.168.1.11
Using default IP port 3260
Created network portal 192.168.1.11:3260.
/iscsi/iqn.20.../tpg1/portals> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
[root@server1 ~]#

允许端口 3260/tcp 通过防火墙。

[root@server1 ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@server1 ~]# firewall-cmd --reload
success

启动并启用目标服务。

[root@server1 ~]# systemctl enable target ; systemctl start target
ln -s '/usr/lib/systemd/system/target.service' '/etc/systemd/system/multi-user.target.wants/target.service'

iSCSI 目标已成功配置。

日期:2020-09-17 00:12:28 来源:oir作者:oir