Saturday 16 November 2019

How to Configure iSCSI Target and Initiator on CentOS 8



iSCSI (Internet Small Computer Systems Interface) is an Internet Protocol based storage networking for connecting remote storage devices over the network. It provides block-level access to storage devices. iSCSI is used to facilitate block-level data transfer between iSCSI initiator on a client machine and target on a storage server over local area networks (LANs), wide area networks (WANs).
This article describes, How to configure iSCSI Target and Initiator on CentOS8 using 8 GB additional disk added to the server.

ISCSI Target Configuration:

[root@lc-storage1 ~]# fdisk –l
………………..
Disk /dev/sdb: 8 GiB, 8589934592 bytes, 16777216 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
………………..
[root@lc-storage1 ~]#

Step 1. Installing Packages: Run the following command to install iSCSI target binary and targetcli commands:

[root@lc-storage1 ~]# dnf install targetcli –y
……………………
Installed:
  targetcli-2.1.fb49-1.el8.noarch        python3-configshell-1:1.1.fb25-1.el8.noarch   python3-kmod-0.9-20.el8.x86_64         python3-pyparsing-2.1.10-7.el8.noarch
  python3-rtslib-2.1.fb69-3.el8.noarch   python3-urwid-1.3.1-4.el8.x86_64              target-restore-2.1.fb69-3.el8.noarch

Complete!
[root@lc-storage1 ~]#

Once the targetcli package installed, start the iSCSI target service and enable it on system start up:

[root@lc-storage1 ~]# systemctl enable target; systemctl restart target
Created symlink /etc/systemd/system/multi-user.target.wants/target.service /usr/lib/systemd/system/target.service.
[root@lc-storage1 ~]#

Once service is started, enter below command to get iSCSI CLI interactive prompt:

[root@lc-storage1 ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/>

Using ls command check the existing iSCSI configuration:

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]
/>

Step 2. Configure iSCSI Target: Now create storage backend using disk /dev/sdb as a block-type backing store for storage object:

/> cd backstores/block
/backstores/block> create name=iscsi-disk1 dev=/dev/sdb
Created block storage object iscsi-disk1 using /dev/sdb.
/backstores/block>

Step 3. Create iSCSI Target: Run the following commands to create an iSCSI target, here we are creating a default IQN:

/backstores/block> cd /iscsi
/iscsi> create iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1
Created target iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi>


Step 4: Create iSCSI LUNs: add the LUNS or logical units to make the storage effective. The LUN should use the previously mentioned backing storage object named scsi-disk1.

/iscsi> cd iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1/tpg1/luns
/iscsi/iqn.20...de1/tpg1/luns> create /backstores/block/iscsi-disk1
Created LUN 0.
/iscsi/iqn.20...de1/tpg1/luns>

Step 5: Create ACL: ACL restrict access to LUNs from unauthorized remote systems and exit from the iSCSI interactive session:

/iscsi/iqn.20...sk1/tpg1/luns> cd ../acls
/iscsi/iqn.20...de1/tpg1/acls> create iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1
Created Node ACL for iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1
Created mapped LUN 0.
/iscsi/iqn.20...de1/tpg1/acls>

Run the following command to get the list of created configuration:

/iscsi/iqn.20...sk1/tpg1/acls> cd /
/> ls
o- / ................................................................................................................. [...]
  o- backstores ................................................................................................ [...]
  | o- block ............................................................................ [Storage Objects: 1]
  | | o- iscsi-disk1 ................................... [/dev/sdb (8.0GiB) 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.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1 ............ [TPGs: 1]
  |   o- tpg1 ......................................................................... [no-gen-acls, no-auth]
  |     o- acls ............................................................................................ [ACLs: 1]
  |     | o- iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1 ……..[Mapped LUNs: 1]
  |     |   o- mapped_lun0 .............................................[lun0 block/iscsi-disk1 (rw)]
  |     o- luns .......................................................................................... [LUNs: 1]
  |     | o- lun0 ............................. [block/iscsi-disk1 (/dev/sdb) (default_tg_pt_gp)]
  |     o- portals .................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 .................................................................................... [OK]
  o- loopback ....................................................................................... [Targets: 0]
/>

Run the exit command to exit with saving configuration from the targetcli interactive session:

/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
[root@lc-storage1 ~]#

Step 6. Firewall Configuration: Run the following commands configure firewall to allow port 3260 accessible from remote systems:

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

If iptables are running instead of firewalld, run the following commands:

[root@lc-storage1 ~]# iptables -I INPUT -p tcp -m tcp -dport 3260 - ACCEPT; systemctl save iptables


iSCSI Initiator Configuration:

Step 1. Packages Installation: Install the iscsi-initiator-utils package to configure iSCSI initiator on Linux systems:

[root@lc-node1 ~]# dnf install iscsi-initiator-utils –y
……………………
Installed:
  iscsi-initiator-utils-6.2.0.876-7.gitf3c8e90.el8.x86_64     iscsi-initiator-utils-iscsiuio-6.2.0.876-7.gitf3c8e90.el8.x86_64     isns-utils-libs-0.97-6.el8.x86_64

Complete!
[root@lc-node1 ~]#

Step 2. iSCSI Initiatorname Configuration: Edit the /etc/iscsi/initiatorname.iscsi file and replace the Initiatorname with the earlier created in ACL on target server and comment all other initiator names if any present in this and not in use anymore:

[root@lc-node1 ~]# vi /etc/iscsi/initiatorname.iscsi
#InitiatorName=iqn.1994-05.com.redhat:5cc8abcc5ada
InitiatorName=iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1

Step 3. Restart iSCSI services: Run the following commands to enable on system start up and restart the service to reflect the change:

[root@lc-node1 ~]# systemctl enable iscsid; systemctl restart iscsid
Created symlink /etc/systemd/system/multi-user.target.wants/iscsid.service /usr/lib/systemd/system/iscsid.service.
[root@lc-node1 ~]#


Step 4. iSCSI Discovery: Discover the target using the below command:

[root@lc-node1 ~]# iscsiadm --mode discovery --type sendtargets --portal 192.168.43.45 --discover
192.168.43.45:3260,1 iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1
[root@lc-node1 ~]#

Step 5. Create iSCSI Initiator Session: Run the following command for making connection:

[root@lc-node1 ~]# iscsiadm --mode node --targetname iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1 --login
Logging in to [iface: default, target: iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1, portal: 192.168.43.45,3260] (multiple)
Login to [iface: default, target: iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1, portal: 192.168.43.45,3260] successful.
[root@lc-node1 ~]#

Step 6. Verification: Once the session created successfully verify the LUNs using below commands:

[root@lc-node1 ~]# lsscsi
[1:0:0:0]    cd/dvd  VBOX     CD-ROM           1.0   /dev/sr0
[2:0:0:0]    disk    ATA      VBOX HARDDISK    1.0   /dev/sda
[3:0:0:0]    disk    LIO-ORG  iscsi-disk1      4.0   /dev/sdb
[root@lc-node1 ~]#

Here the iSCSI target mapped to the disk /dev/sdb. Use the following command to monitor the iSCSI session:

[root@lc-node1 ~]# iscsiadm --mode node -P 1
Target: iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1
        Portal: 192.168.43.45:3260,1
                Iface Name: default
[root@lc-node1 ~]#

Done!!! Now session is created and iSCSI target mapped to the disk /dev/sdb in iSCSI initiator system.

1 comment:

  1. Thank you very much, what a nice and straight forward writeup.

    ReplyDelete