Subscribe:

Ads 468x60px

Pages

Wednesday, August 17, 2011

Configure ISCSI target and ISCSI initiator in linux server

In my lab setup, I have a host named server1.example.com, with an IP address of 192.168.1.112, which runs RHEL 6. This will be my iSCSI Target. A second host, named client1.example.com (192.168.1.11), which is also running RHEL 6, will be the iSCSI initator. 


Solution:
Open-iSCSI project software feature are high-performance, transport independent, multi-platform implementation of RFC3720 iSCSI


Step to configure the iSCSI Target:
Creating the iSCSI Target
install scsi-target-utils
[root@server1 ~]# yum install scsi-target -y


Start the tgtd service
[root@server1 ~]# service tgtd start


Make the service persistent after reboots
[root@server1 ~]# chkconfig tgtd on


Note: The tgtd service hosts SCSI targets and uses the iSCSI protocol to enable communications between targets and initiators. 

we need storage device to use as a target. 1.Create an LVM volume and 2. Create file-based images


1. Create an LVM volume
[root@server1 ~]# fdisk -l


Disk /dev/sda: 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/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         853     6803527+  83  Linux
/dev/sda3             854         903      401625   83  Linux
/dev/sda4             904        1044     1132582+   5  Extended
/dev/sda5             904         977      594373+  83  Linux


Create a raw partition
[root@server1 ~]# fdisk /dev/sda
The number of cylinders for this disk is set to 1044.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
   (e.g., DOS FDISK, OS/2 FDISK)


Command (m for help): n
First cylinder (978-1044, default 978):
Using default value 978
Last cylinder or +size or +sizeM or +sizeK (978-1044, default 1044): +200M


Command (m for help): t
Partition number (1-6): 6
Hex code (type L to list codes): 8e
Changed system type of partition 6 to 8e (Linux LVM)


Command (m for help): p


Disk /dev/sda: 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/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         853     6803527+  83  Linux
/dev/sda3             854         903      401625   83  Linux
/dev/sda4             904        1044     1132582+   5  Extended
/dev/sda5             904         977      594373+  83  Linux
/dev/sda6             978        1002      200781   8e  Linux LVM


Command (m for help): w
The partition table has been altered!


Calling ioctl() to re-read partition table.


WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table.
The new table will be used at the next reboot.
Syncing disks.


[root@server1 ~]# partx -a /dev/sda


Create physical volume
[root@server1 ~]# pvcreate /dev/sda6
  Physical volume "/dev/sda6" successfully created


Create volume group
[root@server1 ~]# vgcreate vol01 /dev/sda6
  Volume group "vol01" successfully created


Create logical volume
[root@server1 ~]# lvcreate -L 150M -n log01 vol01
  Rounding up size to full physical extent 152.00 MB
  Logical volume "log01" created


2. Create file-based images
Create a new directory to store the image file
[root@server1 ~]# mkdir -p /var/lib/tgtd/virtualization


Create an image named virtimage2.img with a size of 100M.
[root@server1 ~]# dd if=/dev/zero of=/var/lib/tgtd/virtualization/virtimage2.img bs=1M seek=100 count=0


Configure the correct SELinux context for the new image and directory.
[root@server1 ~]# restorecon -R /var/lib/tgtd


Check the SELinux context for the new image and directory.
[root@server1 ~]# ls -ldZ /var/lib/tgtd/
drwxr-xr-x  root root root:object_r:var_lib_t:s0       /var/lib/tgtd/


Note: Targets can be created by adding an XML entry to the /etc/tgt/targets.conf file. The target attribute requires an iSCSI Qualified Name (IQN), in the format:
   iqn.yyyy-mm.reversed.domain.name:OptionalIdentifierText
where:
   yyyy-mm represents the 4-digit year and 2-digit month the device was started (for example: 2011-08);
   reversed.domain.name is the hosts domain name in reverse. For example, server1.example.com, in an IQN, becomes com.example.server1; and
   OptionalIdentifierText is any text string, without spaces, that helps the administrator identify which device is which.



Create the target
[root@server1 ~]# vim /etc/tgt/targets.conf
### At last add the following lines ###
<target iqn.2011-07.com.example.server1:trial>
backing-store /dev/vol01/log01                                     #LUN1
backing-store /var/lib/tgtd/virtualization/virtimage2.img   #LUN2
write-cache off
</target>


Save and quite
:wq


Note: Ensure that the /etc/tgt/targets.conf file contains the default-driver iscsi line to set the driver type as iSCSI (the driver uses iSCSI by default, but make sure that line is not commented out).
[root@server1 ~]# grep default-driver /etc/tgt/targets.conf
default-driver iscsi


IPTables configuration:
[root@server1 ~]# iptables -I INPUT -m tcp -p tcp --dport 3260 -j ACCEPT
[root@server1 ~]# service iptables save
[root@server1 ~]# service iptables restart


verify the new iscsi target
[root@server1 ~]# tgt-admin --show
Target 1: iqn.2011-07.com.example.server1:trial
    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: null
            Backing store path: None
            Backing store flags:
        LUN: 1
            Type: disk
            SCSI ID: IET     00010001
            SCSI SN: beaf11
            Size: 159 MB
            Online: Yes
            Removable media: No
            Backing store type: rdwr
            Backing store path: /dev/vol01/log01
            Backing store flags:
        LUN: 2
            Type: disk
            SCSI ID: IET     00010002
            SCSI SN: beaf12
            Size: 105 MB
            Online: Yes
            Removable media: No
            Backing store type: rdwr
            Backing store path: /var/lib/tgtd/virtualization/virtimage2.img
            Backing store flags:
    Account information:
    ACL information:
        ALL

Note: LUN 0 will appear as a device of type "controller". And also notice that the ACL list is set to ALL. This allows all systems on the local network to access this device.






Step to configure the ISCSI-initiator:


Install ISCSI-initiator
[root@server1 ~]# yum install iscsi-initiator -y


Start the iscsi service
# service iscsid start


Make the service persistent after reboots
[root@server1 ~]# chkconfig iscsid on


Now we can test whether the new iSCSI device is discoverable from client1.example.com:


[root@server1 ~]# iscsiadm -m discovery -t sendtargets -p server1.example.com
192.168.1.112:3260,1 iqn.2011-07.com.example.server1:trial
or
[root@server1 ~]# iscsiadm -m discovery -t sendtargets -p 192.168.1.112
192.168.1.112:3260,1 iqn.2011-07.com.example.server1:trial


Note: 192.168.1.112 is the ip address of your own iscsi target server


To view more information about your iSCSI Target
[root@server1 ~]# iscsiadm -m node -T iqn.2011-07.com.example.server1:trial -p 192.168.1.112
# BEGIN RECORD 2.0-872
node.name = iqn.2011-07.com.example.server1:trial
node.tpgt = 1
node.startup = automatic
iface.hwaddress = <empty>
iface.ipaddress = <empty>
iface.iscsi_ifacename = default
iface.net_ifacename = <empty>
iface.transport_name = tcp
iface.initiatorname = <empty>
node.discovery_address = 192.168.1.112
node.discovery_port = 3260
node.discovery_type = send_targets
node.session.initial_cmdsn = 0
node.session.initial_login_retry_max = 8
node.session.xmit_thread_priority = -20
node.session.cmds_max = 128
node.session.queue_depth = 32
node.session.auth.authmethod = None
node.session.auth.username = <empty>
node.session.auth.password = <empty>
node.session.auth.username_in = <empty>
node.session.auth.password_in = <empty>
node.session.timeo.replacement_timeout = 120
node.session.err_timeo.abort_timeout = 15
node.session.err_timeo.lu_reset_timeout = 30
node.session.err_timeo.tgt_reset_timeout = 30
node.session.err_timeo.host_reset_timeout = 60
node.session.iscsi.FastAbort = Yes
node.session.iscsi.InitialR2T = No
node.session.iscsi.ImmediateData = Yes
node.session.iscsi.FirstBurstLength = 262144
node.session.iscsi.MaxBurstLength = 16776192
node.session.iscsi.DefaultTime2Retain = 0
node.session.iscsi.DefaultTime2Wait = 2
node.session.iscsi.MaxConnections = 1
node.session.iscsi.MaxOutstandingR2T = 1
node.session.iscsi.ERL = 0
node.conn[0].address = 192.168.1.112
node.conn[0].port = 3260
node.conn[0].startup = manual
node.conn[0].tcp.window_size = 524288
node.conn[0].tcp.type_of_service = 0
node.conn[0].timeo.logout_timeout = 15
node.conn[0].timeo.login_timeout = 15
node.conn[0].timeo.auth_timeout = 45
node.conn[0].timeo.noop_out_interval = 5
node.conn[0].timeo.noop_out_timeout = 5
node.conn[0].iscsi.MaxXmitDataSegmentLength = 0
node.conn[0].iscsi.MaxRecvDataSegmentLength = 262144
node.conn[0].iscsi.HeaderDigest = None
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD


Log into the iSCSI target
[root@server1 ~]# iscsiadm -m node -T iqn.2011-07.com.example.server1:trial -p 192.168.1.112 -l
Logging in to [iface: default, target: iqn.2011-07.com.example.server1:trial, portal: 192.168.1.112,3260]
Login to [iface: default, target: iqn.2011-07.com.example.server1:trial, portal: 192.168.1.112,3260] successful.


Check the logs for disk partion name is available
[root@server1 ~]# tail -f /var/log/messages
Aug 17 02:03:46 server1 kernel: scsi2 : iSCSI Initiator over TCP/IP
Aug 17 02:03:46 server1 kernel:   Vendor: IET       Model: Controller        Rev: 0001
Aug 17 02:03:46 server1 kernel:   Type:   RAID                               ANSI SCSI revision: 05
Aug 17 02:03:46 server1 kernel: scsi 2:0:0:0: Attached scsi generic sg1 type 12
Aug 17 02:03:46 server1 kernel:   Vendor: IET       Model: VIRTUAL-DISK      Rev: 0001
Aug 17 02:03:46 server1 kernel:   Type:   Direct-Access                      ANSI SCSI revision: 05
Aug 17 02:03:46 server1 kernel: SCSI device sdb: 311296 512-byte hdwr sectors (159 MB)
Aug 17 02:03:46 server1 kernel: sdb: Write Protect is off
Aug 17 02:03:46 server1 kernel: SCSI device sdb: drive cache: write through
Aug 17 02:03:46 server1 kernel: SCSI device sdb: 311296 512-byte hdwr sectors (159 MB)
Aug 17 02:03:46 server1 kernel: sdb: Write Protect is off
Aug 17 02:03:46 server1 kernel: SCSI device sdb: drive cache: write through
Aug 17 02:03:46 server1 kernel:  sdb: unknown partition table
Aug 17 02:03:46 server1 kernel: sd 2:0:0:1: Attached scsi disk sdb
Aug 17 02:03:46 server1 kernel: sd 2:0:0:1: Attached scsi generic sg2 type 0
Aug 17 02:03:46 server1 kernel:   Vendor: IET       Model: VIRTUAL-DISK      Rev: 0001
Aug 17 02:03:46 server1 kernel:   Type:   Direct-Access                      ANSI SCSI revision: 05
Aug 17 02:03:46 server1 kernel: SCSI device sdc: 204800 512-byte hdwr sectors (105 MB)
Aug 17 02:03:46 server1 kernel: sdc: Write Protect is off
Aug 17 02:03:46 server1 kernel: SCSI device sdc: drive cache: write through
Aug 17 02:03:46 server1 kernel: SCSI device sdc: 204800 512-byte hdwr sectors (105 MB)
Aug 17 02:03:46 server1 kernel: sdc: Write Protect is off
Aug 17 02:03:46 server1 kernel: SCSI device sdc: drive cache: write through
Aug 17 02:03:46 server1 kernel:  sdc: unknown partition table
Aug 17 02:03:46 server1 kernel: sd 2:0:0:2: Attached scsi disk sdc
Aug 17 02:03:46 server1 kernel: sd 2:0:0:2: Attached scsi generic sg3 type 0
Aug 17 02:03:46 server1 iscsid: Could not set session1 priority. READ/WRITE throughout and latency could be affected.
Aug 17 02:03:46 server1 iscsid: Connection1:0 to [target: iqn.2011-07.com.example.server1:trial, portal: 192.168.1.112,3260] through [iface: default] is operational now


Note: Now the target is enabled to be accessed upon reboots (persistent) and it's added to a node database in /var/lib/iscsi


Check the partition table
[root@server1 ~]# fdisk -l


Disk /dev/sda: 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/sda1   *           1           6       48163+  83  Linux
/dev/sda2               7         853     6803527+  83  Linux
/dev/sda3             854         903      401625   83  Linux
/dev/sda4             904        1044     1132582+   5  Extended
/dev/sda5             904         977      594373+  83  Linux
/dev/sda6             978        1002      200781   8e  Linux LVM


Disk /dev/sdb: 159 MB, 159383552 bytes
5 heads, 61 sectors/track, 1020 cylinders
Units = cylinders of 305 * 512 = 156160 bytes


Disk /dev/sdb doesn't contain a valid partition table


Disk /dev/sdc: 104 MB, 104857600 bytes
4 heads, 50 sectors/track, 1024 cylinders
Units = cylinders of 200 * 512 = 102400 bytes


Disk /dev/sdc doesn't contain a valid partition table



Create partition Disk
[root@server1 ~]# fdisk /dev/sdc
p              -->Print partition
n              -->Create new partition
p              -->Primary partition
2              -->partition Number
Enter        -->starting cylinder
+100M    -->size of the partition
p              -->Print partition
w              -->Write and save the partition


Reboot or refresh the kernel partition table by using partx command
[root@server1 ~]# partx -a /dev/sdb


Format Disk
[root@server1 ~]# mkfs.ext3 /dev/sdb2


create directory /iscsidata
[root@server1 ~]#mkdir /iscsidata


mount disk(/dev/sdb) to mount point(/iscsidata)
[root@server1 ~]# mount /dev/sdb2 /iscsidata


check the the filesystem is mounted or not
[root@server1 ~]# df -h


Mount the partition at boot. create a enty in the /etv/fstab file
[root@server1 ~]# vim /etc/fstab
/dev/sdb2 /iscsidata ext3 _netdev 0 0


mount all the partition which is exists in the /etc/fstab
[root@server1 ~]# mount -a


check the the filesystem is mounted or not
[root@server1 ~]# mount | grep iscsi


check the disk
# df -h

1 comments:

Pratik said...

nice one... good job.. but, i m getting: while mounting scsi disk on initiator:


# mke2fs -j /dev/sdc1
mke2fs 1.41.12 (17-May-2010)
/dev/sdc1 is apparently in use by the system; will not make a filesystem here!

Post a Comment