Configure iSCSI Target on Centos 7 & Initiator on Windows Server 2016

Configure iSCSI Target on Centos 7 & Initiator on Windows Server 2016

in this post i configure iSCSI target on CentOS 7 and iSCSI initiator on Windows Server 2016, both are VMs on VMware vSphere 6.7 in my demolab, config:

Environment

iSCSI target

  • Centos 7 minimal
  • 2 vCPU
  • 2 GB RAM
  • 20 GB HDD0 – OS
  • 500 GB HDD1 – DATA (used for iSCSI target)
  • 2 NIC
    • 1 x VMXNET3 – mng – ens192 – 192.168.168.111
    • 1 x VMXNET3 – iSCSI network – ens224 – 192.168.168.130

iSCSI client

  • Windows Server 2016
  • 4 vCPU
  • 8 GB RAM
  • 60 GB HHD0 – OS
  • 2 NIC
    • 1 x VMXNET3 – mng – 192.168.168.112
    • 1 x VMXNET3 – iSCSI network – 192.168.168.131

Configure storage 

[root@iscsi01 ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x000d377e

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200    41943039    19921920   8e  Linux LVM

Disk /dev/sdb: 536.9 GB, 536870912000 bytes, 1048576000 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 /dev/mapper/centos-root: 18.2 GB, 18249416704 bytes, 35643392 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 /dev/mapper/centos-swap: 2147 MB, 2147483648 bytes, 4194304 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

you can see that my system has a 500 GB disk (/dev/sdb), i will create a 480 GB partition with LVM

[root@iscsi01 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xf886711c.

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-1048575999, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1048575999, default 1048575999): +450G
Partition 1 of type Linux and of size 450 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

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

Calling ioctl() to re-read partition table.
Syncing disks.

use fdisk for create a new partition

  • n – new partititon
  • p – primary
  • 1 – partition number
  • +450G – create 450 GB partition
  • t – select partition
  • 8e – change it as LVM label
  • w – save
[root@iscsi01 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@iscsi01 ~]# vgcreate vg_iscsi /dev/sdb1
  Volume group "vg_iscsi" successfully created
[root@iscsi01 ~]# lvcreate -l 100%FREE -n lv_iscsi vg_iscsi
  Logical volume "lv_iscsi" created.

create a LVM – in my case /dev/sdb1

Configure iSCSI target

[root@iscsi01 ~]# yum -y install targetcli

first of all install targetcli package

[root@iscsi01 ~]# 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'.
/> cd backstores/block
/backstores/block> create iscsi_disk1 /dev/vg_iscsi/lv_iscsi
Created block storage object iscsi_disk1 using /dev/vg_iscsi/lv_iscsi.

i use my existing logical volume /dev/vg_iscsi/lv_iscsi for storage object iscsi_disk1 as a block-type backing store

Created target iqn.2018-06.target01.centos: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> ls
o- iscsi .................................................................. [Targets: 1]
  o- iqn.2018-06.target01.centos:disk1 ....................................... [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 a target, in default config the target listening on all IPs… 0.0.0.0:3260, but i have separated network 192.168.130.x.

/iscsi> cd iqn.2018-06.target01.centos:disk1/tpg1/portals/
/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 192.168.130.130
Using default IP port 3260
Created network portal 192.168.130.130:3260.

delete 0.0.0.0 3260 target and create 192.168.130.130 target

/iscsi/iqn.20.../tpg1/portals> cd ..
/iscsi/iqn.20...os:disk1/tpg1> cd acls
/iscsi/iqn.20...sk1/tpg1/acls> create iqn.1991-05.com.microsoft:vm-udp
Created Node ACL for iqn.1991-05.com.microsoft:vm-udp

create ACL for my client machine (WS2016) with IQN: „iqn.1991-05.com.microsoft:vm-udp

/iscsi/iqn.20...sk1/tpg1/acls> cd ..
/iscsi/iqn.20...os:disk1/tpg1> luns/
/iscsi/iqn.20...sk1/tpg1/luns> create /backstores/block/iscsi_disk1
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.1991-05.com.microsoft:vm-udp

create a LUN under target and map it on my client

/iscsi> cd ..
/> ls
o- / ............................................................................. [...]
  o- backstores .................................................................. [...]
  | o- block ...................................................... [Storage Objects: 1]
  | | o- iscsi_disk1 .......... [/dev/vg_iscsi/lv_iscsi (480.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.2018-06.target01.centos:disk1 ..................................... [TPGs: 1]
  |   o- tpg1 ................................................... [no-gen-acls, no-auth]
  |     o- acls .............................................................. [ACLs: 1]
  |     | o- iqn.1991-05.com.microsoft:vm-udp ......................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ............................... [lun0 block/iscsi_disk1 (rw)]
  |     o- luns .............................................................. [LUNs: 1]
  |     | o- lun0 ...... [block/iscsi_disk1 (/dev/vg_iscsi/lv_iscsi) (default_tg_pt_gp)]
  |     o- portals ........................................................ [Portals: 1]
  |       o- 192.168.130.130:3260 ................................................. [OK]
  o- loopback ............................................................. [Targets: 0]

verify the target server configuration

/> saveconfig
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json

save config and exit targetcli console

[root@iscsi01 ~]# systemctl enable target.service
[root@iscsi01 ~]# systemctl restart target.service

enable & restart target.service

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

config firewall for iSCSI traffic

Configure iSCSI client (WS2016)

on WS2016 run iSCSI configuration and as target use ip of iSCSI target – 192.168.168.130 and click to quick connect.

Sucessfully connected.

Napsat komentář

Vaše emailová adresa nebude zveřejněna. Vyžadované informace jsou označeny *