OS: ubuntu16.04
编译安装
1.下载代码
git clone https://github.com/fujita/tgt.git
2.安装依赖包
apt install devscripts debhelper librdmacm-dev libibverbs-dev xsltproc docbook-xsl libconfig-general-perl
3. 构建deb包
cd tgt/scripts
./build-pkg.sh deb
4. 安装
cd tgt/pkg
dpkg -i tgt_*.deb
配置
1. 创建
tgtadm --lld iscsi --mode target --op new --tid=1 --targetname iqn.2016-10.finals.com:vio1
2. 查看
root@ubuntu16:/home/finals/tgt/pkg# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2016-10.finals.com:vio1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
Account information:
ACL information:
3.添加LUN
tgtadm --lld iscsi --mode logicalunit --op new --tid 1 --lun 1 -b /home/iscsi-vio1
root@ubuntu16:/home# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2016-10.finals.com:vio1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1074 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path: /home/iscsi-vio1
Backing store flags:
Account information:
ACL information:
4.删除LUN
tgtadm --lld iscsi --mode logicalunit --op delete --tid 1 --lun 1
5.删除Target
tgtadm --lld iscsi --mode target --op delete --tid 1
4.ACL设置
允许任意initiator访问target
tgtadm --lld iscsi --mode target --op bind --tid 1 -I ALL
基于IP的访问控制
tgtadm --lld iscsi --mode target --op bind --tid 1 -I 192.168.14.135
基于子网的访问控制
tgtadm --lld iscsi --mode target --op bind --tid 1 -I 192.168.14.0/24
查看设置结果
root@ubuntu16:/home# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2016-10.finals.com:vio1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1074 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path: /home/iscsi-vio1
Backing store flags:
Account information:
ACL information:
ALL
192.168.14.135
192.168.14.0/24
5.验证机制
1.创建用户
tgtadm --lld iscsi --mode account --op new --user ''finals'' --password ''123456''
- 添加用户到已经存在的target设备
tgtadm --lld iscsi --mode account --op bind --tid 1 --user ''finals''
在initiator中,用户名和密码信息需要添加到/etc/iscsi/iscsid.conf中
- 对于discovery的验证机制(tgt尚未支持): discovery.sendtargets.auth.{username,password}
- 对于session的验证机制:node.session.auth.{username,password}
查看
root@ubuntu16:/home# tgtadm --lld iscsi --mode target --op show
Target 1: iqn.2016-10.finals.com:vio1
System information:
Driver: iscsi
State: ready
I_T nexus information:
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB, Block size: 1
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: null
Backing store path: None
Backing store flags:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 1074 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path: /home/iscsi-vio1
Backing store flags:
Account information:
finals
ACL information:
ALL
192.168.14.135
192.168.14.0/24
使用
1.发现Target
iscsiadm -m discovery -t sendtargets -p 192.168.14.135
显示已发现的target:
iscsiadm -m node
2.连接Target
iscsiadm -m node -p 192.168.14.135 -T iqn.2016-10.finals.com:storage.vio1 --login
3.查看新增磁盘
root@ubuntu16:/home# lsscsi
[1:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[2:0:0:0] disk VMware Virtual disk 1.0 /dev/sda
[2:0:1:0] disk VMware Virtual disk 1.0 /dev/sdb
[3:0:0:0] storage IET Controller 0001 -
[3:0:0:1] disk IET VIRTUAL-DISK 0001 /dev/sdc
4.断开Target
iscsiadm -m node -p 192.168.14.135 -T iqn.2016-10.finals.com:storage.vio1 --logout