2、iscsi安裝與配置:
2.一、實驗環境:
以192.168.10.1做爲target,initiator分別爲192.168.10.2和192.168.10.3。
2.二、target安裝與配置:
在yum源上已經有了一個官方的target軟件tat,因此target端直接使用該軟件提供相關服務便可。
node
yum -y install scsi-target-utilsscsi-target-utils包中的主要配置文件以及命令:
[root@10.1 ~]# dd if=/dev/zero of=/home/test.img bs=1M count=768 [root@10.1 ~]# dd if=/dev/zero of=/home/trunk.img bs=1M count=768 [root@10.1 ~]# 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,開啓緩存會加速,不過相應的,在特殊狀況就有可能丟失數據的可能。
[root@10.1 ~]# /etc/init.d/tgtd start Starting SCSI target daemon: [ OK ] [root@10.1 ~]# 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信息:
[root@10.1 ~]# 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是控制器。
[root@10.1 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.三、initiator安裝與配置:
yum install iscsi-initiator-utilsiscsi-initiator-utils中的主要配置文件以及命令:
[root@10.2 ~]# 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 [root@10.3 ~]# 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也是相似的。
[root@10.2 ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.1994-05.com.redhat:f24aa1f2fabd [root@10.3 ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.1994-05.com.redhat:772524a8a83e在target將會看到這樣的信息,能夠說是毫無分辨性,initiator多了以後不方便管理,強烈建議修改一下這個名稱,initiator的命名規則和target是一致的,能夠改成以下所示:
[root@10.2 ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2013-09.com.inter.10.2:test-initiator [root@10.3 ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2013-09.com.inter.10.3:trunk-initiator經過如下命令啓動iscsi initiator的服務,該服務會啓動iscsid並加載發現了的target,以後使用fdisk –l命令來查看加載的磁盤:
[root@10.2 ~]# /etc/init.d/iscsi start Starting iscsi: [ OK ] [root@10.2 ~]# 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端的「磁盤」。能夠對該磁盤進行格式化並掛載後使用:
[root@10.2 ~]# mkfs.ext4 /dev/sda [root@10.2 ~]# mount -t ext4 /dev/sda /tmp/test如下是一些較爲經常使用的調試命令:
[root@10.2 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