wiki:CentOS55iSCSI
Last modified 9 years ago Last modified on 02/15/11 16:31:57

iSCSI Storage on CentOS 5.5

There are two virtual machines running the CentOS 5.5 operating system:

ip=192.168.228.152 hostname=el5-32 -- iSCSI server (target)

ip=192.168.228.153 hostname=el5-32-2 -- iSCSI client (initiator)

Configure iSCSI server (target)

# uname -nr
el5-32 2.6.18-194.32.1.el5
# ifconfig eth0 | grep 'inet addr'
          inet addr:192.168.228.152  Bcast:192.168.228.255  Mask:255.255.255.0
#
# rpm -q scsi-target-utils
scsi-target-utils-0.0-6.20091205snap.el5_5.3
#
  • Start the SCSI target daemon.
# service tgtd start
Starting SCSI target daemon: Starting target framework daemon

# service tgtd status
tgtd (pid 2697 2696) is running...
# chkconfig tgtd on
# chkconfig --list tgtd
tgtd            0:off   1:off   2:on    3:on    4:on    5:on    6:off
#
  • Create target device, then check current configuration.

In the following example 02130152 is a substitute for a random hexadecimal number, where 0213 represents current date (MMDD), 0 - just a zero, and 152 is the fourth octet in server's IP address.

# tgtadm --lld iscsi --op new --mode target --tid 1 -T iqn.2001-04.com.stgt:`uname -n`-02130152
#
# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2001-04.com.stgt:el5-32-02130152
    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
            Online: Yes
            Removable media: No
            Backing store type: rdwr
            Backing store path: None
    Account information:
    ACL information:
#
  • Add logical unit to the target, enable it to accept initiators from the local network.
# fdisk -l /dev/sdb

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        1044     8385898+  83  Linux
#
# mount |grep sdb
#
#
# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 -b /dev/sdb1
#
# tgtadm --lld iscsi --op bind --mode target --tid 1 -I 192.168.228.0/24
#
# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2001-04.com.stgt:el5-32-02130152
    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
            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: 8587 MB
            Online: Yes
            Removable media: No
            Backing store type: rdwr
            Backing store path: /dev/sdb1
    Account information:
    ACL information:
        192.168.228.0/24
#
  • Save current configuration.
# tgt-admin --dump >/etc/tgt/targets.conf
#
# cat /etc/tgt/targets.conf
default-driver iscsi

<target iqn.2001-04.com.stgt:el5-32-02130152>
        backing-store /dev/sdb1
        initiator-address 192.168.228.0/24
</target>

#

Configure iSCSI client (initiator)

# uname -nr
el5-32-2 2.6.18-194.32.1.el5
# ifconfig eth0 | grep 'inet addr'
          inet addr:192.168.228.153  Bcast:192.168.228.255  Mask:255.255.255.0
#
# rpm -q iscsi-initiator-utils
iscsi-initiator-utils-6.2.0.871-0.20.el5_5
#
# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:d91b4739849
#
# service iscsi status
iscsid (pid  1391) is running...
# chkconfig --list iscsi
iscsi           0:off   1:off   2:off   3:on    4:on    5:on    6:off
#
  • Query the storage server for available targets.
# iscsiadm --mode discovery --type sendtargets --portal  192.168.228.152
192.168.228.152:3260,1 iqn.2001-04.com.stgt:el5-32-02130152
#
  • Acquire the target.
# iscsiadm --mode node --targetname iqn.2001-04.com.stgt:el5-32-02130152 --portal 192.168.228.152:3260 --login
Logging in to [iface: default, target: iqn.2001-04.com.stgt:el5-32-02130152, portal: 192.168.228.152,3260]
Login to [iface: default, target: iqn.2001-04.com.stgt:el5-32-02130152, portal: 192.168.228.152,3260]: successful
#
# grep "`date '+%b %e %H'`" /var/log/messages 
Feb 13 22:24:06 el5-32-2 kernel: scsi1 : iSCSI Initiator over TCP/IP
Feb 13 22:24:07 el5-32-2 kernel:   Vendor: IET       Model: Controller        Rev: 0001
Feb 13 22:24:07 el5-32-2 kernel:   Type:   RAID                               ANSI SCSI revision: 05
Feb 13 22:24:07 el5-32-2 kernel: scsi 1:0:0:0: Attached scsi generic sg1 type 12
Feb 13 22:24:07 el5-32-2 kernel:   Vendor: IET       Model: VIRTUAL-DISK      Rev: 0001
Feb 13 22:24:07 el5-32-2 kernel:   Type:   Direct-Access                      ANSI SCSI revision: 05
Feb 13 22:24:07 el5-32-2 kernel: SCSI device sdb: 16771797 512-byte hdwr sectors (8587 MB)
Feb 13 22:24:07 el5-32-2 kernel: sdb: Write Protect is off
Feb 13 22:24:07 el5-32-2 kernel: SCSI device sdb: drive cache: write back
Feb 13 22:24:07 el5-32-2 kernel: SCSI device sdb: 16771797 512-byte hdwr sectors (8587 MB)
Feb 13 22:24:07 el5-32-2 kernel: sdb: Write Protect is off
Feb 13 22:24:07 el5-32-2 kernel: SCSI device sdb: drive cache: write back
Feb 13 22:24:07 el5-32-2 kernel:  sdb: unknown partition table
Feb 13 22:24:07 el5-32-2 kernel: sd 1:0:0:1: Attached scsi disk sdb
Feb 13 22:24:07 el5-32-2 kernel: sd 1:0:0:1: Attached scsi generic sg2 type 0
Feb 13 22:24:07 el5-32-2 iscsid: connection1:0 is operational now
#
# iscsiadm --mode node --targetname iqn.2001-04.com.stgt:el5-32-02130152 --portal 192.168.228.152:3260 --op update -n node.startup -v automatic
#
  • Check client status.
# iscsiadm -m session
tcp: [1] 192.168.228.152:3260,1 iqn.2001-04.com.stgt:el5-32-02130152
#
# iscsiadm -m session -P 1
Target: iqn.2001-04.com.stgt:el5-32-02130152
        Current Portal: 192.168.228.152:3260,1
        Persistent Portal: 192.168.228.152:3260,1
                **********
                Interface:
                **********
                Iface Name: default
                Iface Transport: tcp
                Iface Initiatorname: iqn.1994-05.com.redhat:d91b4739849
                Iface IPaddress: 192.168.228.153
                Iface HWaddress: <empty>
                Iface Netdev: <empty>
                SID: 1
                iSCSI Connection State: LOGGED IN
                iSCSI Session State: LOGGED_IN
                Internal iscsid Session State: NO CHANGE
#
  • Create new storage partition. Notice that disk geometry is different from that reported on the server (above).
# fdisk /dev/sdb
 [...]
# fdisk -l /dev/sdb

Disk /dev/sdb: 8587 MB, 8587160064 bytes
64 heads, 32 sectors/track, 8189 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1        8189     8385520   83  Linux
#
  • Create new file system.
# mkfs -t ext3 /dev/sdb1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
1048576 inodes, 2096380 blocks
104819 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2147483648
64 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 24 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
#
  • Configure new mount point, mount the file system.
# vi /etc/fstab 
# tail -1 /etc/fstab
/dev/sdb1       /mnt    ext3    _netdev,defaults        1 2
#
# chkconfig netfs on
# chkconfig --list netfs
netfs           0:off   1:off   2:on    3:on    4:on    5:on    6:off
#
# service netfs start
No devices found
Setting up Logical Volume Management:                      [  OK  ]
Checking network-attached filesystems
/dev/sdb1: clean, 12/1048576 files, 70322/2096380 blocks
                                                           [  OK  ]
Mounting other filesystems:                                [  OK  ]
#
#
# mount |grep sdb
/dev/sdb1 on /mnt type ext3 (rw,_netdev)
#
# df -h /dev/sdb1
Filesystem            Size  Used Avail Use% Mounted on
/dev/sdb1             7.9G  147M  7.4G   2% /mnt
#

iSCSI server status

# tgtadm --lld iscsi --op show --mode target
Target 1: iqn.2001-04.com.stgt:el5-32-02130152
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
        I_T nexus: 1
            Initiator: iqn.1994-05.com.redhat:d91b4739849
            Connection: 0
                IP Address: 192.168.228.153
    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: 8587 MB
            Online: Yes
            Removable media: No
            Backing store type: rdwr
            Backing store path: /dev/sdb1
    Account information:
    ACL information:
        192.168.228.0/24
#
#

See Also

file:///usr/share/doc/scsi-target-utils-0.0/README.iscsi

file:///usr/share/doc/scsi-target-utils-0.0/README.lu_configuration