Every IT industry needs storage for saving the increasing data day by day. There are different methods by which we can provide storage to our client servers like through SAN, NAS, DAS, iSCSI, etc. In this tutorial, we are going to learn how to share storage from the main server to the client machine using iSCSI target in Red Hat Enterprise Linux 7 (RHEL 7).
Sharing the storage through iSCSI (Internet Small Computer System Interface) is very economical and any machine can become target i.e. server which will provide the storage. This is a software based technique to provide storage to the client servers and requires “targetcli” rpm. And if you are preparing for RHCE exam, this is one of the objectives of the exam.
Basically, in this tutorial, we will learn how to configure or setup an iSCSI target using targetcli in RHEL7 or CentOS 7.
Step by Step Procedure to setup an iSCSI target in RHEL 7
1. First of all, verify if you have targetcli RPM or not. If not install it using OS native commands. We had the package already so it updated it using repo.
[root@server ~]# rpm -qa |grep -i targetcli targetcli-2.1.fb41-3.el7.noarch [root@server ~]# [root@server ~]# yum install targetcli -y
2. Now once the targetcli package is installed, enable and start it. Enable will make sure target service is active after every reboot.
[root@server ~]# systemctl status target.service ● target.service - Restore LIO kernel target configuration Loaded: loaded (/usr/lib/systemd/system/target.service; disabled; vendor preset: disabled) Active: inactive (dead) [root@server ~]# systemctl enable target.service Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service. [root@server ~]# systemctl start target.service [root@server ~]# systemctl status target.service ● target.service - Restore LIO kernel target configuration Loaded: loaded (/usr/lib/systemd/system/target.service; enabled; vendor preset: disabled) Active: active (exited) since Thu 2018-03-15 01:46:22 PDT; 1s ago Process: 4604 ExecStart=/usr/bin/targetctl restore (code=exited, status=0/SUCCESS) Main PID: 4604 (code=exited, status=0/SUCCESS) Mar 15 01:46:22 server systemd[1]: Starting Restore LIO kernel target configuration... Mar 15 01:46:22 server target[4604]: No saved config file at /etc/target/saveconfig.json, ok, exiting Mar 15 01:46:22 server systemd[1]: Started Restore LIO kernel target configuration. [root@server ~]#
3. Now add permanently iSCSI port 3260 to the firewall rule using the below commands and reload firewalld service.
[root@server ~]# firewall-cmd --permanent --add-port=3260/tcp success [root@server ~]# firewall-cmd --reload success [root@server ~]# firewall-cmd --list-port 3260/tcp [root@server ~]#
Note: You won’t be able to see the port 3260 until you reload the firewalld service.
4. Now create a partition of the disk and set the size which you are going to share. You can also share a complete disk. Here, for example, we are creating 200MB partition with id “8e” for LVM and will create a logical volume (lv) with it.
[root@server ~]# pvcreate /dev/sdb5 Physical volume "/dev/sdb5" successfully created [root@server ~]# [root@server ~]# vgcreate iscsi_vg /dev/sdb5 Volume group "iscsi_vg" successfully created [root@server ~]# [root@server ~]# vgs VG #PV #LV #SN Attr VSize VFree iscsi_vg 1 0 0 wz--n- 196.00m 196.00m [root@server ~]# [root@server ~]# lvcreate -l +100%PVS -n iscsi_lv iscsi_vg Logical volume "iscsi_lv" created. [root@server ~]# [root@server ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert iscsi_lv iscsi_vg -wi-a----- 196.00m [root@server ~]# [root@server ~]# vgs VG #PV #LV #SN Attr VSize VFree iscsi_vg 1 1 0 wz--n- 196.00m 0 [root@server ~]#
Now you have to set configure your target and share the disk to the client. This is where actual work begins and should be done very carefully. We will use ‘targetcli’ command and then follow the steps given below.
5. Enter command ‘targetcli’ to get an iSCSI CLI prompt.
[root@server ~]# targetcli Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.fb46 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. />
6. Now, use the logical volume (/dev/iscsi_vg/iscsi_lv) created in step 4 to create a block storage object ‘iscsi_disk’.
/> /backstores/block create iscsi_disk /dev/iscsi_vg/iscsi_lv Created block storage object iscsi_disk using /dev/iscsi_vg/iscsi_lv. />
7. Then, create an IQN (iSCSI Qualified Name) called iqn.2018-06.com.server:client1.disk1. This will also create a default TPG (Target Portal Group).
/> /iscsi create iqn.2018-06.com.server:client1.disk1 Created target iqn.2018-06.com.server:client1.disk1. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. />
If default portal is created, like above one, delete it. We will create a new one later.
/> cd /iscsi/iqn.2018-06.com.server:client1.disk1/tpg1/portals /iscsi/iqn.20.../tpg1/portals> ls o- portals ................................................................................. [Portals: 1] o- 0.0.0.0:3260 .................................................................................. [OK] /iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 ip_port=3260 Deleted network portal 0.0.0.0:3260
8.Now, we will create an ACL in the TPG.
/> /iscsi/iqn.2018-06.com.server:client1.disk1/tpg1/acls create iqn.2018-06.com.server:client2 Created Node ACL for iqn.2018-06.com.server:client2 />
This ACL configures the target to only accept initiator connections from a client presenting iqn.2018-06.com.server:client2 as it’s initiator IQN, also name as initiator name.
9. Create a lun for each backstores, here we have only 1 backstores, so we will create only 1 lun. This steps also activates the corresponding backstores.
/> /iscsi/iqn.2018-06.com.server:client1.disk1/tpg1/luns create /backstores/block/iscsi_disk Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.2018-06.com.server:client2
10. Now create a portal to designate the listening IP address and ports. The IP given below is the IP of the client where you want to provide the storage.
/> /iscsi/iqn.2018-06.com.server:client1.disk1/tpg1/portals create 192.168.1.18 />
The whole configuration should look like below. After that, you can exit the targetcli prompt.
/iscsi> ls o- iscsi ................................................................................... [Targets: 1] o- iqn.2018-06.com.server:client1.disk1 ..................................................... [TPGs: 1] o- tpg1 ...................................................................... [no-gen-acls, no-auth] o- acls ................................................................................. [ACLs: 1] | o- iqn.2018-06.com.server:client2 .............................................. [Mapped LUNs: 1] | o- mapped_lun0 ................................................... [lun0 block/iscsi_disk (rw)] o- luns ................................................................................. [LUNs: 1] | o- lun0 .......................... [block/iscsi_disk (/dev/iscsi_vg/iscsi_lv) (default_tg_pt_gp)] o- portals ........................................................................... [Portals: 1] o- 192.168.1.18:3260 ....................................................................... [OK] /iscsi> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json
11. Now, just restart the target service.
[root@server ~]# systemctl restart target.service [root@server ~]#
This was all about configuring your iSCSI target or iSCSI server and sharing to the client or iSCSI initiator. Hope you were able to understand and follow the steps. In case of any questions or doubt, please comment below. In the next article, we will see how to setup iSCSI initiator and mount the filesystem. So do not forget to subscribe our blog.
In case you like this article, please share it on your social media.