二、iscsi安装与配置:
2.1、实验环境:
以192.168.10.1作为target,initiator分别为192.168.10.2和192.168.10.3。
2.2、target安装与配置:
在yum源上已经有了一个官方的target软件tat,所以target端直接使用该软件提供相关服务即可。
yum -y install scsi-target-utilsscsi-target-utils包中的主要配置文件以及命令:
[[email protected] ~]# dd if=/dev/zero of=/home/test.img bs=1M count=768 [[email protected] ~]# dd if=/dev/zero of=/home/trunk.img bs=1M count=768 [[email protected] ~]# ll -h /home/*.img -rw-r--r-- 1 root root 768M Sep 11 15:33 /home/test.img -rw-r--r-- 1 root root 768M Sep 11 15:35 /home/trunk.img2.2.2配置文件/etc/tgt/targets.conf配置:
<target iqn.2013-09.com.inter.10.1:test-target> backing-store /home/test.img initiator-address 192.168.10.2 </target> <target iqn.2013-09.com. inter.10.1:trunk-target> backing-store /home/trunk.img initiator-address 192.168.10.3 </target>iSCSI的target名称的命名方式:
discovery.sendtargets.auth.username = username discovery.sendtargets.auth.password = password node.session.auth.username = username node.session.auth.password = passwordwrite-cache:预设该值为on,开启缓存会加速,不过相应的,在特殊情况就有可能丢失数据的可能。
[[email protected] ~]# /etc/init.d/tgtd start Starting SCSI target daemon: [ OK ] [[email protected] ~]# netstat -tlunp | grep tgtd tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 30945/tgtd tcp 0 0 :::3260 :::* LISTEN 30945/tgtd查看target信息:
[[email protected] ~]# tgt-admin --show Target 1: iqn.2013-09.com.inter.10.1:test-target 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 Backing store type: null Backing store path: None Backing store flags: LUN: 1 Type: disk SCSI ID: IET 00010001 SCSI SN: beaf11 Size: 805 MB, Block size: 512 Online: Yes Removable media: No Prevent removal: No Readonly: No Backing store type: rdwr Backing store path: /home/test.img Backing store flags: Account information: ACL information: 192.168.10.2 Target 2: iqn.2013-09.com.inter.10.1:trunk-target System information: Driver: iscsi State: ready I_T nexus information: LUN information: LUN: 0 Type: controller SCSI ID: IET 00020000 SCSI SN: beaf20 Size: 0 MB, Block size: 1 Online: Yes Removable media: No Prevent removal: No Readonly: No Backing store type: null Backing store path: None Backing store flags: LUN: 1 Type: disk SCSI ID: IET 00020001 SCSI SN: beaf21 Size: 805 MB, Block size: 512 Online: Yes Removable media: No Prevent removal: No Readonly: No Backing store type: rdwr Backing store path: /home/trunk.img Backing store flags: Account information: ACL information: 192.168.10.3通过以上信息可以看到配置文件中的配置都已经生效,有两个target,每个target中有1个LUN。这两个target根据ACL控制,一个提供给192.168.10.2使用,一个提供给192.168.10.3使用。其中每个target的LUN0是控制器。
[[email protected] home]# tgt-admin --dump default-driver iscsi <target iqn.2013-09.com. inter.10.1:trunk-target> backing-store /home/trunk.img initiator-address 192.168.10.3 </target> <target iqn.2013-09.com. nter.10.1:test-target> backing-store /home/test.img initiator-address 192.168.10.2 </target>2.3、initiator安装与配置:
yum install iscsi-initiator-utilsiscsi-initiator-utils中的主要配置文件以及命令:
[[email protected] ~]# iscsiadm -m discovery -t sendtargets -p 192.168.10.1 192.168.10.1:3260,1 iqn.2013-09.com.inter.10.1:test-target [[email protected] ~]# iscsiadm -m discovery -t sendtargets -p 192.168.10.1 192.168.10.1:3260,1 iqn.2013-09.com.inter.10.1:trunk-target可以看出2与3分别发现了属于自己的target,权限配置在target端,根据来源IP来设置的。下来以192.168.10.2为例,来介绍一下如何使用,169也是类似的。
[[email protected] ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.1994-05.com.redhat:f24aa1f2fabd [[email protected] ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.1994-05.com.redhat:772524a8a83e在target将会看到这样的信息,可以说是毫无分辨性,initiator多了之后不方便管理,强烈建议修改一下这个名称,initiator的命名规则和target是一致的,可以改为如下所示:
[[email protected] ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2013-09.com.inter.10.2:test-initiator [[email protected] ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2013-09.com.inter.10.3:trunk-initiator通过以下命令启动iscsi initiator的服务,该服务会启动iscsid并加载发现了的target,之后使用fdisk –l命令来查看加载的磁盘:
[[email protected] ~]# /etc/init.d/iscsi start Starting iscsi: [ OK ] [[email protected] ~]# fdisk -l Disk /dev/vda: 69.8 GB, 69793218560 bytes 255 heads, 63 sectors/track, 8485 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0006336e Device Boot Start End Blocks Id System /dev/vda1 * 1 8486 68156416 83 Linux Disk /dev/vdb: 8589 MB, 8589934592 bytes 255 heads, 63 sectors/track, 1044 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00080da4 Device Boot Start End Blocks Id System /dev/vdb1 1 1045 8387584 82 Linux swap / Solaris Disk /dev/sda: 805 MB, 805306368 bytes 25 heads, 62 sectors/track, 1014 cylinders Units = cylinders of 1550 * 512 = 793600 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x00000000如上所示,/dev/sda就是远程挂载过来的target端的“磁盘”。可以对该磁盘进行格式化并挂载后使用:
[[email protected] ~]# mkfs.ext4 /dev/sda [[email protected] ~]# mount -t ext4 /dev/sda /tmp/test以下是一些较为常用的调试命令:
[[email protected] test]# iscsiadm -m node 192.168.10.1:3260,1 iqn.2013-09.com.inter.10.1:test-target在initiator端断开与指定target的连接:
iscsiadm -m node iqn.2013-09.com.inter.10.1:test-target -u在initiator端连接指定target:
iscsiadm -m node iqn.2013-09.com.inter.10.1:test-target -l在initiator端显示已经建立的target连接:
iscsiadm -m session