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.
查看创建的TPG
/> 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]
创建iscsi目标
/> 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