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
Migrate a Linux System from Red Hat Enterprise to CentOS
Viewed 10412 times since Fri, May 15, 2020
SPRAWDZONA KONFIGURACJA RSYSLOG I LOGROTATE, JAKO ZEWNĘTRZNEGO SERWERA SYSLOG
Viewed 3897 times since Fri, Nov 30, 2018
How to Install and use Lsyncd on CentOS 7 / RHEL 7 rsync
Viewed 4429 times since Wed, Oct 31, 2018
Fałszujemy rozpoznania skanerów #1
Viewed 3094 times since Mon, May 21, 2018
18 Quick ‘lsof’ command examples for Linux Geeks
Viewed 11718 times since Sun, Jun 30, 2019
Easily Find Bugs In Shell Scripts With ShellCheck
Viewed 3394 times since Thu, Apr 18, 2019
Top 20 OpenSSH Server Best Security Practices ssh linux aix
Viewed 6067 times since Fri, May 15, 2020
Sample logrotate configuration and troubleshooting part 2
Viewed 9576 times since Fri, Nov 30, 2018
Secure NTP with NTS
Viewed 8522 times since Sun, Dec 6, 2020
Lsyncd: live file syncronization across multiple Linux servers
Viewed 7064 times since Wed, Oct 31, 2018