一、安裝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查看是否格式化完成
[root@iscsi ~]# 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
四、查看服務是否啓動,端口是否正常
[root@iscsi ~]# 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
[root@iscsi ~]#
五、使用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服務器配置是否正常
[root@iscsi ~]# 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