Configure iSCSI Storage Server on CentOS 8

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.

Fig 1: iSCSI server-client architecture

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:

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.

$ ip a

Installing iSCSI Server Tools:

First, update the DNF package repository cache as follows:

$ sudo dnf makecache

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

To confirm the installation, press Y and then press <Enter>.

targetcli should be installed.

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

$ sudo targetcli

targetcli should start.

targetcli is working perfectly.

> ls

Now, exit out of the targetcli tool.

> exit

Now, start target service as follows:

$ sudo systemctl start target

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

$ sudo systemctl enable target

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

Now, start targetcli as follows:

$ sudo targetcli

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

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

> ls /

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

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

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

> ls /

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

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

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

> ls

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

> luns/ create /backstores/fileio/web1

LUN 0 should be created.

> ls

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

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

> ls

Now, save the configuration.

> / saveconfig

Now, exit out of the targetcli interface.

> exit

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:

$ sudo lsblk

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

Now, start targetcli as follows:

$ sudo targetcli

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.

The data1 block backstore should be created.

> ls /

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

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

A new iSCSI target should be created.

> ls /

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

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

The TPG of the target should look as follows.

> ls

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

> luns/ create /backstores/block/data1

A new LUN should be created.

> ls

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

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

> ls

Now, save the configuration.

> / saveconfig

Now, exit out of the targetcli interface.

> exit

Configuring Firewall:

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

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

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

$ sudo firewall-cmd --reload

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:

$ sudo dnf makecache

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

$ sudo dnf install iscsi-initiator-utils

To confirm the installation, press Y and then press <Enter>.

iSCSI client utilities should be installed.

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

$ sudo vi /etc/iscsi/initiatorname.iscsi

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

Now, scan for the targets as follows:

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

Now, you can login to the targets as follows:

$ sudo iscsiadm -m node --login

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

$ sudo lsblk

Now, start the iscsi and iscsid services as follows:

$ sudo systemctl start iscsi
$ sudo systemctl start iscsid

The iscsi and iscsid services should be running.

$ sudo systemctl status iscsi iscsid

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

$ sudo systemctl enable iscsi
$ sudo systemctl enable iscsid

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

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

$ sudo mkdir /data

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

$ sudo blkid

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.

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

$ sudo vi /etc/fstab

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

UUID=c1cbfa44-a8a9-4343-a88e-769b63a6e006
/data     ext4       defaults,_netdev   0 0

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:

$ sudo mount /data

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

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



from Linux Hint https://ift.tt/3arLXfP

Post a Comment

0 Comments