Saturday, 25 April 2015

Install/Configure iSCSI targets, LUN's, initiators - CentOS

​iSCSI is an acronym for Internet Small Computer System Interface, an Internet Protocol (IP)-based storage networking standard for linking data storage facilities. iSCSI can be used to transmit data over local area networks (LANs), wide area networks (WANs), or the Internet. iSCSI protocol allows clients (called initiators) to send SCSI commands (CDBs) to SCSI storage devices (targets) on remote servers. It is a storage area network (SAN) protocol, allowing organizations to consolidate storage into data center storage arrays while providing hosts with the illusion of locally attached disks. However, the performance of an iSCSI SAN deployment can be severely degraded if not operated on a dedicated network or subnet (LAN or VLAN), due to competition for a fixed amount of bandwidth.


Environment: centos 6.5 - iSCSI target 
             centos 7   - iSCSI initiators

Diagram is self explanatory for the environment on which I would explain below article in three sections
I have attached one HDD on the target server.

Section 1: Install iscsi target 
Section 2: Create LUN using iscsi
Section 3: Install initiators and verify LUN

Section 1 :

- Install the iscsi target package
iscsitarget# yum install scsi-target-utils -y

- start the iscsi service and autostart while system boots.
iscsitarget# /etc/init.d/tgtd start
iscsitarget# chkconfig tgtd on

- Incase firewall is enabled, add rules to allow iptables to discover iscsi targets.
iscsitarget# iptables -A INPUT -i eth0 -p tcp --dport 860 -m state --state NEW,ESTABLISHED -j ACCEPT
iscsitarget# iptables -A INPUT -i eth0 -p tcp --dport 3260 -m state --state NEW,ESTABLISHED -j ACCEPT
iscsitarget# iptables-save
iscsitarget# /etc/init.d/iptables restart

Section 2:
- Check your fdisk utility shows the newly added disk, then partition the drive and change partition type to LVM(8e). save the changes and make sure kernel is aware of the changes made to partition table(partprobe).

iscsitarget# pvcreate /dev/sdb1
iscsitarget# vgcreate vg_iscsi /dev/sdb1
iscsitarget# lvcreate -l 100%FREE -n lv_iscsi vg_iscsi
iscsitarget# pvs;vgs;lvs
  PV         VG       Fmt  Attr PSize    PFree
  /dev/sdb1  vg_iscsi lvm2 a--  1016.00m    0
  VG       #PV #LV #SN Attr   VSize    VFree
  vg_iscsi   1   1   0 wz--n- 1016.00m    0
  LV       VG       Attr       LSize    Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv_iscsi vg_iscsi -wi-ao---- 1016.00m
iscsitarget#

- we need to define the LUN in the target configuration, so it will be available for client machines(initiators).
iscsitarget# cat -n /etc/tgt/targets.conf
    16  default-driver iscsi
    17
    18  <target iqn.2015-04.com.test:apache:lun1>
    19          backing-store /dev/vg_iscsi/lv_iscsi
    20  </target>

briefly, the fields are:
- iqn, iSCSI Qualified Name 
- date (yyyy-mm),  that the naming authority took ownership of the domain
- reversed domain name of the authority
- Optional ":" prefixing a storage target name specified by the naming authority

- reload the configuration
iscsitarget# /etc/init.d/tgtd reload

- show target and LUN status
iscsitarget# tgtadm --mode target --op show
Target 1: iqn.2015-04.com.test:apache:lun1  <<=== iSCSI Qualified Name
    System information: 
        Driver: iscsi
        State: ready   <<=== iSCSI is Ready to Use
    I_T nexus information:
        I_T nexus: 1
            Initiator: iqn.1994-05.com.redhat:905dbea49e0
            Connection: 0
                IP Address: 192.168.229.132
        I_T nexus: 2
            Initiator: iqn.1994-05.com.redhat:488c35a56511
            Connection: 0
                IP Address: 192.168.229.133
    LUN information:
        LUN: 0  <<==== Default LUN ID reservered for controller  
            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: 1065 MB, Block size: 512  <<== Lun size defined in the target
            Online: Yes  <<===  Lun is ready to be used 
            Removable media: No
            Prevent removal: No
            Readonly: No
            Backing store type: rdwr
            Backing store path: /dev/vg_iscsi/lv_iscsi
            Backing store flags:
    Account information:
    ACL information:
        ALL
iscsitarget#

Section 3:

On the clients, install initiator package. 
iscsiinitiator1# yum install iscsi-initiator-utils.x86_64
iscsiinitiator1#

iscsiinitiator2# yum install iscsi-initiator-utils.x86_64
iscsiinitiator2#

- discover the share from the target server. 
iscsiinitiator1# iscsiadm -m discoverydb -t st -p 192.168.229.130 -D
192.168.229.130:3260,1 iqn.2015-04.com.test:apache:lun1
iscsiinitiator1#

iscsiinitiator2# iscsiadm -m discoverydb -t st -p 192.168.229.130 -D
192.168.229.130:3260,1 iqn.2015-04.com.test:apache:lun1
iscsiinitiator2# 

- To attach LUN to client's local system, you will be required to authenticate with target server and allow to login to LUN.
iscsiinitiator1# iscsiadm -m node -T iqn.2015-04.com.test:apache:lun1 -p 192.168.229.130:3260 -l
iscsiinitiator1#

iscsiinitiator2# iscsiadm -m node -T iqn.2015-04.com.test:apache:lun1 -p 192.168.229.130:3260 -l
iscsiinitiator2#

- you can list your block devices from the initiators(lsblk), where you could see new disk. Now, you can create partition, format and mount the file system to use. optional, can be appended in /etc/fstab if you need it to be mounted after reboots.
iscsiinitiator1# lsblk -i 
sdb                       8:16   0 1016M  0 disk
iscsiinitiator1#

iscsiinitiator2# lsblk -i 
sdb                       8:16   0 1016M  0 disk
iscsiinitiator2#