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
Check a Website Availability from the Linux Command Line
Viewed 6166 times since Mon, Feb 18, 2019
How to create stunnel with systemd? stunnel
Viewed 8581 times since Thu, Jan 16, 2020
Procedura powiekszania OCFS2 online
Viewed 5180 times since Fri, Jun 8, 2018
RHEL: Handling SCSI disks
Viewed 11987 times since Sun, May 27, 2018
How to deal with dmesg timestamps
Viewed 2756 times since Wed, Oct 3, 2018
Monitoring bezpieczeństwa Linux: integracja auditd + OSSEC cz. I
Viewed 2132 times since Fri, Apr 5, 2019
Epoch & Unix Timestamp Conversion Tools
Viewed 45629 times since Fri, Jun 22, 2018
10 Linux rsync Examples to Exclude Files/Directories
Viewed 10490 times since Wed, Oct 31, 2018
Expand or grow a file system on a Linux VMWare VM without downtime
Viewed 11348 times since Fri, Jul 27, 2018
YUM CRON Enabling automatic updates in Centos 7 and RHEL 7
Viewed 11656 times since Fri, Oct 26, 2018