How To Configure ISCSI Target Server

You are here:
< All Topics

 (Intro from Wikipedia)

 

 iSCSI an acronym for Internet Small Computer Systems Interface , an Internet Protocol (IP)-based storage networking standard for linking data storage facilities. It provides block-level access to storage devices by carrying SCSI commands over a TCP/IP network.

 

iSCSI is used to facilitate data transfers over intranets and to manage storage over long distances. It can be used to transmit data over local area networks (LANs), wide area networks (WANs), or the Internet and can enable location-independent data storage and retrieval.

 

The protocol allows clients (called initiators) to send SCSI commands (CDBs) to storage devices (targets) on remote servers. It is a storage area network (SAN) protocol, allowing organizations to consolidate storage into storage arrays while providing clients (such as database and web servers) with the illusion of locally attached SCSI disks.

 

iSCSI mainly competes with Fibre Channel, but unlike traditional Fibre Channel, which usually requires dedicated cabling, iSCSI can be run over long distances using existing network infrastructure.

 

 

POINTS TO WATCH WHEN CONFIGURING ISCSI

 

[root@centosstorage iscsi]# cat initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:7db3edc45
[root@centosstorage iscsi]#

 

Make sure you set

 

systemctl enable –now target

 

otherwise the iscsi configuration gets lost on reboots!

 

systemctl status target.service

 

 

To disconnect initiator client from target server

 

on the client do:

 

iscsiadm –mode node –logout

 

 

on ubuntu: to disable firewall:

 

root@storageserver:/# systemctl disable ufw
Synchronizing state of ufw.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install disable ufw
Removed /etc/systemd/system/multi-user.target.wants/ufw.service.
root@storageserver:/#
root@storageserver:/#

 

 

Installing Target ISCSI server on Ubuntu:

 

Preliminaries

 

note:
The Linux SCSI target framework, also known as TGT, can be used to create an iSCSI target server. TGT simplifies the creations and maintenance of iSCSI targets. TGT is supported by various Linux flavors (SUSE Linux, Fedora, RHEL, Debian, and Ubuntu). Execute the following command to install the TGT package.

 

root@LinuxSQL01:/# sudo apt-get install TGT

 

(I have NOT used TGT here – iscsi was already available in the ubuntu server installation)

 

Be sure to start and enable both iscsid and iscsi. Note that you will likely need to restart these if you edit the IQN of the initiator later.

 

 

systemctl enable iscsid iscsi
systemctl start iscsid iscsi

 

create the storage file:

 

root@storageserver:~# dd if=/dev/zero of=/storage/VHD1.img bs=10k count=100000
100000+0 records in
100000+0 records out
1024000000 bytes (1.0 GB, 977 MiB) copied, 1.44653 s, 708 MB/s
root@storageserver:~#

 

this creates a 1GB virtual disk

 

next use losetup to make the device available – this is NOT a file system mount — it must NOT be mounted for the iscsi to be able to access it.

 

 

check to see exactly which loop device is available, loop1 might already be taken on the machine!

 

use df to find out

 

on my VM loop5 is the next one free:

 

root@storageserver:~# losetup /dev/loop5 /storage/VHD1.img

 

NOTE if you reboot the storage server, then you first have to run losetup for your storage device before you can use iscsi!

 

 

the iscsi port must be open, otherwise clients cannot connect to the target!

 

on the server:

 

firewall-cmd –permanent –add-port=3260/tcp

 

then do a

 

firewall-cmd –reload

 

then call up

 

[root@clusterserver ~]# targetcli

 

root@storageserver:~# apt install targetcli-fb

 

ISCSI TARGET CONFIG using targetcli

 

The ISCSI server which manages connections to the storage is known as the target.

 

NOTE the iSCSI target drive must be UNMOUNTED before configuring for iSCSI

 

Configuration of the target is carried out using a commandline interface tool called targetcli. This can be used as pure command line commands, or alternatively in interactive mode. The description below refers to the interactive mode.

 

[root@centosstorage iscsi]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type ‘help’.

/>

 

First, create the backstore/s. These are the data storage devices. They can be physical or virtual drives.

 

The types of backstores are described as follows:

 

block: Linux block devices such as /dev/sda
fileio: Any file on a mounted file system such as /tmp/disk1.img
pscsi: Any storage object that supports pass-through SCSI commands
ramdisk: Memory copy RAM disks

 

/> /backstores/block create lun0 /dev/loop1
Created block storage object lun0 using /dev/loop1.
/>

 

NOTE: if you dont have a physical storage device available, for testing purposes, you can simply create an iSCSI target for a
disk file by using the backstores fileio command, for example as follows:

 

/backstores/fileio create lun0 /media/storage/VHD1.img 100M

 

This creates a 100MB virtual drive file.

 

Then create the iscsi IQN target for the server. The IQN is a globally-unique identifying number for the server.

 

/> /iscsi create
Created target iqn.2003-01.org.linux-iscsi.centosstorage.x8664:sn.3ad620590c10.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/>

 

Then add the lun to the iscsi system using the IQN we have just created for the server:

 

/iscsi/iqn.20…c10/tpg1/luns> create /backstores/block/lun0
Created LUN 0.
/iscsi/iqn.20…c10/tpg1/luns>

/iscsi/iqn.20…c10/tpg1/luns> ls
o- luns …………………………………………………………………………………………………… [LUNs: 1]
o- lun0 ………………………………………………………………….. [block/lun0 (/dev/loop1) (default_tg_pt_gp)]
/iscsi/iqn.20…c10/tpg1/luns>

 

 

ADD THE ACL PERMISSION:

 

Note we use tpgi and the iqn of the server and the client: tpg1 means target permission group 1

 

you need the client initiator iqn names for this. Call them up on the client machines from shell command line:

 

cat /etc/iscsi/initiatorname.iscsi

 

[root@centos1 ~]# cat /etc/iscsi/initiatorname.iscsi

InitiatorName=iqn.1994-05.com.redhat:d1136c5524b9

 

NOTE – if you clone machines, a NEW hostname, ip, mac: means a new iscsi iqn!

 

if the iqn is identical with the other nodes (due to Oracle VM machine cloning), then you need to do following to generate a new unique iqn for the node:

 

mv /etc/iscsi/initiatorname.iscsi /var/tmp/initiatorname.iscsi.backup
echo “InitiatorName=`/sbin/iscsi-iname`” > /etc/iscsi/initiatorname.iscsi
cat /etc/iscsi/initiatorname.iscsi

 

root@ubuntu2:~# mv /etc/iscsi/initiatorname.iscsi /var/tmp/initiatorname.iscsi.backup
root@ubuntu2:~# echo “InitiatorName=`/sbin/iscsi-iname`” > /etc/iscsi/initiatorname.iscsi
root@ubuntu2:~# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2005-03.org.open-iscsi:48e32ccf636f
root@ubuntu2:~#

 

/>

 

then in targetcli on the target iscsi server ie centossstorage, you need to do this for each client who wishes to connect to the target.

 

 

/> /iscsi/iqn.2003-01.org.linux-iscsi.centosstorage.x8664:sn.3ad620590c10/tpg1/acls create iqn.1994-05.com.redhat:d1136c5524b9
Created Node ACL for iqn.1994-05.com.redhat:d1136c5524b9
Created mapped LUN 0.

/>

/> ls
o- / …………………………………………………………………………………………………………. […]
o- backstores ……………………………………………………………………………………………….. […]
| o- block …………………………………………………………………………………….. [Storage Objects: 1]
| | o- lun0 ………………………………………………………………… [/dev/loop1 (4.7GiB) write-thru activated]
| | o- alua ……………………………………………………………………………………… [ALUA Groups: 1]
| | o- default_tg_pt_gp …………………………………………………………….. [ALUA state: Active/optimized]
| o- fileio ……………………………………………………………………………………. [Storage Objects: 0]
| o- pscsi …………………………………………………………………………………….. [Storage Objects: 0]
| o- ramdisk …………………………………………………………………………………… [Storage Objects: 0]
o- iscsi ……………………………………………………………………………………………… [Targets: 1]
| o- iqn.2003-01.org.linux-iscsi.centosstorage.x8664:sn.3ad620590c10 …………………………………………… [TPGs: 1]
| o- tpg1 ………………………………………………………………………………….. [no-gen-acls, no-auth]
| o- acls ……………………………………………………………………………………………. [ACLs: 3]
| | o- iqn.1994-05.com.redhat:ce78a43c3f55 ………………………………………………………… [Mapped LUNs: 1]
| | | o- mapped_lun0 ………………………………………………………………………. [lun0 block/lun0 (rw)]
| | o- iqn.1994-05.com.redhat:d1136c5524b9 ………………………………………………………… [Mapped LUNs: 1]
| | | o- mapped_lun0 ………………………………………………………………………. [lun0 block/lun0 (rw)]
| | o- iqn.1994-05.com.redhat:e6a379479d2 …………………………………………………………. [Mapped LUNs: 1]
| | o- mapped_lun0 ………………………………………………………………………. [lun0 block/lun0 (rw)]
| o- luns ……………………………………………………………………………………………. [LUNs: 1]
| | o- lun0 …………………………………………………………… [block/lun0 (/dev/loop1) (default_tg_pt_gp)]
| o- portals ………………………………………………………………………………………. [Portals: 1]
| o- 0.0.0.0:3260 ……………………………………………………………………………………….. [OK]
o- loopback …………………………………………………………………………………………… [Targets: 0]
/>

 

 

next do a saveconfig:

 

/> saveconfig

Configuration saved to /etc/target/saveconfig.json

/>
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
[root@centosstorage iscsi]#

 

NOTE: to restore the config, use:

 

/> restoreconfig VHD1.img

 

 

IMPORTANT

 

make sure you set

 

systemctl enable –now target

 

otherwise the iscsi configuration gets lost on reboots!

 

 

Table of Contents