iSCSI on Centos 7 Configuration and Setup Guide for Initiator and Target

initiator = client

target = server

These are the first concepts you should understand which is that in iscsi essentially the "initiator" is the client and the "target" is the server.

iSCSI is derived from the old fashioned SCSI that us oldtimers grew to love.  The "i" stands for Internet and the SCSI stands for "Small Computers Systems Interface" (SCSI).

iSCSI Target (Server) Setup

targetcli is the package that creates the iSCSI server and allows you to export your devices. 

yum -y install targetcli

Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: centos.ca-west.mirror.fullhost.io
 * epel: mirrors.cat.pdx.edu
 * extras: centos.ca-west.mirror.fullhost.io
 * updates: centos.ca-west.mirror.fullhost.io
Resolving Dependencies
--> Running transaction check
---> Package targetcli.noarch 0:2.1.fb46-6.el7_5 will be updated
---> Package targetcli.noarch 0:2.1.fb46-7.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package            Arch            Version                 Repository     Size
================================================================================
Updating:
 targetcli          noarch          2.1.fb46-7.el7          base           67 k

Transaction Summary
================================================================================
Upgrade  1 Package

Total download size: 67 k
Downloading packages:
No Presto metadata available for base
targetcli-2.1.fb46-7.el7.noarch.rpm                        |  67 kB   00:00    
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : targetcli-2.1.fb46-7.el7.noarch                              1/2
  Cleanup    : targetcli-2.1.fb46-6.el7_5.noarch                            2/2
  Verifying  : targetcli-2.1.fb46-7.el7.noarch                              1/2
  Verifying  : targetcli-2.1.fb46-6.el7_5.noarch                            2/2

Updated:
  targetcli.noarch 0:2.1.fb46-7.el7                                            

Complete!

 

systemctl enable target

systemctl start target

systemctl disable firewalld

systemctl stop firewalld

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


 

Launch targetcli to configure our iSCSI target

targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb46
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/>

Let's see what block storage/backing devices we have?

/> cd backstores/block
/backstores/block> ls
o- block .................................................. [Storage Objects: 0]
/backstores/block>

Create our iSCSI disk

/backstores/block> create areebsfault /dev/sdb
Created block storage object areebsfault using /dev/sdb.

Create our target

The "iqn" must go first and then year-time and then local and finally the "host name" and after the colon the target name "sdb".  IQN= iSCSI Qualified Name

  • iqn
  • Date (1982-01)
  • Reversed domain name of the authority (eg. target.abcrandom.local) becomes local.abcrandom.target
  • Optional “:” that prefixes a storage target name specified by the naming authority

 

cd /iscsi

/iscsi> create iqn.2018-12.local.abcrandom.target:sdb
Created target iqn.2018-12.local.abcrandom.target:sdb.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.

Do we have any LUN?

/iscsi/iqn.20...sdb/tpg1/acls> cd /iscsi/iqn.2018-12.local.abcrandom.target:sdb/
/iscsi/iqn.20...om.target:sdb> ls
o- iqn.2018-12.local.abcrandom.target:sdb ............................ [TPGs: 1]
  o- tpg1 ............................................... [no-gen-acls, no-auth]
    o- acls .......................................................... [ACLs: 0]
    o- luns .......................................................... [LUNs: 0]
    o- portals .................................................... [Portals: 1]
      o- 0.0.0.0:3260 ..................................................... [OK]

Create our LUN

cd /iscsi/iqn.2018-12.local.abcrandom.target:sdb/tpg1/luns


/iscsi/iqn.20...sdb/tpg1/luns> create /backstores/block/areebsfault lun1
Created LUN 1.

/iscsi/iqn.20...sdb/tpg1/luns> ls
o- luns .............................................................. [LUNs: 1]
  o- lun1 .................... [block/areebsfault (/dev/sdb) (default_tg_pt_gp)]

Create ACL so our initiator can connect


cd /iscsi/iqn.2018-12.local.abcrandom.target:sdb/tpg1/acls


/iscsi/iqn.20...sdb/tpg1/acls> create iqn.1982-01.ca.bla.tld:abc123
Created Node ACL for iqn.1982-01.ca.bla.tld:abc123
Created mapped LUN 1.

*Note the iqn for this ACL as you will need to use it in the clientside (initiator setup).

 

Client Side Setup

systemctl disable firewalld

systemctl stop firewalld

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

yum -y install iscsi-initiator-utils
 

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.its.sfu.ca
 * extras: mirror.its.sfu.ca
 * updates: mirror.its.sfu.ca
Resolving Dependencies
--> Running transaction check
---> Package iscsi-initiator-utils.x86_64 0:6.2.0.874-10.el7 will be installed
--> Processing Dependency: iscsi-initiator-utils-iscsiuio >= 6.2.0.874-10.el7 for package: iscsi-initiator-utils-6.2.0.874-10.el7.x86_64
--> Running transaction check
---> Package iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.874-10.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                           Arch      Version              Repository
                                                                           Size
================================================================================
Installing:
 iscsi-initiator-utils             x86_64    6.2.0.874-10.el7     base    421 k
Installing for dependencies:
 iscsi-initiator-utils-iscsiuio    x86_64    6.2.0.874-10.el7     base     92 k

Transaction Summary
================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 513 k
Installed size: 2.6 M
Downloading packages:
(1/2): iscsi-initiator-utils-6.2.0.874-10.el7.x86_64.rpm   | 421 kB   00:00    
(2/2): iscsi-initiator-utils-iscsiuio-6.2.0.874-10.el7.x86 |  92 kB   00:00    
--------------------------------------------------------------------------------
Total                                              977 kB/s | 513 kB  00:00    
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : iscsi-initiator-utils-6.2.0.874-10.el7.x86_64                1/2
  Installing : iscsi-initiator-utils-iscsiuio-6.2.0.874-10.el7.x86_64       2/2
  Verifying  : iscsi-initiator-utils-iscsiuio-6.2.0.874-10.el7.x86_64       1/2
  Verifying  : iscsi-initiator-utils-6.2.0.874-10.el7.x86_64                2/2

Installed:
  iscsi-initiator-utils.x86_64 0:6.2.0.874-10.el7                              

Dependency Installed:
  iscsi-initiator-utils-iscsiuio.x86_64 0:6.2.0.874-10.el7                     

Complete!

Edit initiatorname.iscsi

vi /etc/iscsi/initiatorname.iscsi

You can also use the echo command (make sure you use the correct iqn):

echo "InitiatorName=iqn.1982-01.ca.bla.tld:abc123" > /etc/iscsi/initiatorname.iscsi

Start and Enable iscsid

[root@localhost ~]# systemctl start iscsid
[root@localhost ~]# systemctl enable iscsid
Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.

Find Targets!

iscsiadm -m discovery --type sendtargets -p 192.168.1.91
192.168.1.91:3260,1 iqn.2018-12.local.abcrandom.target:sdb

If all is well you should see this with ls

ls /var/lib/iscsi/nodes
iqn.2018-12.local.abcrandom.target:sdb
[root@localhost ~]# ls /var/lib/iscsi/
ifaces/       nodes/        slp/         
isns/         send_targets/ static/      
[root@localhost ~]# ls /var/lib/iscsi/send_targets/
192.168.1.91,3260

Mount all iscsi targets

iscsiadm -m node -l
Logging in to [iface: default, target: iqn.2018-12.local.abcrandom.target:sdb, portal: 192.168.1.91,3260] (multiple)
Login to [iface: default, target: iqn.2018-12.local.abcrandom.target:sdb, portal: 192.168.1.91,3260] successful.

 

You should now see a /dev/sdb available that you can format like a normal disk.
 

cat /proc/partitions
major minor  #blocks  name

  11        0    1048575 sr0
   8        0   15728640 sda
   8        1    1048576 sda1
   8        2   14679040 sda2
 253        0   13103104 dm-0
 253        1    1572864 dm-1
   8       16       4096 sdb

 

Set it for onboot loading

 mkfs.ext4 /dev/sdb1
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=32764 blocks
1024 inodes, 4092 blocks
204 blocks (4.99%) reserved for the super user
First data block=1
Maximum filesystem blocks=4194304
1 block group
8192 blocks per group, 8192 fragments per group
1024 inodes per group

Allocating group tables: done                           
Writing inode tables: done                           
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

[root@localhost ~]# blkid /dev/sdb1
/dev/sdb1: UUID="7c1b6358-24b0-4296-b099-13eb1100f72e" TYPE="ext4"

add something like this to /etcfstab

UUID=7c1b6358-24b0-4296-b099-13eb1100f72e /mnt/iscsi ext4 _netdev 0 0

Troubleshooting Common Issues

  1. Firewall Issues.  Make sure firewalls are disabled or port 3260 is enabled.
  2. Listening on the wrong IP or port in your portal.
  3. Specifying the target instead of the initiator name/ACL name.
  4. Not creating an LUN
  5. Mixing up different target names with the wrong initiator name.
  6. The client side is using the wrong initiator name (often a random generated one by the OS).

How To

Login To All Targets

iscsiadm -m node -l

Login To Specific Target

iscsiadm -m node -l -T iqn.target.name:bla

Delete your iscsi target

/iscsi> cd /iscsi/
/iscsi> delete iqn.2016-06.localb.a.bla:123
Deleted Target iqn.2016-06.localb.a.bla:123.

Disconnect your client from a target

iscsiadm -m node --logout -T iqn.2018-12.local.abcrandom.target:sdb
Logging out of session [sid: 1, target: iqn.2018-12.local.abcrandom.target:sdb, portal: 192.168.1.91,3260]
Logout of [sid: 1, target: iqn.2018-12.local.abcrandom.target:sdb, portal: 192.168.1.91,3260] successful.

 

Disconnect from ALL targets

iscsiadm -m node --logout all
Logging out of session [sid: 2, target: iqn.2018-12.local.abcrandom.target:sdb, portal: 192.168.1.91,3260]
Logout of [sid: 2, target: iqn.2018-12.local.abcrandom.target:sdb, portal: 192.168.1.91,3260] successful.

 


Tags:

iscsi, centos, configuration, initiator, targetinitiator, server, concepts, essentially, quot, derived, scsi, oldtimers, interface, targetcli, creates, allows, export, devices, yum, install, plugins, fastestmirror, langpacks, loading, speeds, cached, hostfile, ca, fullhost, io, epel, mirrors, pdx, edu, extras, updates, resolving, dependencies, transaction, noarch, fb, _, updated, update, dependency, resolution, resolved, repository, updating, summary, upgrade, download, downloading, packages, presto, metadata, rpm, kb, succeeded, cleanup, verifying, configure, preferences, prefs, bin, shell, copyright, datera, inc, commands, backing, backstores, ls, objects, disk, areebsfault, dev, sdb, iqn, colon, abcrandom, tpg, global, pref, auto_add_default_portal, default, portal, ips, acl, om,

Latest Articles

  • How To Install OpenProject on Centos 7 Step-by-Step Guide
  • Ubuntu Debian Linux Cannot Install Wine Solution - wine1.6 : Depends: wine1.6-i386 (= 1:1.6.2-0ubuntu14.2) but it is not installable wine1.4 : Depends: wine1.6 but it is not going to be installed
  • How To Install python 3.4 3.5 and up on Linux with wine - Working Solution
  • using Xvfb on virtual remote ssh server to have X graphical programs work
  • ssh Received disconnect from port 22:2: Too many authentication failures
  • named bind errors - DNSKEY: unable to find a DNSKEY which verifies the DNSKEY RRset and also matches a trusted key for '.'
  • OpenVZ vs LXC DIR mode poor security in LXC
  • httpd: Syntax error on line 221 of /etc/httpd/conf/httpd.conf: Syntax error on line 6 of /etc/httpd/conf.d/php.conf: Cannot load modules/libphp5.so into server: /lib64/libresolv.so.2: symbol __h_errno, version GLIBC_PRIVATE not defined in file libc.s
  • Radeon R3 GPU on Debian Crashing
  • MySQL 5.7 on Debian and Ubuntu - How To Reset Root Password
  • SSH and sshfs timeout settings keepalive
  • Linux How To Add User To Additional Group
  • Howto Set Static IP on boot in initramfs for dropbear or other purposes NFS, Linux, Debian, Ubuntu, CentOS
  • Convert and install to LUKS Encrypted Drive Ubuntu 18.04 19.10 Linux Mint and Debian Based Linux
  • Debian and Netplan
  • CentOS 8 how to restart the network!
  • CentOS 8 how to convert to a bootable mdadm RAID software array
  • ADATA USB Thumb Drive Issues
  • KMODE EXCEPTION NOT HANDLED - QEMU/KVM Won't Boot Windows 2016 or 10 Image or Physical Machine
  • Linux Mint / Ubuntu / Debian Mate Disable Guest Session and Hide Usernames on Lightdm Login screen GUI