12.5. iSCSI-based Storage Pools This section covers using iSCSI-based devices to store guest virtual machines. iSCSI (Internet Small Computer System Interface) is a network protocol for sharing storage devices. iSCSI connects initiators (storage clients) to targets (storage servers) using SCSI instructions over the IP layer. 12.5.1. Configuring a Software iSCSI Target The scsi-target-utils package provides a tool for creating software-backed iSCSI targets. Procedure 12.4. Creating an iSCSI target Install the required packages Install the scsi-target-utils package and all dependencies Start the tgtd service The tgtd service host physical machines SCSI targets and uses the iSCSI protocol to host physical machine targets. Start the tgtd service and make the service persistent after restarting with the chkconfig command. Optional: Create LVM volumes LVM volumes are useful for iSCSI backing images. LVM snapshots and resizing can be beneficial for guest virtual machines. This example creates an LVM image named virtimage1 on a new volume group named virtstore on a RAID5 array for hosting guest virtual machines with iSCSI. Create the RAID array Creating software RAID5 arrays is covered by the Red Hat Enterprise Linux Deployment Guide . Create the LVM volume group Create a volume group named virtstore with the vgcreate command. Create a LVM logical volume Create a logical volume group named virtimage1 on the virtstore volume group with a size of 20GB using the lvcreate command. The new logical volume, virtimage1 , is ready to use for iSCSI. Optional: Create file-based images File-based storage is sufficient for testing but is not recommended for production environments or any significant I/O activity. This optional procedure creates a file based imaged named virtimage2.img for an iSCSI target. Create a new directory for the image Create a new directory to store the image. The directory must have the correct SELinux contexts. Create the image file Create an image named virtimage2.img with a size of 10GB. Configure SELinux file contexts Configure the correct SELinux context for the new image and directory. The new file-based image, virtimage2.img , is ready to use for iSCSI. Create targets Targets can be created by adding a XML entry to the /etc/tgt/targets.conf file. The target attribute requires an iSCSI Qualified Name (IQN). The IQN is in the format: Where: yyyy - mm represents the year and month the device was started (for example: 2010-05 ); reversed domain name is the host physical machines domain name in reverse (for example server1.example.com in an IQN would be com.example.server1 ); and optional identifier text is any text string, without spaces, that assists the administrator in identifying devices or hardware. This example creates iSCSI targets for the two types of images created in the optional steps on server1.example.com with an optional identifier trial . Add the following to the /etc/tgt/targets.conf file. 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. Important This example creates a globally accessible target without access control. Refer to the scsi-target-utils for information on implementing secure access. Restart the tgtd service Restart the tgtd service to reload the configuration changes. iptables configuration Open port 3260 for iSCSI access with iptables . Verify the new targets View the new targets to ensure the setup was successful with the tgt-admin --show command. Warning The ACL list is set to all. This allows all systems on the local network to access this device. It is recommended to set host physical machine access ACLs for production environments. Optional: Test discovery Test whether the new iSCSI device is discoverable. Optional: Test attaching the device Attach the new device ( iqn.2010-05.com.example.server1:iscsirhel6guest ) to determine whether the device can be attached. Detach the device. An iSCSI device is now ready to use for virtualization.

Commands:
yum install scsi-target-utils
service tgtd start chkconfig tgtd on
vgcreate virtstore /dev/md1
lvcreate --size 20G -n virtimage1 virtstore
mkdir -p /var/lib/tgtd/ virtualization
dd if=/dev/zero of=/var/lib/tgtd/ virtualization / virtimage2.img bs=1M seek=10000 count=0
restorecon -R /var/lib/tgtd
iqn. yyyy - mm . reversed domain name : optional identifier text
<target iqn.2010-05.com.example. server1 : iscsirhel6guest > backing-store /dev/ virtstore / virtimage1 #LUN 1 backing-store /var/lib/tgtd/ virtualization / virtimage2.img #LUN 2 write-cache off </target>
service tgtd restart
iptables -I INPUT -p tcp -m tcp --dport 3260 -j ACCEPT service iptables save service iptables restart
tgt-admin --show Target 1: iqn.2010-05.com.example.server1:iscsirhel6guest 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: 20000 MB Online: Yes Removable media: No Backing store type: rdwr Backing store path: /dev/ virtstore / virtimage1 LUN: 2 Type: disk SCSI ID: IET 00010002 SCSI SN: beaf12 Size: 10000 MB Online: Yes Removable media: No Backing store type: rdwr Backing store path: /var/lib/tgtd/ virtualization / virtimage2.img Account information: ACL information: ALL
iscsiadm --mode discovery --type sendtargets --portal server1.example.com 127.0.0.1:3260,1 iqn.2010-05.com.example.server1:iscsirhel6guest
iscsiadm -d2 -m node --login scsiadm: Max file limits 1024 1024 Logging in to [iface: default, target: iqn.2010-05.com.example.server1:iscsirhel6guest, portal: 10.0.0.1,3260] Login to [iface: default, target: iqn.2010-05.com.example.server1:iscsirhel6guest, portal: 10.0.0.1,3260] successful.
iscsiadm -d2 -m node --logout scsiadm: Max file limits 1024 1024 Logging out of session [sid: 2, target: iqn.2010-05.com.example.server1:iscsirhel6guest, portal: 10.0.0.1,3260 Logout of [sid: 2, target: iqn.2010-05.com.example.server1:iscsirhel6guest, portal: 10.0.0.1,3260] successful.