configure iscsi target server

This post will show you How to Install and Configure iSCSI Target Server using targetcli on Linux.

If you are interested in learning, Request you to go through the below recommended tutorial.

In a SCSI Environment, there are two kind of iSCSI connecting types which are,

1. An iSCSI target which provides some storage space, this would be at server end.
2. An iSCSI initiator who access the provided space from storage at client end. This iSCSI initiator would be at Client end.

Our Scenario:

1. iSCSI Server : 192.168.2.1
2. iSCSI Client : 192.168.2.2

At Server End: iSCSI Target Congfiguration

iSCSI target configuration is done through the interactively targetcli command. This command uses a directory tree structures to access the different objects.

Configure iSCSI Target Server using targetcli on Linux

To create an iSCSI target server, we need to follow the below steps on the server.

ALSO WATCH THIS iSCSI CONFIGURATION TUTORIAL VIDEO FREE ON OUR YOUTUBE CHANNEL

Install the required Packages using YUM
If yum not configured, please go through this link How to Configure Local Yum Server

[root @learnitguide ~]#  yum install -y targetcli

Activate the target service at boot:

[root @learnitguide ~]#  systemctl enable target

Note: This is required to be enabled, otherwise your configuration won’t be read after a reboot!

Execute the targetcli command

[root @learnitguide ~]#  targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb34
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type ‘help’.
/>

Creating Backstores

There is a two main options, fileio and block.

We will go with block backstores,

block backstore that usually provides the best performance. You can use a block device like /dev/sdb or a logical volume previously created.

/> backstores/block/ create mylun /dev/VolGroup00/lvol00
Created block storage object block1 using /dev/VolGroup00/lvol00.

Creating an IQN

/> iscsi/ create iqn.2015-07.net.learnitguide:t1
Created target iqn.2015-07.net.learnitguide.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.

Now, we can go to the newly created directory.

Three objects have been defined under tpg1:

  1. acls (access control lists: restrict access to resources),
  2. luns (logical unit number),
  3. portals (define ways to reach the exported resources).

/iscsi/iqn.20…ple:t1/tpg1> portals/ create
Using default IP port 3260
Binding to INADDR_ANY (0.0.0.0)
Created network portal 0.0.0.0:3260.

Finally check the configuration using the command “ls” and quit from the targetcli session.

/iscsi/iqn.20…ple:tgt1/tpg1> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

Note: The configuration is automatically saved to the /etc/target/saveconfig.json file.

Also, it can be useful to check the ports currently used so we can confirm who accessing it.

[root @learnitguide ~]#  netstat -ant
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:3260            0.0.0.0:*               LISTEN
tcp        0      0 192.168.2.1:22         192.168.2.2:33584      ESTABLISHED
tcp6       0      0 :::22                   :::*                    LISTEN
tcp6       0      0 ::1:25                  :::*                    LISTEN

Finally, open the 3260 tcp port in the firewall configuration:

[root @learnitguide ~]#  firewall-cmd –permanent –add-port=3260/tcp
Success

Reload the firewall configuration:

[root @learnitguide ~]#  firewall-cmd –reload
Success

That’s it, we are done with iSCSI target configuration at server end. Now we need to go to the client and access the lun as mentioned in our previous articles. Click here to see How to Access or Map an iSCSI LUN Volume on Linux Client.

Related Content on Linux might be useful to you to improve your Linux Skills.

Keep practicing and have fun. Leave your comments if any.

Support Us: Share with your friends and groups.

Stay connected with us on social networking sites, Thank you.