创建iscsi target
1、准备存储(实验用的是lvm)
[root@node4 ~]# lvcreate -n storage -L 4G vgsrv Logical volume "storage" created [root@node4 ~]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert home vgsrv -wi-ao 256.00m root vgsrv -wi-ao 3.31g storage vgsrv -wi-a- 4.00g #确认lvm创建成功 swap vgsrv -wi-ao 544.00m
2、安装 scsi-target-utils 包
[root@node4 ~]# yum install -y scsi-target-utils ... ... Installed: scsi-target-utils.x86_64 0:1.0.14-4.el6 Dependency Installed: libibverbs.x86_64 0:1.1.5-3.el6 librdmacm.x86_64 0:1.0.14.1-3.el6 perl-Config-General.noarch 0:2.44-1.el6 Complete!
3、编辑tgt配置文件
[root@node4 ~]# vim /etc/tgt/targets.conf [root@node4 ~]# grep -Ev '\ *#|^$' /etc/tgt/targets.conf default-driver iscsi <target iqn.2012-04.com.example.cluster3:storage> <backing-store /dev/vgsrv/storage> #因为是物理设备,所以是backing-store vendor_id rhtraining #指定vendor_id scsi_sn rh436 #指定易于辨识的scsi_sn </backing-store> initiator-address 172.18.3.1 #指定initiator的有效IP(ACL) initiator-address 172.18.3.2 initiator-address 172.18.3.3 </target>
4、测试tgtd守护进程启动
[root@node4 ~]# service tgtd start Starting SCSI target daemon: [ OK ]
5、检查target输出
[root@node4 ~]# tgt-admin -s Target 1: iqn.2012-04.com.example.cluster3:storage #iqn输出正确 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 Readonly: No Backing store type: null Backing store path: None Backing store flags: LUN: 1 Type: disk SCSI ID: IET 00010001 SCSI SN: rh436 #sn输出正确 Size: 4295 MB, Block size: 512 Online: Yes Removable media: No Readonly: No Backing store type: rdwr Backing store path: /dev/vgsrv/storage #存储源 Backing store flags: Account information: ACL information: 172.18.3.1 #ACL正确 172.18.3.2 172.18.3.3
6、配置tgtd开机自启动
[root@node4 ~]# chkconfig tgtd on
配置initiator端
1、配置Initiator Name
[root@node1 ~]# vim /etc/iscsi/initiatorname.iscsi [root@node1 ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2012-04.com.example.cluster3:node1
2、重启iscsid服务,使Initiator Name生效
[root@node1 ~]# service iscsid restart Stopping iscsid: Starting iscsid: [ OK ]
3、探测iscsi并登录
[root@node1 ~]# iscsiadm -m discovery -t st -p 172.18.3.4 172.18.3.4:3260,1 iqn.2012-04.com.example.cluster3:storage [root@node1 ~]# iscsiadm -m node -T iqn.2012-04.com.example.cluster3:storage -l Logging in to [iface: default, target: iqn.2012-04.com.example.cluster3:storage, portal: 172.18.3.4,3260] (multiple) Login to [iface: default, target: iqn.2012-04.com.example.cluster3:storage, portal: 172.18.3.4,3260] successful.
4、确认iscsi状态
[root@node1 ~]# iscsiadm -m session -P1 #-P后面0-3显示详细程度不同 Target: iqn.2012-04.com.example.cluster3:storage Current Portal: 172.18.3.4:3260,1 Persistent Portal: 172.18.3.4:3260,1 ********** Interface: ********** Iface Name: default Iface Transport: tcp Iface Initiatorname: iqn.2012-04.com.example.cluster3:node1 #配置initiator生效 Iface IPaddress: 172.18.3.1 Iface HWaddress: <empty> Iface Netdev: <empty> SID: 9 iSCSI Connection State: LOGGED IN iSCSI Session State: LOGGED_IN Internal iscsid Session State: NO CHANGE
5、可以看到iscsi磁盘了
[root@node1 ~]# iscsiadm -m session -P3 iSCSI Transport Class version 2.0-870 version 2.0-872.33.el6 Target: iqn.2012-04.com.example.cluster3:storage Current Portal: 172.18.3.4:3260,1 Persistent Portal: 172.18.3.4:3260,1 ********** Interface: ********** Iface Name: default Iface Transport: tcp Iface Initiatorname: iqn.2012-04.com.example.cluster3:node1 Iface IPaddress: 172.18.3.1 Iface HWaddress: <empty> Iface Netdev: <empty> SID: 11 iSCSI Connection State: LOGGED IN iSCSI Session State: LOGGED_IN Internal iscsid Session State: NO CHANGE ********* Timeouts: ********* Recovery Timeout: 120 Target Reset Timeout: 30 LUN Reset Timeout: 30 Abort Timeout: 15 ***** CHAP: ***** username: <empty> password: ******** username_in: <empty> password_in: ******** ************************ Negotiated iSCSI params: ************************ HeaderDigest: None DataDigest: None MaxRecvDataSegmentLength: 262144 MaxXmitDataSegmentLength: 8192 FirstBurstLength: 65536 MaxBurstLength: 262144 ImmediateData: Yes InitialR2T: Yes MaxOutstandingR2T: 1 ************************ Attached SCSI devices: ************************ Host Number: 12 State: running scsi12 Channel 00 Id 0 Lun: 0 scsi12 Channel 00 Id 0 Lun: 1 Attached scsi disk sda State: running #需要用-P3才能看到iscsi对应的磁盘名称
[root@node1 ~]# ll /dev/sd* brw-rw----. 1 root disk 8, 0 Apr 1 23:33 /dev/sda