Skip to main content

How to configure ISCSI target and initiator?



What is ISCSI?
ISCSI is a shared storage service, by using ISCSI service we can share storage space which we can use as internal storage in different machines.

Requirements-

2 CentOS machines
Free storage space (as per your requirements)

Let’s start with configuration-

Configuration (Server-Side)-

First, we need to install the targetcli package,
# yum install targetcli -y

Now start and enable the service.
# systemctl start/enable target.service

Create partition of free space that you want to share as ISCSI storage.
# fdisk /dev/sdb
Follow the instructions and create a partition according to your requirements.
I’ve created a partition of 6GB size.

No need to format this partition but you can create LVM partition if you want.
Now run following command-
# targetcli

> cd /backstores/block
> create data_block /dev/sdb1
> cd /iscsi
> create iqn.2020-03.com.example:server1
> cd iqn.2020-03.com.example:server1/tpg1/acls
> create iqn.2020-03.com.example:desktop1
> cd ../luns
> create /backstores/block/data_block
> cd ../portals
> create 172.16.0.187 3260
> cd /
> saveconfig
> exit
Restart the service in Server(Target) machine
# systemctl restart target.service

Add the port in firewall-
# firewall-cmd --permanent --add-port=3260/tcp
# firewall-cmd --reload

Configuration (Client-side)-
First install initiator-utils package.
# yum install iscsi-initiator-utils -y

Now add iqn name in initiatorname file.
# vim /etc/iscsi/initiatorname.iscsi
Iqn.2020-02.com.example:desktop1
Save and exit from that file.

Now discover for target’s iqn name by using the following command-
# iscsiadm --mode discoverydb --type sendtargets --portal 172.16.0.187

Now you got the iqn name of the target machine after that run the following command to login that iscsi device in your initiator machine.
# iscsiadm --mode node --targetname iqn.2020-02.com.example:server1 --portal 172.16.0.187:3260 --login

Now you will get a device listed in your drive list like “/dev/sdb” or “/dev/sdc” according to your drive lists.
After getting that drive run fdisk command to create a partition in it and then format that partition and mount it.

# fdisk /dev/sdb

# mkfs.ext4 /deb/sdb1

To mount I’m gonna edit fstab file-
# vim /etc/fstab
/dev/sdb1    /media        ext4        _netdev,defaults    0    0

Save and exit.

To logout from iscsi drive, we need to first remove that fstab line and then run following line-
# iscsiadm --mode node --targetname iqn.2020-02.com.example:server1 --portal 172.16.0.187:3260 --logout

=> If you have any doubts please comment below or you can mail me-
 JohnTheH4cker

Comments