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

  • Linux named / bind how to dump, view and clear the cache!
  • Centos 6 / 7 / 8 How To Change Default nameservers in /etc/resolv.conf when using DHCP / dhclient
  • Adobe Acrobat Reader for Linux to use and view XFA Fillable Forms
  • Debian Linux Mint Ubuntu iptables save and restore settings automatically onboot and reboot
  • Why SMART is not smart at all and doesn't properly predict disk errors that cause a kernel panic or crash
  • scp: ambiguous target error and solution
  • VirtualBox How To Add iSCSI Storage using VBoxManage
  • iSCSI on Centos 7 Configuration and Setup Guide for Initiator and Target
  • Python and BeautifulSoup4's BS4's Decompose Method To Remove Unwanted Inner Tags
  • httpd AH00534: httpd: Configuration error: No MPM loaded. solution
  • bash script to remove modules from httpd.conf that are not actually installed
  • bash scripting how to create a function
  • Centos 7 PHP MySQL Not Working Solution
  • Bash How To Cut or Split Natively And Get The LAST Field
  • Bash Script How To Manipulate Text/Strings By Searchig and Replacing Natively
  • How Does Cisco CUCM (Cisco Unified Communication Manager) Work?
  • What DNS Options Does Active Directory Offer in Windows Server 2008,2012,2016 ?
  • syntax error, unexpected T_SL in PHP Solution
  • grep regular expression match number range between specific numbers
  • bash how to print out lines of text within a range from the first occurrence