测试环境:rhel 6.3 虚拟机 

IP规划:

服务器:192.168.0.240

客户端:192.168.0.241 和 192.168.0.242

 

SCSI服务器端

1、准备共享磁盘或分区 ,此处共享出一块磁盘/dev/vdb

2、安装软件包

[root@node0 ~]# yum groupinstall "Network Storage Server" -y

================================================================================================
 Package                       Arch             Version                  Repository        Size
================================================================================================
Installing:
 scsi-target-utils             x86_64           1.0.24-2.el6             Server           170 k
Installing for dependencies:
 perl-Config-General           noarch           2.44-1.el6               Server            68 k

3、启动并启用tgtd服务

[root@node0 ~]# /etc/init.d/tgtd start
Starting SCSI target daemon:                               [  OK  ]
[root@node0 ~]# chkconfig tgtd on

4、编辑scsi服务端的targets配置文件

[root@node0 ~]# vi /etc/tgt/targets.conf

<target iqn.2012-07.com.example:rhcs>
     backing-store /dev/vdb
     initiator-address 192.168.0.241
     initiator-address 192.168.0.242
</target>

5、重启tgtd服务

[root@node0 ~]# /etc/init.d/tgtd restart
Stopping SCSI target daemon:                               [  OK  ]
Starting SCSI target daemon:                               [  OK  ]

6、显示所有targets

[root@node0 ~]# tgt-admin -s
Target 1: iqn.2012-07.com.example:rhcs
    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: 5369 MB, Block size: 512
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/vdb
            Backing store flags:
    Account information:
    ACL information:
        192.168.0.241
        192.168.0.242

 

iSCSI客户端配置

1、安装软件包


================================================================================================
 Package                        Arch            Version                   Repository       Size
================================================================================================
Installing:
 iscsi-initiator-utils          x86_64          6.2.0.872-41.el6          Server          654 k

2、discover 发现 targets

 [root@node1 ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.0.240 --discover

Starting iscsid:                                           [  OK  ]

192.168.0.240:3260,1 iqn.2012-07.com.example:rhcs

3、login 连接 targets

 [root@node1 ~]# iscsiadm --mode node --targetname iqn.2012-07.com.example:rhcs --portal 192.168.0.240:3260 --login
Logging in to [iface: default, target: iqn.2012-07.com.example:rhcs, portal: 192.168.0.240,3260] (multiple)
Login to [iface: default, target: iqn.2012-07.com.example:rhcs, portal: 192.168.0.240,3260] successful.

4、查看是否连接成功


[root@node1 ~]# fdisk -l

……
Disk /dev/sda: 5368 MB, 5368709120 bytes
166 heads, 62 sectors/track, 1018 cylinders
Units = cylinders of 10292 * 512 = 5269504 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x65ddc4fb

   Device Boot      Start         End      Blocks   Id  System

// 看到 sda盘,代表SCSI盘,说明客户端挂载成功!

 

遇到问题小记

问题描述:SCSI服务器端与客户端可相互ping通,但当iSCSI客户端discover scsi-targets时,报错 No route to host

[root@node1 ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.0.240 --discoveriscsiadm: cannot make connection to 192.168.0.240: No route to host
iscsiadm: cannot make connection to 192.168.0.240: No route to host
iscsiadm: cannot make connection to 192.168.0.240: No route to host
iscsiadm: cannot make connection to 192.168.0.240: No route to host
iscsiadm: cannot make connection to 192.168.0.240: No route to host
iscsiadm: cannot make connection to 192.168.0.240: No route to host
iscsiadm: connection login retries (reopen_max) 5 exceeded
iscsiadm: Could not perform SendTargets discovery: encountered connection failure

问题原因:SCSI服务器端iptables限制

解决办法:清空服务器端iptables,或开放3260端口