RHEL: iSCSI target/initiator configuration on RHEL6

RHEL: iSCSI target/initiator configuration on RHEL6

# Tested on RHEL 6


# iSCSI target configuration
# ------------------------------------------------------------------------------------------

# Required package: scsi-target-utils
# Some documentation: /usr/share/doc/scsi-target-utils-X.X.XX/README.iscsi

# This recipe is about exporting one storage device (LVM volume, disk partition,...),
# a target, using the iSCSI protocol in a way that clients can connect to it remotely

# For this example I'm exporting a LVM logical volume like following one:

lvcreate -n myscsilv -L 4G myvg


# Target creation (iSCSI Qualified Name - IQN - )

tgtadm --lld iscsi --op new --mode target --tid 1 -T <iqn.2014-06.com.example.myserver:myiscsi>


# Let's associate a device (our logical volume) to the target we've just created

tgtadm --lld iscsi --op new --mode logicalunit --tid <1> --lun <1> -b </dev/myvg/myscsilv>


# And authorize initiators to connect to our target

tgtadm --lld iscsi --op bind --mode target --tid 1 -I 172.257.1/24
tgtadm --lld iscsi --op bind --mode target --tid 1 -I 172.257.2/24
tgtadm --lld iscsi --op bind --mode target --tid 1 -I 172.257.3/24


# DO NOT FORGET to dump configuration to config. file

cp -p /etc/tgt/targets.conf /etc/tgt/targets.conf.orig

tgt-admin --dump > /etc/tgt/targets.conf

cat targets.conf
   default-driver iscsi

   <target iqn.2014-06.com.example.myserver:myiscsi>
         backing-store /dev/myvg/myscsilv
         initiator-address 172.257.1/24
         initiator-address 172.257.2/24
         initiator-address 172.257.3/24
   </target>

# Finaly, enable and restart tgtd daemon

chkconfig tgtd on
service tgtd restart


# Some of the properties like vendor, SN or scsi ID may be modified like this:

vi targets.conf
   default-driver iscsi

   <target iqn.2014-06.com.example.myserver:myiscsi>
         <backing-store /dev/myvg/myscsilv>
             vendor_id MyVendor
             scsi_sn 1234567890
             scsi_id MyDisc-myscsilv
         </backing-store>
         initiator-address 172.257.1/24
         initiator-address 172.257.2/24
         initiator-address 172.257.3/24
   </target>


service tgtd restart


tgt-admin -s
   Target 1: iqn.2014-06.com.example.myserver:myiscsi
       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, Block size: 1
               Online: Yes
               Removable media: No
               Readonly: No
               Backing store type: null
               Backing store path: None
               Backing store flags:
           LUN: 1
               Type: disk
     -->       SCSI ID: MyDisc-myscsilv
     -->       SCSI SN: 1234567890
               Size: 4295 MB, Block size: 512
               Online: Yes
               Removable media: No
               Readonly: No
               Backing store type: rdwr
               Backing store path: /dev/myvg/myscsilv
               Backing store flags:
       Account information:
       ACL information:
           172.257.1/24
           172.257.2/24
           172.257.3/24





# iSCSI initiator configuration
# ------------------------------------------------------------------------------------------

# Required package: iscsi-initiator-utils

# We are connecting to a storage device (LVM volume, disk partition,...), a target, being
# using exported by a remote server, using the iSCSI protocol

# Ensure that iscsi daemon is started and enabled for changes to persist across reboots

chkconfig iscsi on
service iscsi restart


# Discover iSCSI target(s) being shared by remote server

iscsiadm --mode discoverydb --type sendtargets --portal <172.257.7.4> --discover
   172.257.7.4:3260,1 iqn.2014-06.com.example.myserver:myiscsi

# or # iscsiadm -m discovery -t st -p <172.257.7.4>



# Login to iSCSI target; take we must be authorized to connect on remote server

iscsiadm -m node -T <iqn.2014-06.com.example.myserver:myiscsi> -p <172.257.7.4> -l
   Logging in to [iface: default, target: iqn.2014-06.com.example.myserver:myiscsi, portal: 172.257.7.4,3260] (multiple)
   Login to [iface: default, target: iqn.2014-06.com.example.myserver:myiscsi, portal: 172.257.7.4,3260] successful.

# Note that this attachment is persistent across reboot, even if we disconnect from iSCSI target

# Check

dmesg
[...]
   sd 2:0:0:1: [sda] 8388608 512-byte logical blocks: (4.29 GB/4.00 GiB)
   sd 2:0:0:1: [sda] Write Protect is off
   sd 2:0:0:1: [sda] Mode Sense: 49 00 00 08
   sd 2:0:0:1: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
    sda: unknown partition table
   sd 2:0:0:1: [sda] Attached SCSI disk
   scsi 2:0:0:0: Attached scsi generic sg0 type 12
   sd 2:0:0:1: Attached scsi generic sg1 type 0

lvmdiskscan | grep sda
     /dev/sda        [       4.00 GiB]



# Stop using a target

iscsiadm -m node -T <iqn.2014-06.com.example.myserver:myiscsi> -p <172.257.7.4> -u

# This will not remove the configuration for this target. As long as "node.startup" is set to
# "automatic" in /etc/iscsi/iscsid.conf file, this target will be rediscovered next time
# iscsi daemon is restarted. This means too that any modification in configuration should be
# done before descovering targets. Otherwise, changes will not take effect on already
# connected targets. For the target to be effectively removed, run following command:

iscsiadm -m node -T <iqn.2014-06.com.example.myserver:myiscsi> -p <172.257.7.4> --op delete
0 (0)
Article Rating (No Votes)
Rate this article
Attachments
There are no attachments for this article.
Comments
There are no comments for this article. Be the first to post a comment.
Full Name
Email Address
Security Code Security Code
Related Articles RSS Feed
Do you Know These 5 Use of V$session View ?
Viewed 114479 times since Thu, Jun 21, 2018
Linux RedHat How To Create An RPM Package
Viewed 3394 times since Sun, Jan 9, 2022
logrotate Log Rotate Configuration
Viewed 3316 times since Sun, Jan 12, 2020
debian Debian/Ubuntu Linux: Find If Installed APT Package Includes a Fix/Patch Via CVE Number
Viewed 9598 times since Sun, Sep 23, 2018
RHCS6: Mirror/unmirror a GFS2 volume
Viewed 5388 times since Sun, Jun 3, 2018
Watchdog script to keep an application running
Viewed 18874 times since Tue, Jul 31, 2018
Using grep to find string in files
Viewed 2389 times since Fri, May 15, 2020
zabbix linux How to solve apache error No space left on device: Cannot create SSLMutex
Viewed 2557 times since Wed, Nov 11, 2020
LVM: Reduce SWAP size by shrinking existing Logical Volume
Viewed 6373 times since Sat, Jun 2, 2018
HowTo: Find Out Hard Disk Specs / Details on Linux
Viewed 3684 times since Mon, Jan 28, 2019