一、安装iscsi target
yum install -y scsi-target-utils
二、添加磁盘并格式化
2.1查看添加的磁盘系统是否正确识别fdisk -l
2.2分别格式化添加的磁盘 fdisk /dev/sdb;fdisk /dev/sdc;fdisk /dev/sdd;fdisk /dev/sde
2.3查看是否格式化完成
[[email protected] ~]# fdisk -l
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 2087 16763796 83 Linux
/dev/sda2 2088 2609 4192965 82 Linux swap / Solaris
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 512 524272 83 Linux
Disk /dev/sdc: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 512 524272 83 Linux
Disk /dev/sdd: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdd1 1 391 3140676 83 Linux
Disk /dev/sde: 3221 MB, 3221225472 bytes
255 heads, 63 sectors/track, 391 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sde1 1 391 3140676 83 Linux
三、启动iscsi target服务
service tgtd start
四、查看服务是否启动,端口是否正常
[[email protected] ~]# netstat -an | grep 3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN
tcp 0 0 192.168.1.200:3260 192.168.1.253:10282 ESTABLISHED
tcp 0 0 :::3260 :::* LISTEN
[[email protected] ~]#
五、使用tgtadm配置iscsi target的IQN、磁盘资源、及initiator服务器
5.1 配置iscsi target服务器的IQN为 iqn.2016-09.com.centos:000
tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2016-09.com.centos:000
5.2 把格式化后的四个磁盘分配给tid1
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 2 -b /dev/sdc1
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 3 -b /dev/sdd1
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 4 -b /dev/sde1
5.3配置initiator服务器,只允许IP为192.168.1.199;192.168.1.198的initiator服务器访问
tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.1.199
tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.1.198
六、查看资源分配是否正常,initiator服务器配置是否正常
[[email protected] ~]# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2016-09.com.centos:000
System information:
Driver: iscsi
State: ready
I_T nexus information:
I_T nexus: 1
Initiator: iqn.1988-12.com.oracle:002
Connection: 0
IP Address: 192.168.1.253
LUN information:
LUN: 0
Type: controller
SCSI ID: IET 00010000
SCSI SN: beaf10
Size: 0 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: None
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 537 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sdb1
LUN: 2
Type: disk
SCSI ID: IET 00010002
SCSI SN: beaf12
Size: 537 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sdc1
LUN: 3
Type: disk
SCSI ID: IET 00010003
SCSI SN: beaf13
Size: 3216 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sdd1
LUN: 4
Type: disk
SCSI ID: IET 00010004
SCSI SN: beaf14
Size: 3216 MB
Online: Yes
Removable media: No
Backing store type: rdwr
Backing store path: /dev/sde1
Account information:
ACL information:
192.168.1.199
192.168.1.198
七、把tgtd服务配置信息加入到/etc/rc.local文件中,使其可以重启自动生效
tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2016-09.com.centos:000
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 2 -b /dev/sdc1
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 3 -b /dev/sdd1
tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 4 -b /dev/sde1
tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.1.199
tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.1.198