RHEL5 iSCSI Target/Initiator
iSCSI is a protocol that allows you to use a disk in a remote machine, locally as a block device. It is a very popular SAN protocol, which allows the consolidation of storage into one large storage pool.
In iSCSI terminology, a target is a storage resource located on an iSCSI server and an initiator is a client which will be connecting to a target.
In this post I will demonstrate how to setup an iSCSI target and initiator on RedHat Enterprise Linux 5.
Target
RHEL5 has the stgt target daemon included with it. This is the server which allows initiators (clients) to connect to the disks using the iSCSI protocol. It is installable using yum:
yum install scsi-target-utils
To share a disk over iSCSI, you can either use a disk image, or a block device. I prefer to use LVM logical volumes as LVM allows easy management of free space.
Stgt’s configuration file lives in /etc/tgt/targets.conf, although most configuration can be done using the command line (although this is not persistant across reboots, so I prefer to use the configuration file).
To create a target, just add the following lines:
backing-store /dev/DiskArray/Archive1
Please note that you must replace iqn.2009-02.com.hamzahkhan:archive1 with your own domain name, and resource name. It must be in the iSCSI Qualified Name (IQN) format, iqn.yyyy-mm.{reversed domain name}:an_easy_to_remember_lablel.
The second line, backing-store /dev/DiskArray/Archive1 specifies the disk/disk image that is to become the target, I am using LVM logical volume although the procedure is exactly the same for disk images, and real physical disks.
By default, stgt will allow all IPs to connect to the target, which is highly insecure! To change this behaviour, it is possible to specify IP addresses which are allowed to use the targets. To do this, just place the following line under backing-store:
initiator-address 10.1.0.4
This will allow 10.1.0.4 to access the target.
Now, use chkconfig to make stgt start at boot, and start up the daemon.
/etc/init.d/tgtd start
chkconfig tgtd on
Thats all there is to it on the server side! All done
You can now connect to the target using any initiator, such as the one built into Windows Vista (although I have never tried using Windows).
Initiator
RedHat have included an iSCSI daemon which is also installable using yum:
yum install iscsi-initiator-utils
To connect to the target, edit /etc/iscsi/initiatorname.iscsi and change InitiatorName to something you prefer (Remember! it must be in the IQN format, iqn.yyyy-mm.{reversed domain name}:an_easy_to_remember_lablel. I usually use iqn.2009-02.com.hamzahkhan:hostname_of_box). Next start up iSCSId:
/etc/init.d/iscsid start
and use iSCSI target descovery to find the targets on the server:
iscsiadm -m discovery -t st -p $SERVERS_IP
If all is well, it should output the names of all the targets that the initiator is allowed to connect to!
Next, we need to create the disk nodes. To do this, RedHat have provided a nice start up script. This script will login to all the targets that the iSCSI daemon knows about. We have already used the iscsiadm command to tell the iSCSI daemon which targets exist on the server, so using the script is all that is left:
/etc/init.d/iscsi start
Thats all there is to it!
You should have a new disk node in /dev/. You can use lsscsi (yum install lsscsi) to find the exact name if you have a lot of USB/SATA/SCSI drives connected to the machine already.
Now all you have to do is partition the disk, and dump your files onto it
Please remember, you must NEVER mount a partition on two machines at the same time. Doing so will cause data loss!
It IS possible to mount the same disk on multiple machines, but this requires a special clustered filesystem such as GFS.




