Configure ISCSI targets/Clients on CentOS7/RHEL7
ISCSI targets are used to share disk on network to ISCSI Clients. This is IP based storage, work with internet protocol. In this post we will see HowTo configure ISCSI targets/Clients on CentOS7/RHEL7.
SetUP
For this setup, we use CentOS7.4 machine, latest as of now.
####ISCSI target Server # cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) # uname -r 3.10.0-693.2.2.el7.x86_64 # hostname srv7-1 ####ISCSI Client Machine # cat /etc/redhat-release CentOS Linux release 7.4.1708 (Core) # uname -r 3.10.0-693.2.2.el7.x86_64 # hostname mysql-pri
Now we would see how to set ISCSI target on Server to connect on ISCSI Client machine.For this i am using KVM Guest machine with Sparse files as loop block devices, for same we already have on post, which describe HowTo Manage loop device on CentOS7.
Block device used in Post
We are considering that we already loop block device to share with ISCSI target Server.
# losetup -a /dev/loop0: [64769]:67251540 (/data/Disk_1) /dev/loop1: [64769]:67731536 (/data/Disk_2)
Installation
Now we need to Install “targetcli” package for work on ISCSI target server
yum install targetcli -y
Let’s work on ISCSI target Server with targetcli command-line tool.
This is default blank targetcli, which we could see in fresh target ISCSI machine. We can see there is no block device,ISCSI and acl mentioned in command-line.
ot@srv7-1 ~]# targetcli targetcli shell version 2.1.fb46 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> 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]
Creation of Block Device
First we have to create block device like below, These block could be accessible to ISCSI targets and can map to their luns, which we would see later in post.
/> cd backstores/block /backstores/block> create MySQL_Disk1 /dev/loop0 [ 426.021152] Rounding down aligned max_sectors from 255 to 248 Created block storage object MySQL_Disk1 using /dev/loop0. /backstores/block> create MySQL_Disk2 /dev/loop1 [ 431.588520] Rounding down aligned max_sectors from 255 to 248 Created block storage object MySQL_Disk2 using /dev/loop1.
Now we can see in above output creation of two block device in targetcli, these are same loop devices which we were mentioned above. Now picture of /backstore/block is like below.
/backstores/block> ls o- block ........................................................ [Storage Objects: 2] o- MySQL_Disk1 ......................... [/dev/loop0 (10.0GiB) write-thru activated] | o- alua ......................................................... [ALUA Groups: 1] | o- default_tg_pt_gp ............................. [ALUA state: Active/optimized] o- MySQL_Disk2 ......................... [/dev/loop1 (10.0GiB) write-thru activated] o- alua ......................................................... [ALUA Groups: 1] o- default_tg_pt_gp ............................. [ALUA state: Active/optimized]
Creation of ISCSI target
Now we have to create iscsi target and need to map blocks to their luns. Let’s see further process below
/backstores/block> cd /iscsi /iscsi> ls o- iscsi ................................................................... [Targets: 0] /iscsi> create iqn.2017-09.Remote.MySQL:Disks Created target iqn.2017-09.Remote.MySQL:Disks. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260.
Now we need to map those block device that we have created earlier to this iscsi target’s luns column like below.
/iscsi> cd iqn.2017-09.Remote.MySQL:Disks/tpg1/luns /iscsi/iqn.20...sks/tpg1/luns> create /backstores/block/MySQL_Disk1 Created LUN 0. /iscsi/iqn.20...sks/tpg1/luns> create /backstores/block/MySQL_Disk2 Created LUN 1. /iscsi/iqn.20...sks/tpg1/luns> ls o- luns ................................ [LUNs: 2] o- lun0 .............................. [block/MySQL_Disk1 (/dev/loop0) (default_tg_pt_gp)] o- lun1 .............................. [block/MySQL_Disk2 (/dev/loop1) (default_tg_pt_gp)]
Set Authentication for ISCSI targets
Now we should setup Authentication on this ISCSI target.
####ACL is blank /> cd iscsi/iqn.2017-09.Remote.MySQL:Disks/tpg1/acls /iscsi/iqn.20...sks/tpg1/acls> ls o- acls ........................................................................................... [ACLs: 0] ####Create ISCSI target for ACL(same we create earlier) /iscsi/iqn.20...sks/tpg1/acls> create iqn.2017-09.Remote.MySQL:Disks Created Node ACL for iqn.2017-09.Remote.MySQL:Disks Created mapped LUN 1. Created mapped LUN 0. ####Now it has ISCSI target, need to create authentication for same /iscsi/iqn.20...sks/tpg1/acls> ls o- acls ....................................................................... [ACLs: 1] o- iqn.2017-09.Remote.MySQL:Disks ........................................... [Mapped LUNs: 2] o- mapped_lun0 ............................................................ [lun0 block/MySQL_Disk1 (rw)] o- mapped_lun1 ............................................................ [lun1 block/MySQL_Disk2 (rw)] ####SetUp authentication, Enter mapped ISCSI target /iscsi/iqn.20...sks/tpg1/acls> cd iqn.2017-09.Remote.MySQL:Disks/ /iscsi/iqn.20...e.MySQL:Disks> set auth userid=MySQL_Servers Parameter userid is now 'MySQL_Servers'. /iscsi/iqn.20...e.MySQL:Disks> set auth password=Passw0rd Parameter password is now 'Passw0rd'. /iscsi/iqn.20...e.MySQL:Disks> ls o- iqn.2017-09.Remote.MySQL:Disks ............................................. [Mapped LUNs: 2] o- mapped_lun0 .............................................................. [lun0 block/MySQL_Disk1 (rw)] o- mapped_lun1 .............................................................. [lun1 block/MySQL_Disk2 (rw)]
We should save our configuration with “saveconfig” command.
/> saveconfig Last 10 configs saved in /etc/target/backup. 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
Configure Clients
Now we need to connect Client with this iSCSI Server.
Installation of packages
First we need to install packages for ISCSI Client binaries.
yum install iscsi-initiator-utils -y
Discover available targets
Now we should discover the target with below command.
# iscsiadm -m discovery -t st -p 192.168.122.4 [12596.699871] Loading iSCSI transport class v2.0-870. [12596.724181] iscsi: registered transport (tcp) 192.168.122.4:3260,1 iqn.2017-09.Remote.MySQL:Disks
In above command we used target Server IP Address to discover Targets.
Now we should mentioned required target in “/etc/iscsi/initiatorname.iscsi” like below.
# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2017-09.Remote.MySQL:Disks
Now we need to configure /etc/iscsi/iscsid.conf in “CHAP Settings” section like below.
# egrep "authmethod|username|password" /etc/iscsi/iscsid.conf| grep -v ^# node.session.auth.authmethod = CHAP node.session.auth.username = MySQL_Servers node.session.auth.password = Passw0rd
Now restart iscsid service and put it on enable mode.
systemctl restart iscsid.service systemctl enable iscsid.service
Connect ISCSI targets
Now try to connect ISCSI target.
Before this i suggest to check your disk like below.
# sfdisk -s /dev/vda: 20971520 /dev/mapper/centos-swap: 2097152 /dev/mapper/centos-root: 18358272 total: 41426944 blocks
Let’s try t connect ISCSI target with below command.
# iscsiadm -m node -T iqn.2017-09.Remote.MySQL:Disks -p 192.168.122.4 -l Logging in to [iface: default, target: iqn.2017-09.Remote.MySQL:Disks, portal: 192.168.122.4,3260] (multiple) [13700.054450] scsi host5: iSCSI Initiator over TCP/IP [13700.060495] scsi 5:0:0:0: Direct-Access LIO-ORG MySQL_Disk1 4.0 PQ: 0 ANSI: 5 [13700.062538] scsi 5:0:0:0: alua: supports implicit and explicit TPGS [13700.064312] scsi 5:0:0:0: alua: port group 00 rel port 01 [13700.065503] scsi 5:0:0:0: alua: port group 00 state A non-preferred supports TOlUSNA [13700.066229] scsi 5:0:0:0: alua: Attached [13700.067549] scsi 5:0:0:0: Attached scsi generic sg1 type 0 [13700.068799] scsi 5:0:0:1: Direct-Access LIO-ORG MySQL_Disk2 4.0 PQ: 0 ANSI: 5 [13700.070845] scsi 5:0:0:1: alua: supports implicit and explicit TPGS [13700.073621] scsi 5:0:0:1: alua: port group 00 rel port 01 [13700.074907] scsi 5:0:0:1: alua: port group 00 state A non-preferred supports TOlUSNA [13700.075934] scsi 5:0:0:1: alua: Attached [13700.079433] scsi 5:0:0:1: Attached scsi generic sg2 type 0 Login to [iface: default, target: iqn.2017-09.Remote.MySQL:Disks, portal: 192.168.122.4,3260] successful.
Now check you disk once more. you will find ISCSI DISK connected on machine.
# sfdisk -s /dev/vda: 20971520 /dev/mapper/centos-swap: 2097152 /dev/mapper/centos-root: 18358272 /dev/sdb: 10485760 /dev/sda: 10485760 total: 62398464 blocks
Above Picture is from ISCSI target Server targetcli command-line tools configuration.
Leave a Reply