Linux

How to Set Up an iSCSI Storage Server on Ubuntu 20.04 LTS

How to Set Up an iSCSI Storage Server on Ubuntu 20.04 LTS

iSCSI stands for Internet Small Computer System Interface is a Storage Area Network protocol that can be used to share block devices such as HDD / SSD partitions, or LVM partitions, or block files on the network. iSCSI works in a client-server model and relies on TCP / IP networks to send SCSI commands between the client and the initiating target. ISCSI Target is a service on the iSCSI server that provides access to shared storage and iSCSI Initiator is an iSCSI client that is connected to the target and accesses shared storage.

In this tutorial, we will explain how to set iSCSI targets and iSCSI initiators on an Ubuntu 20.04 server.

Requirements

  • A system running Ubuntu 20.04 for the iSCSI target with a 1GB external HDD.
  • A new system running Ubuntu 20.04 for the iSCSI initiator.
  • The static IP address 192.168.1.10 is configured on the iSCSI target and 192.168.1.20 is configured on the iSCSI initiator.
  • The root password is configured on both servers.

System Update

Before you begin, it’s a good idea to update your system with the latest packages. You can update it with the following command:

apt-get update -y
apt-get upgrade -y

After all packages have been updated, restart your system to apply changes.

Install iSCSI Target

By default, the iSCSI Target package is available in the default Ubuntu 20.04 repository. You can install it by running the following command on the iSCSI Target server:

apt-get install tgt -y

After installing iSCSI Target, verify the server status with the following command:

systemctl status tgt

You should get the following output:

? tgt.service - (i)SCSI target daemon
     Loaded: loaded (/lib/systemd/system/tgt.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-07-11 07:13:04 UTC; 23s ago
       Docs: man:tgtd(8)
   Main PID: 7770 (tgtd)
     Status: "Starting event loop..."
      Tasks: 1
     Memory: 1.1M
     CGroup: /system.slice/tgt.service
             ??7770 /usr/sbin/tgtd -f

Jul 11 07:13:04 ubuntu2004 systemd[1]: Starting (i)SCSI target daemon...
Jul 11 07:13:04 ubuntu2004 tgtd[7770]: tgtd: iser_ib_init(3431) Failed to initialize RDMA; load kernel modules?
Jul 11 07:13:04 ubuntu2004 tgtd[7770]: tgtd: work_timer_start(146) use timer_fd based scheduler
Jul 11 07:13:04 ubuntu2004 tgtd[7770]: tgtd: bs_init(387) use signalfd notification
Jul 11 07:13:04 ubuntu2004 systemd[1]: Started (i)SCSI target daemon.

At this point, iSCSI Target is installed on your server, you can now proceed to the next step.

Configure iSCSI Targets

First, you must create a Logical Unit Number (LUN) device on your iSCSI server. LUN is a backend storage device that is part of a physical SCSI device. All LUNs are mapped to the iSCSI Target virtually attached to the client operating system. Therefore, Initiator can create and manage file systems on the iSCSI LUN.

You can configure it by creating a new configuration file:

nano /etc/tgt/conf.d/iscsi.conf

Add the following lines:

<target iqn.2020-07.example.com:lun1>
     backing-store /dev/sdb
     initiator-address 192.168.1.20
    incominguser iscsi-user password
     outgoinguser iscsi-target secretpass
</target>

Save and close the file when you are finished.

Where:

  • The first line defines the name LUN.
  • The second line determines the location and name of the storage device on the iSCSI Target server.
  • The third line determines the IP address of the iSCSI initiator.
  • The fourth line defines the username / password that came in.
  • The fifth line defines the username / password that the initiator will give the target to allow the shared CHAP authentication to occur.

Next, restart the iSCSI service to apply the changes:

systemctl restart tgt

Next, verify the iSCSI Target server with the following command:

tgtadm --mode target --op show

You should get the following output:

Target 1: iqn.2020-07.example.com:lun1
    System information:
        Driver: iscsi
        State: ready
    I_T nexus information:
    LUN information:
        LUN: 0
            Type: controller
            SCSI ID: IET     00010000
            SCSI SN: beaf10
            Size: 0 MB, Block size: 1
            Online: Yes
            Removable media: No
            Prevent removal: No
            Readonly: No
            SWP: No
            Thin-provisioning: No
            Backing store type: null
            Backing store path: None
            Backing store flags: 
    Account information:
        iscsi-user
        iscsi-target (outgoing)
    ACL information:
        192.168.1.10

At this point, the iSCSI target server is installed and configured. Now you can proceed to the next step.

Install and Configure the iSCSI Initiator

Next, open the iSCSI initiator engine and install the iSCSI initiator package with the following command:

apt-get install open-iscsi -y

After the installation is complete, find the iSCSI target server to find the shared target using the following command:

iscsiadm -m discovery -t st -p 192.168.1.10

You will see the following output:

192.168.1.10:3260,1 iqn.2020-07.example.com:lun1

Next, you need to specify the name of the LUN device in the initiatorname.iscsi file:

nano /etc/iscsi/initiatorname.iscsi

Add your target iSCSI LUN name as shown below:

InitiatorName=iqn.2020-07.example.com:lun1

Save and close the file when you are finished.

Next, you need to determine the CHAP information that you have configured on the iSCSI target to access the iSCSI target from the iSCSI initiator. The node configuration file will be in the etc / etc / iscsi / nodes / direktori directory and will have a per LUN directory available.

You can define it by editing the following file:

nano /etc/iscsi/nodes/iqn.2020-07.example.com\:lun1/192.168.1.10\,3260\,1/default

Add / Change the following line:

node.session.auth.authmethod = CHAP  
node.session.auth.username = iscsi-user
node.session.auth.password = password          
node.session.auth.username_in = iscsi-target
node.session.auth.password_in = secretpass         
node.startup = automatic

Save and close the file then restart the iSCSI initiator service with the following command:

systemctl restart open-iscsi iscsid

You can also verify service status with the following command:

systemctl status open-iscsi

You should get the following output:

? open-iscsi.service - Login to default iSCSI targets
     Loaded: loaded (/lib/systemd/system/open-iscsi.service; enabled; vendor preset: enabled)
     Active: active (exited) since Sat 2020-07-11 07:24:19 UTC; 10s ago
       Docs: man:iscsiadm(8)
             man:iscsid(8)
    Process: 3861 ExecStart=/sbin/iscsiadm -m node --loginall=automatic (code=exited, status=0/SUCCESS)
    Process: 3867 ExecStart=/lib/open-iscsi/activate-storage.sh (code=exited, status=0/SUCCESS)
   Main PID: 3867 (code=exited, status=0/SUCCESS)

Jul 11 07:24:19 initiator systemd[1]: Starting Login to default iSCSI targets...
Jul 11 07:24:19 initiator iscsiadm[3861]: Logging in to [iface: default, target: iqn.2020-07.example.com:lun1, portal: 104.245.33.142,3260] (m>
Jul 11 07:24:19 initiator iscsiadm[3861]: Login to [iface: default, target: iqn.2020-07.example.com:lun1, portal: 104.245.33.142,3260] success>
Jul 11 07:24:19 initiator systemd[1]: Finished Login to default iSCSI targets.

You should get the following output:

iscsiadm -m session -o show

You should get the following output:

tcp: [2] 192.168.1.10:3260,1 iqn.2020-07.example.com:lun1 (non-flash)

You can also verify the shared storage device from the iSCSI target with the following command:

lsblk

You will see the shared device sdb in the following output:

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   80G  0 disk 
??sda1   8:1    0   80G  0 part /
sdb      8:16   0 1000M  0 disk

Create a File System on a Shared Device

To use a shared device on the iSCSI initiator, you must create a file system on the shared device (sdb) and install it to make this device useful.

First, create a file system on a shared device (sdb) with the following command:

fdisk /dev/sdb

Answer all questions as shown below to create a file system:

Welcome to fdisk (util-linux 2.34).
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.
Created a new DOS disklabel with disk identifier 0x9743ddcf.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-2047999, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2047999, default 2047999): 

Created a new partition 1 of type 'Linux' and of size 999 MiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Next, format the partition with the following command:

mkfs.ext4 /dev/sdb1

You should get the following output:

mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 255744 4k blocks and 64000 inodes
Filesystem UUID: e7f06605-a0f5-41e1-b1b2-e85bd7a2d6a3
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Next, attach the partition to the / mnt directory with the following command:

mount /dev/sdb1 /mnt

You can now verify the partition that was installed with the following command:

df -h

You should get the following output:

Filesystem      Size  Used Avail Use% Mounted on
udev            981M     0  981M   0% /dev
tmpfs           199M  588K  199M   1% /run
/dev/sda1        79G  1.8G   74G   3% /
tmpfs           994M     0  994M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           994M     0  994M   0% /sys/fs/cgroup
tmpfs           199M     0  199M   0% /run/user/0
/dev/sdb1       968M  2.5M  899M   1% /mnt

Conclusion

In the guide above, you learn how to set iSCSI targets and initiators on an Ubuntu 20.04 server. You also learn how to share devices on the Target server and access them from the initiator. Feel free to ask me if you have questions.

Related posts

How to Upgrade From Windows 7 to Linux

Howto

How to use Node Selectors in Kubernetes

Linux

How to Install a Plex Media Server on Ubuntu 20.04 / Linux Mint 20

Linux

How to Use a Loop in a Playbook Possible

Linux

How to Install Matrix Synapse Chat on Ubuntu 20.04 LTS

Linux

How to Install an Ubuntu 20.04 LTS (Focal Fossa) Server

Howto

How to Install Apache ActiveMQ on Debian 10

Linux

What is Fedora Linux?

InstallWorld

How To Install NTP (Chrony) On CentOS 8 / CentOS 7 & RHEL 8 / RHEL 7

Linux