12.5. iSCSI-based Storage Pools
12.5.1. Configuring a Software iSCSI Target
Procedure 12.4. Creating an iSCSI target
Install the required packages
Install the scsi-target-utils package and all dependencies# yum install scsi-target-utils
Start the tgtd service
Thetgtd
service host physical machines SCSI targets and uses the iSCSI protocol to host physical machine targets. Start thetgtd
service and make the service persistent after restarting with thechkconfig
command.# service tgtd start # chkconfig tgtd on
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 thevgcreate
command.# vgcreate virtstore /dev/md1
Create a LVM logical volume
Create a logical volume group named virtimage1 on the virtstore volume group with a size of 20GB using thelvcreate
command.# lvcreate --size 20G -n virtimage1 virtstore
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.# mkdir -p /var/lib/tgtd/virtualization
Create the image file
Create an image named virtimage2.img with a size of 10GB.# dd if=/dev/zero of=/var/lib/tgtd/virtualization/virtimage2.img bs=1M seek=10000 count=0
Configure SELinux file contexts
Configure the correct SELinux context for the new image and directory.# restorecon -R /var/lib/tgtd
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. Thetarget
attribute requires an iSCSI Qualified Name (IQN). The IQN is in the format:iqn.yyyy-mm.reversed domain name:optional identifier text
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.<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>
Ensure that the/etc/tgt/targets.conf
file contains thedefault-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 thetgtd
service to reload the configuration changes.# service tgtd restart
iptables configuration
Open port 3260 for iSCSI access withiptables
.# iptables -I INPUT -p tcp -m tcp --dport 3260 -j ACCEPT # service iptables save # service iptables restart
Verify the new targets
View the new targets to ensure the setup was successful with thetgt-admin --show
command.# 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
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.# iscsiadm --mode discovery --type sendtargets --portal server1.example.com 127.0.0.1:3260,1 iqn.2010-05.com.example.server1:iscsirhel6guest
Optional: Test attaching the device
Attach the new device (iqn.2010-05.com.example.server1:iscsirhel6guest) to determine whether the device can be attached.# 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.
Detach the device.# 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.