Sunday 17 November 2019

How to Configure iSCSI Target with Two LUNs on CentOS 7 (Using HDD Partitions)



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 with Two LUNs on CentOS7

here, 8 GB additional disk added for iSCSI Target configuration.

[root@lc-storage1 ~]# fdisk -l
……………………………
Disk /dev/sdb: 8589 MB, 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. Create HDD Partitions: Create two partition from the 8 GB hard disk to configure iSCSI back store. You can add two separate hard disks for the same.

[root@lc-storage1 ~]# fdisk /dev/sdb
…………………….
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-16777215, default 16777215): +4G
Partition 1 of type Linux and of size 4 GiB is set

Command (m for help): n
Partition type:
   p   primary (1 primary, 0 extended, 3 free)
   e   extended
Select (default p): p
Partition number (2-4, default 2): 2
First sector (8390656-16777215, default 8390656):
Using default value 8390656
Last sector, +sectors or +size{K,M,G} (8390656-16777215, default 16777215):
Using default value 16777215
Partition 2 of type Linux and of size 4 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@lc-storage1 ~]#

Verify created partition using below command:

[root@lc-storage1 ~]# fdisk -l /dev/sdb

Disk /dev/sdb: 8589 MB, 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
Disk label type: dos
Disk identifier: 0x88154e17
  
   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048     8390655     4194304   83  Linux
/dev/sdb2         8390656    16777215     4193280   83  Linux
[root@lc-storage1 ~]#

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

[root@lc-storage1 ~]# yum install targetcli
Loaded plugins: fastestmirror
………………..
Installed:
  targetcli.noarch 0:2.1.fb46-7.el7

Dependency Installed:
  libnl.x86_64 0:1.1.4-3.el7          pyparsing.noarch 0:1.5.6-9.el7              python-configshell.noarch 1:1.1.fb23-5.el7      python-ethtool.x86_64 0:0.8-7.el7
  python-kmod.x86_64 0:0.9-4.el7      python-rtslib.noarch 0:2.1.fb63-13.el7      python-six.noarch 0:1.9.0-2.el7                 python-urwid.x86_64 0:1.1.1-3.el7

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 from /etc/systemd/system/multi-user.target.wants/target.service to /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
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. Create Target Back Stores: Now create storage backend using disk partitions /dev/sdb1 and sdb2 as a block-type backing stores for storage object:

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

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

/backstores> cd /iscsi
/iscsi> create iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1
Created target iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-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>

Step 4: Creating LUNs: add the LUNs or logical units to make the storage effective. The LUN should use the previously mentioned backing storage object named iscsi-disk1 and iscsi-disk2

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

Step 5: Creating 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...sk1/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 2.
/iscsi/iqn.20...sk1/tpg1/acls> create iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node2
Created Node ACL for iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node2
Created mapped LUN 2.
/iscsi/iqn.20...sk1/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: 2]
  | | o- iscsi-disk1 .................................... [/dev/sdb1 (4.0GiB) write-thru activated]
  | | | o- alua ............................................................................. [ALUA Groups: 1]
  | | |   o- default_tg_pt_gp .................................. [ALUA state: Active/optimized]
  | | o- iscsi-disk2 .................................... [/dev/sdb2 (4.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 ............................. [TPGs: 1]
  |   o- tpg1 ........................................................................... [no-gen-acls, no-auth]
  |     o- acls .............................................................................................. [ACLs: 2]
  |     | o- iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node1 …………………………………………………………………….. [Mapped LUNs: 2]
  |     | | o- mapped_lun0 ............................................ [lun0 block/iscsi-disk1 (rw)]
  |     | | o- mapped_lun1 ............................................ [lun1 block/iscsi-disk2 (rw)]
  |     | o- iqn.2019-11.local.linuxcnf.lc-storage1:iscsi-disk1:lc-node2 ................................................................................................. [Mapped LUNs: 2]
  |     |   o- mapped_lun0 ............................................. [lun0 block/iscsi-disk1 (rw)]
  |     |   o- mapped_lun1 ............................................. [lun1 block/iscsi-disk2 (rw)]
  |     o- luns ........................................................................................... [LUNs: 2]
  |     | o- lun0 ............................ [block/iscsi-disk1 (/dev/sdb1) (default_tg_pt_gp)]
  |     | o- lun1 ............................ [block/iscsi-disk2 (/dev/sdb2) (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
Last 10 configs saved in /etc/target/backup/.
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 ~]#

Done!!! iSCSI Target Server end using two LUNs configuration has been done. Follow article How to configure iSCSI Target and Initiator on CentOS 7 for iSCI initiator configuration.

No comments:

Post a Comment