In this article, I am going to show you how to configure iSCSI storage server on CentOS 8. So, let’s get started.

Basics of iSCSI:

iSCSI storage server is used to share block devices such as HDD/SSD partitions, or LVM partitions, or block files on the network. iSCSI clients can use these shares over the network just as any ordinary HDD or SSD mounted to it. The iSCSI client can format these disks, mount them and store files and directories as usual.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Fig 1: iSCSI server-client architecture

Each iSCSI client has an initiator ID which is used to connect to the targets on the server.

The targets are shares on the iSCSI server. Each target consists of a unique name (IQN), the path of the block device (i.e. disk partition or block file), the initiator ID that can connect to this target, and an optional username-password based authentication system.

In fig 1, the iSCSI storage server allows 3 initiators (3 iSCSI clients) to connect to 4 targets. initiator01 can connect to target01 and target02, initiator02 can connect to target03, and initiator03 can connect to target04.

iSCSI Target and Initiator Naming Conventions:

The iSCSI target name and initiator name must be unique.

The target naming format is:

iqn.YYYY-MM.reverse-domain-name:target-name

Example:

 iqn.2020-03.com.linuxhint:www, iqn.2020-03.com.linuxhint:logs,


 iqn.2020-03.com.linuxhint:user-bob etc.

The initiator naming format is:

iqn.YYYY-MM.reverse-domain-name:initiator-name

Example:

iqn.2020-03.com.linuxhint:initiator01, iqn.2020-03.com.linuxhint:initiator02,


 iqn.2020-03.com.linuxhint:initiator03 etc.

Network Topology:

Configure iSCSI Storage Server on CentOS 8 centos Storage

Fig 2: Network topology used in this iSCSI server article

The network topology used in this article is given in fig 2. Here, I will configure a CentOS 8 machine as an iSCSI server. The iSCSI server has a static IP address 192.168.20.197. The iSCSI client is also on the network 192.168.20.0/24. So, it can access the iSCSI server.

Setting Up Static IP Address:

You must set up a static IP address on your CentOS 8 machine which you will configure as an iSCSI server. To set up a static IP address on CentOS 8, check my article Configuring Static IP on CentOS 8.

The CentOS 8 machine I will configure as an iSCSI server in this article has the static IP address 192.168.20.197. It will be different for you. So, make sure to replace it with yours from now on.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Installing iSCSI Server Tools:

First, update the DNF package repository cache as follows:

Configure iSCSI Storage Server on CentOS 8 centos Storage

You must have targetcli tool installed on the CentOS 8 machine which you want to configure as an iSCSI server.

To install targetcli, run the following command:

$ sudo dnf install targetcli

Configure iSCSI Storage Server on CentOS 8 centos Storage

To confirm the installation, press Y and then press .

Configure iSCSI Storage Server on CentOS 8 centos Storage

targetcli should be installed.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, to test whether the targetcli tool is working, start targetcli as follows:

Configure iSCSI Storage Server on CentOS 8 centos Storage

targetcli should start.

Configure iSCSI Storage Server on CentOS 8 centos Storage

targetcli is working perfectly.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, exit out of the targetcli tool.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, start target service as follows:

$ sudo systemctl start target

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, add target service to the system startup as follows:

$ sudo systemctl enable target

Configure iSCSI Storage Server on CentOS 8 centos Storage

Sharing File Blocks:

You can share file blocks as storage devices via iSCSI.

First, create a new directory where you want to keep all the file blocks as follows:

$ sudo mkdir -pv /iscsi/blocks

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, start targetcli as follows:

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, create a new 1 GB fileio backstore web1 in the path /iscsi/blocks/web1.img as follows:

> /backstores/fileio create web1 /iscsi/blocks/web1.img 1G

Configure iSCSI Storage Server on CentOS 8 centos Storage

The web1 1GB file block should be created in the path /iscsi/blocks/web1.img

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, create a new iSCSI target iqn.2020-03.com.linuxhint:web as follows:

> /iscsi create iqn.2020-03.com.linuxhint:web

Configure iSCSI Storage Server on CentOS 8 centos Storage

The iSCSI target iqn.2020-03.com.linuxhint:web should be created.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, navigate to the target’s TPG (Target Portal Group) as follows:

> /iscsi/iqn.2020-03.com.linuxhint:web/tpg1/

Configure iSCSI Storage Server on CentOS 8 centos Storage

This is how the TPG of the target should look like.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, create a LUN from the web1 fileio backstore you’ve created earlier.

> luns/ create /backstores/fileio/web1

Configure iSCSI Storage Server on CentOS 8 centos Storage

LUN 0 should be created.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, create an ACL for the initiator iqn.2020-03.com.linuxhint:init1 so that the iSCSI client can access the LUNS in this target.

> acls/ create iqn.2020-03.com.linuxhint:init1

Configure iSCSI Storage Server on CentOS 8 centos Storage

An ACL should be created and LUN 0 should be mapped to it.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, save the configuration.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, exit out of the targetcli interface.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Sharing HDD/SSD or HDD/SSD Partitions:

You can also share the whole HDD/SSD or one or more HDD/SSD partition via iSCSI. If you share the whole HDD/SSD, the partitions of that HDD/SSD will also be accessible from the initiator or the iSCSI client.

First, find the HDD/SSD name or HDD/SSD partition name that you want to share with the following command:

Here, nvme0n2 is the SSD name and nvme0n2p1, nvme0n2p2 and nvme0n2p3 are the partitions of  that SSD.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, start targetcli as follows:

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, create a block backstore data1 using the HDD/SSD or HDD/SSD partition as follows.

> /backstores/block create data1 /dev/nvme0n2p1

NOTE: Here, I used the SSD partition /dev/nvme0n2p1.

Configure iSCSI Storage Server on CentOS 8 centos Storage

The data1 block backstore should be created.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, create a new iSCSI target iqn.2020-03.com.linuxhint:data as follows:

> /iscsi/ create iqn.2020-03.com.linuxhint:data

Configure iSCSI Storage Server on CentOS 8 centos Storage

A new iSCSI target should be created.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, navigate to the TPG of the target as follows:

> /iscsi/iqn.2020-03.com.linuxhint:data/tpg1/

Configure iSCSI Storage Server on CentOS 8 centos Storage

The TPG of the target should look as follows.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, create a new LUN from the data1 block backstore you’ve created earlier.

> luns/ create /backstores/block/data1

Configure iSCSI Storage Server on CentOS 8 centos Storage

A new LUN should be created.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, create an ACL for the initiator iqn.2020-03.com.linuxhint:init1 so that the iSCSI client can access the LUNS in this target.

> acls/ create iqn.2020-03.com.linuxhint:init1

Configure iSCSI Storage Server on CentOS 8 centos Storage

An ACL should be created and LUN 0 should be mapped to it.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, save the configuration.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, exit out of the targetcli interface.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Configuring Firewall:

Now, allow access to the iSCSI port 3260 through the firewall as follows:

$ sudo firewall-cmd –add-service=iscsi-target –permanent

Configure iSCSI Storage Server on CentOS 8 centos Storage

For the changes to take effect, run the following command:

$ sudo firewall-cmd –reload

Configure iSCSI Storage Server on CentOS 8 centos Storage

Installing iSCSI Client Tools:

On the iSCSI client, you must have iscsi-initiator-utils package installed in order to access the shared iSCSI storage devices.

First, update the DNF package repository cache as follows:

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, install iscsi-initiator-utils package on the client machine as follows:

$ sudo dnf install iscsi-initiator-utils

Configure iSCSI Storage Server on CentOS 8 centos Storage

To confirm the installation, press Y and then press .

Configure iSCSI Storage Server on CentOS 8 centos Storage

iSCSI client utilities should be installed.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, open the /etc/iscsi/initiatorname.iscsi configuration file as follows:

$ sudo vi /etc/iscsi/initiatorname.iscsi

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, set your initiator name to InitiatorName and save the file.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, scan for the targets as follows:

$ sudo iscsiadm -m discovery -t sendtargets -p 192.168.20.197

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, you can login to the targets as follows:

$ sudo iscsiadm -m node –login

Configure iSCSI Storage Server on CentOS 8 centos Storage

The iSCSI storage devices should be attached to your client as you can see in the screenshot below.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, start the iscsi and iscsid services as follows:

$ sudo systemctl start iscsi


$ sudo systemctl start iscsid

Configure iSCSI Storage Server on CentOS 8 centos Storage

The iscsi and iscsid services should be running.

$ sudo systemctl status iscsi iscsid

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, add the iscsi and iscsid service to the system startup as follows:

$ sudo systemctl enable iscsi


$ sudo systemctl enable iscsid

Configure iSCSI Storage Server on CentOS 8 centos Storage

Configure iSCSI Storage Server on CentOS 8 centos Storage

Mounting iSCSI Disk:

You can mount the iSCSI disks permanently on the iSCSI client using the /etc/fstab file.

First, format the iSCSI disk if it’s not already formatted.

$ sudo mkfs.ext4 -L data /dev/sda

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, create a directory (mount point) for the iSCSI disk as follows:

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, find the UUID of the iSCSI disk that you want to mount as follows:

The UUID in my case is c1cbfa44-a8a9-4343-a88e-769b63a6e006. It will be different for you. So, make sure to replace it with yours in the /etc/fstab file.

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, open the /etc/fstab file as follows:

Configure iSCSI Storage Server on CentOS 8 centos Storage

Now, add the following line to the /etc/fstab file.

UUID=c1cbfa44-a8a9-4343-a88e-769b63a6e006

/data     ext4       defaults,_netdev   0 0

Configure iSCSI Storage Server on CentOS 8 centos Storage

Make sure to add the _netdev option in the /etc/fstab file while mounting iSCSI disks. Otherwise, your CentOS 8 iSCSI client may not boot.

Now, you can mount the iSCSI disk for the first time as follows:

Configure iSCSI Storage Server on CentOS 8 centos Storage

As you can see, the iSCSI disk is mounted correctly.

Configure iSCSI Storage Server on CentOS 8 centos Storage

So, that’s how you configure iSCSI storage server and client on CentOS 8. Thanks for reading this article.

About the author

Configure iSCSI Storage Server on CentOS 8 centos Storage

Shahriar Shovon

Freelancer & Linux System Administrator. Also loves Web API development with Node.js and JavaScript. I was born in Bangladesh. I am currently studying Electronics and Communication Engineering at Khulna University of Engineering & Technology (KUET), one of the demanding public engineering universities of Bangladesh.