🌐 🇵🇱 Polski · 🇬🇧 EN
The iSCSI protocol is a typical client-server protocol. This tool allows you to expose a disk resource (target) to a client, which is called an initiator. iSCSI refers to the server providing virtual disks over the network as an iSCSI "target". The client mounting these disks is called an initiator, which makes sense considering that iSCSI commands originate from the client and the server responds to them. In an iSCSI relationship, separate software components are responsible for the implementation of the target and the initiator. All modern operating systems include an initiator (though it is sometimes an optional component), and most systems already have a built-in target implementation. The iSCSI standard specification is defined in document RFC 3720.
There were at least four different iSCSI initiator implementations for Linux environments. Several died a natural death, while others were merged. The only one that has survived to this day appears to be Open-iSCSI, the standard initiator available for all Linux distributions. To use it, we install the open-iscsi package on Ubuntu or iscsi-initiator-utils on RedHat systems.
CONFIGURING THE SHARED DISK RESOURCE (TARGET)
Step 1 - Installing the required packages.
# yum install -y scsi-target-utils.i686
Step 2 - Verifying that the package is installed and available on the system
# rpm -qa | grep scsi
scsi-target-utils-1.0.14-4.el6.i686
Step 3 - Setting the service to start on system boot/reboot
# chkconfig tgtd on
Step 4 - Checking startup settings
# chkconfig tgtd --list
tgtd 0:off 1:off 2:on 3:on 4:on 5:on 6:off
The tgtadm tool along with its available switches is used to configure the sharing.
A list of switches can be found in the system manual and can be accessed by running the command:
man tgtadm
CONFIGURING THE SHARED RESOURCE
Step 1 - Creating a target
# tgtadm --lld iscsi --op new --mode target --tid 1 --targetname nowy_target
Step 2 - Verifying that the new target has been created
# tgtadm --lld iscsi --op show --mode target
Target 1: nowy_target
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:
Account information:
ACL information:
As shown above, the new target has been created and already contains a new Logical Unit - LUN 0, which is used to manage the target. You can also see the assigned name (nowy_target) and the iscsi driver used.
Step 3 - Creating a new custom Logical Unit (LUN)
# tgtadm --lld iscsi --op new --mode logicalunit --tid 1 --lun 1 --backing-store /dev/sdb2
Step 4 - Verifying the creation of the new LUN
# tgtadm --lld iscsi --op show --mode target
Target 1: nowy_target
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: IET 00010001
SCSI SN: beaf11
Size: 2155 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb2
Backing store flags:
Account information:
ACL information:
BASIC SECURITY SETTINGS
When checking and displaying information about the created target and LUN, the last line contains: ACL information, which defines access rights to the created LUN.
Step 1 - Restricting resource sharing to a selected host
# tgtadm --lld iscsi --op bind --mode target --tid 1 --initiator-address 192.168.56.101
Step 2 - Verifying the changes made
# tgtadm --lld iscsi --op show --mode target
Target 1: nowy_target
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: IET 00010001
SCSI SN: beaf11
Size: 2155 MB, Block size: 512
Online: Yes
Removable media: No
Readonly: No
Backing store type: rdwr
Backing store path: /dev/sdb2
Backing store flags:
Account information:
ACL information:
192.168.56.101
CONFIGURING SYSTEM FIREWALL - IPTABLES
Step 1 - Checking which port the tgtd service is running on
# netstat -taupen | grep tgtd
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN 0 15896 2048/tgtd
tcp 0 0 :::3260 :::* LISTEN 0 15897 2048/tgtd
Step 2 - Adding appropriate rules to the iptables system firewall
# iptables -I INPUT 16 -p tcp -m tcp --dport 3260 -j ACCEPT
After performing the steps above, the selected resource is shared. In our case, it was /dev/sdb2.
SAVING THE CONFIGURATION
If all the steps above have been performed correctly, it would be useful to enable sharing after a system reboot. The target configuration is located in the file:
/etc/tgt/targets.conf
In this file, we save information about the created target.
Step 1 - Generating current information about the configured target.
# tgt-admin --dump
default-driver iscsi
<target nowy_target>
backing-store /dev/sdb2
initiator-address 192.168.56.101
</target>
This information must be included in /etc/tgt/targets.conf, so you can redirect it immediately
# tgt-admin --dump > /etc/tgt/targets.conf
CONFIGURING THE INITIATOR - CLIENT
Step 1 - Installing the required packages
# yum install -y iscsi-initiator-utils.i686
Step 2 - Verifying package installation
# rpm -qa | grep scsi
iscsi-initiator-utils-6.2.0.872-34.el6.i686
Step 3 - Setting the service to start on system boot
NOTE
The services will be started provided that the target to be mounted has been set beforehand.
After installation, the services are configured to be started with the system
# chkconfig --list | grep scsi
iscsi 0:off 1:off 2:off 3:on 4:on 5:on 6:off
iscsid 0:off 1:off 2:off 3:on 4:on 5:on 6:off
DISCOVERING THE SHARED TARGET
Step 1 - Discovering the shared resource
As before, the system manual will be useful here, where we will find all the necessary commands:
# man iscsiadm
commands are in the EXAMPLES section
Discovering a new resource
# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.56.102 --discover
192.168.56.102:3260,1 nowy_target
Step 2 - Logging in to the new resource by providing the target name and host address
# iscsiadm --mode node --targetname nowy_target --portal 192.168.56.102:3260 --login
Logging in to [iface: default, target: nowy_target, portal: 192.168.56.102,3260] (multiple)
Login to [iface: default, target: nowy_target, portal: 192.168.56.102,3260] successful.
Step 3 - Verifying the connection of the new resource
# cat /proc/partitions
major minor #blocks name
8 0 20971520 sda
8 1 512000 sda1
8 2 20458496 sda2
253 0 18391040 dm-0
253 1 2064384 dm-1
8 16 2104515 sdb
If you want to disconnect the resource, run the command:
# iscsiadm --mode node --targetname nowy_target --portal 192.168.56.102:3260 --logout
Logging out of session [sid: 1, target: nowy_target, portal: 192.168.56.102,3260]
Logout of [sid: 1, target: nowy_target, portal: 192.168.56.2,3260] successful.
# iscsiadm --mode node --targetname nowy_target --portal 192.168.56.102:3260 --logout
Logging out of session [sid: 1, target: nowy_target, portal: 192.168.56.102,3260]
Logout of [sid: 1, target: nowy_target, portal: 192.168.56.2,3260] successful.

Comments