天天看點

iscsi target 之LIO配置

LIO 配置

現在主流Linux都可以設定iSCSI,如STGT/TGT、LIO Target等。Linux-IO(LIO)Target是目前Linux标準的iSCSI target的開源實作,包含在Linux核心(2.6.38後)中。LIO不發起會話,而是提供LUNs,等待來自SCSI initiator的指令并進行所需的I/O資料傳輸。更詳細的參考:http://en.wikipedia.org/wiki/LIO_Target

設定一個target,包含以下元件:

儲存設備:使用Linux作為target,可以使用LVM邏輯卷來作為底層儲存設備,也可以使用其他儲存設備,如分區、硬碟、稀疏檔案等。

LUN ID:每個通過iSCSI target共享的儲存設備是當做一個LUN來共享,每個LUN都有一個唯一ID。

Target ID:如果想要授權target連接配接到特定節點,建立不同的target,每個target有自己的target ID,也稱為IQN(Internet Qualifiied Name)。iSCSI用戶端使用IQN來進行連接配接。

Identifier:辨別符用來識别特定的iSCSI target。

端口号:target監聽的TCP端口,預設是3260。

CentOS7上使用targetcli指令來設定iSCSI target.

# systemctl enable target.service  
# systemctl start target.service  
           

targetcli支援不同的後端存儲,當建立iSCSI磁盤時,必須指定後端存儲類型。targetcli來檢視可用的後端存儲。

[root@node114 lib]# targetcli 
targetcli shell version 2.1.fb37
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> 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]
           

添加LVM,使用指令“/backstores/fileio create lun1 /opt/disk1.img 1.5T”可以添加一個稀疏檔案的target,

添加裸盤,則"/backstores/block create lun1 /dev/sdb"

/> /backstores/fileio create lun0  /var/lib/iscsi.img 1500G
Created fileio lun0 with size 1610612736000
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- lun0 ................................................................. [/var/lib/iscsi.img (1.5TiB) write-back deactivated]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]
           

定義target

/> /iscsi create
Created target iqn.2003-01.org.linux-iscsi.node114.x8664:sn.1fd7d0e50a51.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
           
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- lun0 ................................................................. [/var/lib/iscsi.img (1.5TiB) write-back deactivated]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2003-01.org.linux-iscsi.node114.x8664:sn.1fd7d0e50a51 ......................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 0]
  |     o- luns .......................................................................................................... [LUNs: 0]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
           
/> cd /iscsi/iqn.2003-01.org.linux-iscsi.node114.x8664:sn.1d0909400c72/tpg1/
/iscsi/iqn.20...09400c72/tpg1> ls
o- tpg1 ..................................................................................................... [no-gen-acls, no-auth]
  o- acls ................................................................................................................ [ACLs: 0]
  o- luns ................................................................................................................ [LUNs: 0]
  o- portals .......................................................................................................... [Portals: 1]
    o- 0.0.0.0:3260 ........................................................................................................... [OK]
/iscsi/iqn.20...09400c72/tpg1> portals/ create  
Using default IP port 3260
Binding to INADDR_ANY (0.0.0.0)
This NetworkPortal already exists in configFS.
/iscsi/iqn.20...09400c72/tpg1> luns/ create /backstores/fileio/lun0  
Created LUN 0.
/iscsi/iqn.20...09400c72/tpg1> set attribute authentication=0 demo_mode_write_protect=0 generate_node_acls=1 cache_dynamic_acls=1
Parameter demo_mode_write_protect is now '0'.
Parameter authentication is now '0'.
Parameter generate_node_acls is now '1'.
Parameter cache_dynamic_acls is now '1'.
           
/iscsi/iqn.20...09400c72/tpg1> cd /
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 1]
  | | o- lun0 ................................................................... [/var/lib/iscsi.img (1.5TiB) write-back activated]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2003-01.org.linux-iscsi.node114.x8664:sn.1d0909400c72 ......................................................... [TPGs: 1]
  |   o- tpg1 .................................................................................................. [gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 0]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ............................................................................... [fileio/lun0 (/var/lib/iscsi.img)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json           

繼續閱讀