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
INSTALACJA MIB SNMP W SYSTEMIE CENTOS/RHEL 6
Viewed 12756 times since Fri, Nov 30, 2018
Understanding System auditing with auditd
Viewed 9386 times since Fri, Apr 5, 2019
Create a Linux Swap File
Viewed 2774 times since Fri, Jun 8, 2018
Transform XML to CSV Format | Unix String Pattern Manipulation The Ugly Way
Viewed 4907 times since Sun, Jan 9, 2022
RHEL7 slow ssh login
Viewed 4118 times since Tue, Aug 6, 2019
Managing temporary files with systemd-tmpfiles on Red Hat Enterprise Linux 7
Viewed 9303 times since Sun, Nov 22, 2020
Logowanie za pomocą kluczy Secure Shell
Viewed 2674 times since Thu, May 24, 2018
Linux - How to monitor memory usage
Viewed 2864 times since Fri, Jun 8, 2018
How to Install and use Lsyncd on CentOS 7 / RHEL 7 rsync
Viewed 4050 times since Wed, Oct 31, 2018
How to create a Systemd service in Linux
Viewed 2637 times since Mon, Dec 7, 2020