How to Configure Storage Server with iSCSI in Redhat and Centos 7

0
1619

Let me start with wikipedia definition of  ISCSi . In computing, iSCSI is 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.

How to Configure Storage Server with iSCSI in Redhat and Centos 7

My System : 

Available  disks 

 

We will use /dev/sdb as iscsi disk, and  before that we need to install some needed package to make this possible:

#yum  install   targetcli

===========================================================================================================
 Package Arch Version Repository Size
===========================================================================================================
Installing:
 targetcli noarch 2.1.fb46-1.el7 base 64 k
Installing for dependencies:
 libnl x86_64 1.1.4-3.el7 base 128 k
 pyparsing noarch 1.5.6-9.el7 base 94 k
 python-configshell noarch 1:1.1.fb23-3.el7 base 67 k
 python-ethtool x86_64 0.8-5.el7 base 33 k
 python-kmod x86_64 0.9-4.el7 base 57 k
 python-rtslib noarch 2.1.fb63-2.el7 base 97 k
 python-six noarch 1.9.0-2.el7 base 29 k
 python-urwid x86_64 1.1.1-3.el7 base 654 k

installing targetcli is generating python-rtslib package, which provides the /usr/lib/systemd/system/target.service file.

Lets Enable and start the server

# systemctl enable target
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.

# systemctl start target

Start The Targetcli  Console

# 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'.
/backstores/block> create disk1 /dev/sdb
Created block storage object disk1 using /dev/sdb.
/backstores/block> /backstores/fileio
####### Or  disk based on created file
/backstores/fileio> create disk2 /root/disk2.img 3G
Created fileio disk2 with size 3221225472
/backstores/fileio>

you can always  use command ” ls ” to see the created Contents.

/> ls 
o- / ................................................................................................................ [...]
 o- backstores ..................................................................................................... [...]
 | o- block ......................................................................................... [Storage Objects: 1]
 | | o- disk1 ................................................................. [/dev/sdb (5.0GiB) write-thru deactivated]
 | | o- alua .......................................................................................... [ALUA Groups: 1]
 | | o- default_tg_pt_gp .............................................................. [ALUA state: Active/optimized]
 | o- fileio ........................................................................................ [Storage Objects: 1]
 | | o- disk2 .......................................................... [/root/disk2.img (3.0GiB) write-back deactivated]
 | | o- alua .......................................................................................... [ALUA Groups: 1]
 | | o- default_tg_pt_gp .............................................................. [ALUA state: Active/optimized]
 | o- pscsi ......................................................................................... [Storage Objects: 0]
 | o- ramdisk ....................................................................................... [Storage Objects: 0]
 o- iscsi ................................................................................................... [Targets: 0]
 o- loopback ................................................................................................ [Targets: 0]
/>

 

 

Create and Configure ISCSI Qualified  name (IQN)

/iscsi> create iqn.2018-04.org.osradar.com.centos7.disk1
Created target iqn.2018-04.org.osradar.com.centos7.disk1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi>

Configure ACL

its Access Control Lists (ACLs) to  restrict access to LUNs from remote systems  (it’s the IQN of an initiator you permit to connect)

you can create it like this :

/iscsi/iqn.20...sk1/tpg1/acls> create iqn.2018-04.org.osradar.com.centos7.share
Created Node ACL for iqn.2018-04.org.osradar.com.centos7.share
/iscsi/iqn.20...sk1/tpg1/acls>

Target Portal Group (TPG)

The default portal of 0.0.0.0:3260 allows the iSCSI server to listen on all IPv4 addresses on port 3260. u can also specify the IP address if you like

/iscsi/iqn.20.../tpg1/portals> ls
o- portals ............................................................................................................ [Portals: 1]
 o- 0.0.0.0:3260 ............................................................................................................. [OK]
/iscsi/iqn.20.../tpg1/portals>

Adding ISCSI disken to Target Portal Group

/iscsi/iqn.20...sk1/tpg1/luns> create /backstores/block/disk1 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2018-04.org.osradar.com.centos7.share
/iscsi/iqn.20...sk1/tpg1/luns> create /backstores/fileio/disk2 
Created LUN 1.
Created LUN 1->1 mapping in node ACL iqn.2018-04.org.osradar.com.centos7.share
/iscsi/iqn.20...sk1/tpg1/luns>

before to save the configuration Please that all settings are there with “ls” command:

Please before to  exit Save The Configuration with command  saveconfig :

/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> exit

Check if The port listening :

[root@osradar.com ~]# ss -pant | grep 3260
LISTEN 0 256 *:3260 *:*

Or

[root@osradar.com ~]# netstat -plunt | grep 3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN - 

Firewall Configuration:

Please  allow  the service or Ip on firewallcmd

[root@osradar ~]# firewall-cmd --permanent --add-port=3260/tcp 
success
[root@osradar ~]# firewall-cmd --reload 
success

Now you are ready to share your ISCSI with other hosts using the ACL.

How to install and configure the  ISCSI Initiator 

LEAVE A REPLY

Please enter your comment!
Please enter your name here