• Home
  • RHCE Providing Remote Block Storage Using iSCSI

RHCE Providing Remote Block Storage Using iSCSI

iSCSI Concept

Video Tutorial Part 1

Part 2

Part 3

What is iSCSI

iSCSI is refer to Internet Small Computer System interface.This is used to Transfer data actually SCSI high performance local storage bus over the TCP/IP protocol. At the beginning this used as testing environments but now advancement of software,hardware and networking iSCSI concept is used in  production environments too.

SCSI cables only can transfer reliable data within 20m only.But using fiber optic cables and expensive switches.it can be done but its more expensive.But when you use iSCSI concept you can transfer storage data using Ethernet.

iSCSI concept mostly used in NAS(Network attached  Storage) and SAN(Storage Area Networks)

There are two main component

  1. iSCSI Target(server side)
  2. iSCSI Initiator(Client Side)

And there is few terminology you need to understand

iSCSI Terminology

  • Initiator-is the client side this can be hardware device or a software.Initiator should have unique name.
  • Target-is the Storage device.Target also have unique name.Target can provide one or more block devices.This is called LUN
  • ACL-is the Access Control List.Provide permission to initiator
  • Discovery-Can query all the configured targets
  • IQN-is the iSCSI Qualified Name.this will identify the target and the initiator.IQN has pattern
iqn.year-month.com.example
this use reverse domain if the domain is example.com reverse domain is com.example

 

  • LUN-Logical Unit Number block devices attached and available via target
  • Node-iSCSI target or a iSCSI initiator can identified by its own IQN
  • Portal- IP and the Port number of target or a initiator
  • TGP-Target Portal Group specific IP and The Port listen by the iSCSI target

Create iSCSI Target Using targetcli

Today Lesson we are going to create separate partition inside the Server and Mount it inside the Desktop using iSCSI concept.

First we create separate partition 1G inside the server

fdisk /dev/vdb

fdisk /dev/vdb
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 0x519596cb.

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

Then

partprobe to sysnc newly created partition with kernel

Now create volume group called my_iSCSI

[root@server0 ~]# pvcreate /dev/vdb1
  Physical volume "/dev/vdb1" successfully created
[root@server0 ~]# vgcreate my_iSCSI /dev/vdb1
  Volume group "my_iSCSI" successfully created
[root@server0 ~]# vgdisplay my_iSCSI 
  --- Volume group ---
  VG Name               my_iSCSI
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  1
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                0
  Open LV               0
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               1020.00 MiB
  PE Size               4.00 MiB
  Total PE              255
  Alloc PE / Size       0 / 0   
  Free  PE / Size       255 / 1020.00 MiB
  VG UUID               uG3VnL-8xkq-1CaA-VBWu-0x6T-PK2q-ElAa7h

now Create 100mb logical volume called my_logical_volume_disk1 inside the my_iSCSI volume group

[root@server0 ~]# lvcreate -n my_logical_volume_disk1 -L 100m my_iSCSI
  Logical volume "my_logical_volume_disk1" created

lets check newly created 100mb logical volume my_logical_volume

[root@server0 ~]# lvdisplay my_iSCSI/my_logical_volume_disk1
  --- Logical volume ---
  LV Path                /dev/my_iSCSI/my_logical_volume_disk1
  LV Name                my_logical_volume_disk1
  VG Name                my_iSCSI
  LV UUID                wRdHem-GW44-D05N-7TSW-s247-petJ-ZtC50U
  LV Write Access        read/write
  LV Creation host, time server0.example.com, 2018-02-20 00:28:02 +0000
  LV Status              available
  # open                 0
  LV Size                100.00 MiB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           252:0

see LV Size 100.00 MiB

lets make this 100mb logical volume as target .Then remote desktop can access the target.

first install and enable targetcli then start target

yum install targetcli -y

systemctl enable target

systemctl start target

Then open targetcli

type targetcli in terminal

targetcli looks like this lets make our logical volume as target.so it can be used by the target initiator

/> /backstores/block create server0.disk1 /dev/my_iSCSI/my_logical_volume_disk1 
Created block storage object server0.disk1 using /dev/my_iSCSI/my_logical_volume_disk1.

server0.disk1 is the name for backstore

Then Create unique IQN (iSCSI Qualified Name) for the target

/> /iscsi create iqn.2018-02.com.example:server0
Created target iqn.2018-02.com.example:server0.
Created TPG 1.

This will create TGP(Target Portal Group ) automatically named as tgp1

Now Create ACL for target initiator.so client can connect via initiator name

/> /iscsi/iqn.2018-02.com.example:server0/tpg1/acls create iqn.2018-02.com.example:desktop0
Created Node ACL for iqn.2018-02.com.example:desktop0

 

Then create LUN for previously created backstore

/> /iscsi/iqn.2018-02.com.example:server0/tpg1/luns create /backstores/block/server0.disk1 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2018-02.com.example:desktop0

Make portal listen on port 3260 in target.so any request received to target on port 3260 will directed to iSCSI

/> /iscsi/iqn.2018-02.com.example:server0/tpg1/portals create 172.25.0.11
Using default IP port 3260
Created network portal 172.25.0.11:3260.

Then verify the configuration using ls

Final stem type exit to save and exit the targetcli

/> exit

 

All the configuration is saved as a jsonfile

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

Now 100mb logical volume is configured as a target.This target can access via remote machine using target initiator.

lets access this target from another machine.Now im using Desktop

Accessing iSCSI Storage

Previous step we created the target in server0. Now i’m inside desktop0 and create target initiator inside the desktop and access the server0 target via Desktop.Lets get started.

First install iscsi-initiator-utils

yum install iscsi-initiator-utils -y

 

Edit /etc/iscsi/initiatorname.iscsi

nano /etc/iscsi/initiatorname.iscsi

#remove content and give new initiator name in previous lesson
#iqn.2018-02.com.example:desktop0

InitiatorName=iqn.2018-02.com.example:desktop0  

Enable iSCSI and start iSCSI

systemctl enable iscsi

systemctl start iscsi

 

Discover iSCSI target

iscsiadm -m discovery -t st -p 172.25.0.11

but error will occur.

iscsiadm: cannot make connection to 172.25.0.11: No route to host

Fixed iscsiadm: cannot make connection to IP: No route to host Solved

Lets add port 3260 to firewall in server0

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

Then reload the firewall-cmd

firewall-cmd --reload 
success

Check ports that allowed through firewall

 firewall-cmd --list-ports 
3260/tcp

Lets rerun the discovery command to get the node of the target .so lets back to desktop0

[root@desktop0 ~]# iscsiadm -m discovery -t st -p 172.25.0.11
172.25.0.11:3260,1 iqn.2018-02.com.example:server0

Same thing can be done like this also

[root@desktop0 ~]# iscsiadm --mode discovery --type sendtargets --portal 172.25.0.11
172.25.0.11:3260,1 iqn.2018-02.com.example:server0

 

Log in to iSCSI Target

iscsiadm -m node -T iqn.2018-02.com.example:server0 -p 172.25.0.11 -l

Same thing can by this command also

iscsiadm --mode node --targetname iqn.2018-02.com.example:server0 --portal 172.25.0.11 --login

Lets check any scsi device that have attached to the system

[root@desktop0 ~]# lsblk --scsi
NAME HCTL       TYPE VENDOR   MODEL             REV TRAN
sda  2:0:0:0    disk LIO-ORG  server0.disk1    4.0  iscsi

Check disk for read only mode

[root@desktop0 ~]# lsblk | egrep "NAME|sda"
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0  100M  0 disk 

RO equals to 0 that means this is read write mode.

Now we are good to go.Now create file system just like normal device.Our iSCSI device is sda so /dev/sda

mkfs.ext4 /dev/sda 
mke2fs 1.42.9 (28-Dec-2013)
/dev/sda is entire device, not just one partition!
Proceed anyway? (y,n) y

this will format entire  device as ext4 file system.

For mount this newly created device we need UUID so get UUID

blkid | grep "/dev/sda"
/dev/sda: UUID="5bea3bc8-14b8-4cf9-96f7-fb6d0e8b2b5c" TYPE="ext4"

Add this UUID to the /etc/fstab so it will auto mount when system restart

inside /etc/fstab

#Mounting iSCSI Remote File system
UUID=5bea3bc8-14b8-4cf9-96f7-fb6d0e8b2b5c /mnt/iscsi ext4 _netdev 0 0

in this case remember normally we use default but here its _netdev that means it wait for the network to mount the devices.

now create new directory called /mnt/iscsi

mkdir -p /mnt/iscsi

 

Mount devices

mount -a

See file system is mounted via iSCSI

 df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        10G  3.0G  7.0G  31% /
devtmpfs        906M     0  906M   0% /dev
tmpfs           921M   80K  921M   1% /dev/shm
tmpfs           921M   17M  904M   2% /run
tmpfs           921M     0  921M   0% /sys/fs/cgroup
/dev/sda         93M  1.6M   85M   2% /mnt/iscsi

create new text file inside /mnt/iscsi/first.txt

echo "This is my first file on iSCSI device" >> /mnt/iscsi/first.txt

 

Check session details of iscsi administrator

iscsiadm --mode session -P 3

This will give the all the information about the iSCSI session.

iSCSI node keep the record of the session.this located inside /var/lib/iscsi/nodes

cd /var/lib/iscsi/
ls
iqn.2018-02.com.example:server0

Logout From iSCSI Target

[root@desktop0 nodes]# iscsiadm --mode node --targetname iqn.2018-02.com.example\:server0 --portal 172.25.0.11 -u
Logging out of session [sid: 1, target: iqn.2018-02.com.example:server0, portal: 172.25.0.11,3260]
Logout of [sid: 1, target: iqn.2018-02.com.example:server0, portal: 172.25.0.11,3260] successful.

we use -l or –login for login to the node -u or –logout

But /var/lib/iscsi/nodes still keep the record for the session.so delete node record

Delete node record in iSCSI

iscsiadm --mode node --targetname iqn.2018-02.com.example\:server0 --portal 172.25.0.11 -o delete

 

This will stop the session and delete the record.after this step session record file is delete.

Rebooting the iscsi System

First umount the file system

umount /mnt/iscsi

Stop iSCSI Initiator

systemctl stop iscsi

 

This will release the all the file system locks otherwise system will stuck because of locked file system.

Reboot the desktop0.This should auto mount the iSCSI target because its in /etc/fstab

I hope you will get something from this tutorial.if you like this tutorial please share on facebook,twitter,google plus.

If you have any question please leave comment below.

See you in next tutorial.

Sameera Dissanayaka

 

 

 

 

 

Keyword For Search

redhat iscsi initiator
redhat iscsi multipath
redhat iscsi target server
redhat iscsi setup
redhat iscsi rescan
redhat iscsi config
redhat iscsi boot
redhat iscsi timeout
redhat iscsi target
redhat add iscsi disk
redhat iscsi bonding
redhat iscsi configuration
redhat iscsi client
redhat iscsi commands
redhat iscsi chap
redhat iscsi ceph
redhat ceph iscsi gateway
redhat configure iscsi target
redhat 7 iscsi configuration
redhat delete iscsi target
redhat discover iscsi
redhat list iscsi devices
iscsi discovery redhat
redhat scan iscsi disk
redhat iscsi fstab
redhat boot from iscsi
redhat iscsi gui
redhat iscsi howto
redhat iscsi initiator howto
rhel5 iscsi how to
red hat linux iscsi howto
redhat iscsi iface
redhat install iscsi
redhat install iscsi target
rhel5 iscsi initiator
redhat list iscsi targets
red hat linux iscsi
redhat remove iscsi lun
redhat add iscsi lun
red hat login iscsi
redhat iscsi mount
redhat 7 iscsi multipath
redhat mount iscsi volume
redhat 6 iscsi multipath
redhat iscsi initiator name
redhat openstack iscsi
iscsi on redhat
iscsi on redhat 7
redhat iscsi package
redhat remove iscsi target
redhat restart iscsi
redhat iscsi server
redhat iscsi service
redhat show iscsi
redhat iscsi initiator setup
redhat 7 iscsi server
redhat ceph storage iscsi
redhat iscsi troubleshooting
rhel5 iscsi target
redhat 7 iscsi target
redhat 6 iscsi target
red hat update iscsi
rhel 4 iscsi
iscsi redhat 5
redhat 5 iscsi
rhel5 iscsi
rhel 5 iscsi target
iscsi redhat 6
install iscsi redhat 6
iscsi redhat 7
redhat 7.4 iscsi
redhat 7.3 iscsi
redhat 7.2 iscsi
redhat 7 iscsi
rhel 7 iscsi multipath
rhel 7 iscsi target setup
rhel 7 iscsi boot
rhel 7 iscsi client

6 Comments

Leave A Comment