如何在CentOS7上使用targetcli扩展iSCSI lun?

如何在CentOS7上使用targetcli扩展iSCSI lun?

我有一台配置了 iSCSI 的 CentOS 7 计算机。请参阅下面 targetcli 的 ls 输出。我想将disk02添加到lun0,以便iSCSI客户端可以看到总共869.16GB而不是392.2GB

问题:是否可以让 lun0 使用 disk0 和 disk1 的总容量,如果可以,如何在 CentOS7 上使用 targetcli 来实现这一点。

/> ls
o- / ....................................................................................................... [...]
  o- backstores ............................................................................................ [...]
  | o- block ................................................................................ [Storage Objects: 2]
  | | o- disk01 ...................................................... [/dev/sdb4 (392.2GiB) write-thru activated]
  | | o- disk02 ..................................................... [/dev/sda (476.9GiB) write-thru deactivated]
  | o- fileio ............................................................................... [Storage Objects: 0]
  | o- pscsi ................................................................................ [Storage Objects: 0]
  | o- ramdisk .............................................................................. [Storage Objects: 0]
  o- iscsi .......................................................................................... [Targets: 1]
  | o- iqn.2014-08.com.exmaple:nuc .................................................................... [TPGs: 1]
  |   o- tpg1 ................................................................................ [gen-acls, no-auth]
  |     o- acls ........................................................................................ [ACLs: 0]
  |     o- luns ........................................................................................ [LUNs: 1]
  |     | o- lun0 ..................................................................... [block/disk01 (/dev/sdb4)]
  |     o- portals .................................................................................. [Portals: 1]
  |       o- 0.0.0.0:3260 ................................................................................... [OK]
  o- loopback ....................................................................................... [Targets: 0]
/> 

答案1

iSCS 目标 LUN 的创建将先前定义的存储对象与目标链接起来,并定义设备将使用哪个编号。

lun0因此,如果要扩容LUN( ),则disk01需要扩容底层存储对象()。

执行此操作的一种方法是从两个磁盘创建逻辑卷,如下所示(尽管这需要中断):

删除未使用的存储对象disk02并从中创建逻辑卷:

/backstores/block> delete disk02
Deleted storage object disk02.
/backstores/block> ls
o- block ...................................................................................................... [Storage Objects: 1]
  o- disk01 .............................................................................. [/dev/sdb4 (392.2GiB) write-thru activated]
/backstores/block>

iscsi_lv01使用整个设备创建逻辑卷 ( ):

$ pvcreate /dev/sda
  Physical volume "/dev/sda" successfully created
$ vgcreate iscsi_disk01 /dev/sda
  Volume group "iscsi_disk01" successfully created
$ lvcreate iscsi_disk01 -l 100%FREE -n iscsi_lv01
  Logical volume "iscsi_lv01" created

笔记:
显然,如果现有设备已格式化并包含数据,则必须对该新卷进行格式化并将数据复制到其上。

使用新卷创建新存储对象:

$ targetcli
/backstores/block> create iscsi_lv01 /dev/iscsi_disk01/iscsi_lv01
Created block storage object iscsi_lv01 using /dev/iscsi_disk01/iscsi_lv01.
/backstores/block> ls
o- block ...................................................................................................... [Storage Objects: 2]
  o- disk01 .............................................................................. [/dev/sdb4 (392.2GiB) write-thru activated]
  o- iscsi_lv01 .................................................... [/dev/iscsi_disk01/iscsi_lv01 (476.9GiB) write-thru deactivated]
/backstores/block>

lun0使用新卷重新创建

/> cd iscsi/iqn.2014-08.com.exmaple:nuc/tpg1/luns/
/iscsi/iqn.20...nuc/tpg1/luns> delete lun0
Deleted LUN 0.
/iscsi/iqn.20...nuc/tpg1/luns> create /backstores/block/iscsi_lv01
Created LUN 0.
/iscsi/iqn.20...nuc/tpg1/luns> ls
o- luns .................................................................................................................. [LUNs: 1]
  o- lun0 ........................................................................ [block/iscsi_lv01 (/dev/iscsi_disk01/iscsi_lv01)]
/iscsi/iqn.20...nuc/tpg1/luns>

删除现有的存储对象disk01,然后将其添加到卷组中:

/> cd backstores/block/
/backstores/block> delete disk01
Deleted storage object disk01.
/backstores/block> cd /
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_lv01 .................................................. [/dev/iscsi_disk01/iscsi_lv01 (476.9GiB) write-thru activated]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2014-08.com.exmaple:nuc ....................................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 0]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ................................................................ [block/iscsi_lv01 (/dev/iscsi_disk01/iscsi_lv01)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]

保存新配置以防万一auto_save_on_exit未设置为 true:

/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

使用原始设备扩展现有逻辑卷disk01

$ pvcreate /dev/sdb4
  Physical volume "/dev/sdb4" successfully created
$ vgextend iscsi_disk01 /dev/sdb4
  Volume group "iscsi_disk01" successfully extended
$ lvextend -l 100%VG /dev/iscsi_disk01/iscsi_lv01
  Extending logical volume iscsi_lv01 to 869.1GiB
  Logical volume iscsi_lv01 successfully resized
$

笔记:
disk01如果卷需要格式化,则添加 后还需要调整文件系统大小的额外步骤。

注意新大小的存储对象:

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- iscsi_lv01 .................................................. [/dev/iscsi_disk01/iscsi_lv01 (869.1GiB) write-thru activated]

遗憾的是,此方法在调整 lun 大小时需要停机时间,但是,遵循此方法将确保停机时间保持在最低限度。

参考

维基百科
使用 tgtadm 的 iSCSI 目标指南

相关内容