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
Linux Add a Swap File – HowTo
Viewed 3790 times since Fri, Jun 8, 2018
List usernames instead of uids with the ps command for long usernames
Viewed 470 times since Wed, Jul 25, 2018
KONTO SFTP Z CHROOTEM Z UŻYCIEM OPENSSH-SERVER NA CENTOS/RHEL6
Viewed 401 times since Fri, Nov 30, 2018
debian Install a newer kernel in Debian 9 (stretch) stable
Viewed 466 times since Sun, Sep 23, 2018
python learning
Viewed 368 times since Wed, Dec 18, 2019
Linux - How to monitor memory usage
Viewed 430 times since Fri, Jun 8, 2018
SSH: Execute Remote Command or Script – Linux
Viewed 393 times since Mon, Feb 18, 2019
Linux - How to get network speed and statistic of ethernet adapter in Linux
Viewed 497 times since Fri, Jun 8, 2018
RHEL: Force system to prompt for password in Single User mode
Viewed 1373 times since Sat, Jun 2, 2018
CentOS / RHEL 7 : Configuring an NFS server and NFS client Linux NFS
Viewed 453 times since Fri, Feb 21, 2020