Introduction
In this article, we will explore the what, who, where, when, why, and how of Network File System (NFS) as Storage Server functionality on the Fedora 40 platform, so let's get started.
Overview
What
iSCSI Target Configuration using Targetcli involves setting up storage devices to be accessible over a network. It includes creating targets, setting up LUNs (Logical Unit Numbers), and managing access.
Who
System administrators and IT professionals responsible for managing and configuring storage networks and resources.
Where
This configuration is applicable in data centers, enterprise environments, or any setup requiring networked storage solutions.
When
When you need to provide centralized storage resources accessible over a network, iSCSI target configuration becomes crucial.
Why
Configuring iSCSI targets has several pros and cons:
Pros | Cons |
---|---|
Centralized storage management. | Network dependency can lead to latency issues. |
Scalability for large environments. | Requires careful network planning and configuration. |
Cost-effective compared to other storage solutions. | Performance can be affected by network congestion. |
Flexibility in storage allocation. | Potential security risks if not properly managed. |
How
Follow these steps to configure an iSCSI target using Targetcli:
Step 1 | Install Targetcli: sudo apt-get install targetcli |
Step 2 | Create a backing store: targetcli backstores/fileio create mybackstore /path/to/file.img 10G |
Step 3 | Create an iSCSI target: targetcli iscsi/ create iqn.2024-11.com.example:target |
Step 4 | Assign LUNs: targetcli iscsi/iqn.2024-11.com.example:target/tpg1/luns/ create /backstores/fileio/mybackstore |
Consequences
Setting up an iSCSI target using Targetcli can lead to several consequences:
Positive |
|
Negative |
|
Conclusion
Configuring iSCSI targets using Targetcli offers a robust and flexible solution for networked storage. While it comes with its challenges, the benefits of centralized management, scalability, and cost-effectiveness make it a compelling choice for many organizations. Proper planning and security measures are essential to mitigate potential risks and ensure optimal performance.
iSCSI : Configure Target (Targetcli)
Configure Storage Server with iSCSI. Storage server with iSCSI on network is called iSCSI Target, Client Host that connects to iSCSI Target is called iSCSI Initiator. This example is based on the environment like follows.
+----------------------+ | +-------------------------+ | [ iSCSI Target ] |10.0.0.30 | 10.0.0.51| [ iSCSI Initiator ] | | dlp.bizantum.lab +----------+----------+ node01.bizantum.lab | | | | | +----------------------+ +-------------------------+
Step [1]Install administration tool.
[root@dlp ~]# dnf -y install targetcli
Step [2]Configure iSCSI Target. For example, Create a disk-image under the [/var/lib/iscsi_disks] directory and set it as a SCSI device.
# create a directory
[root@dlp ~]# mkdir /var/lib/iscsi_disks
# enter to the admin console
[root@dlp ~]# targetcli
targetcli shell version 2.1.58
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> cd /backstores/fileio
# create a disk-image with the name [disk01] on [/var/lib/iscsi_disks/disk01.img] with 10G
/backstores/fileio> create disk01 /var/lib/iscsi_disks/disk01.img 10G
Created fileio disk01 with size 10737418240
/backstores/fileio> cd /iscsi
# create a target
# naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]
/iscsi> create iqn.2024-04.lab.bizantum:dlp.target01
Created target iqn.2024-04.lab.bizantum:dlp.target01.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> cd iqn.2024-04.lab.bizantum:dlp.target01/tpg1
# enable authentication
/iscsi/iqn.20...target01/tpg1> set attribute authentication=1
Parameter authentication is now '1'.
/iscsi/iqn.20...target01/tpg1> cd luns
# set LUN
/iscsi/iqn.20...t01/tpg1/luns> create /backstores/fileio/disk01
Created LUN 0.
/iscsi/iqn.20...t01/tpg1/luns> cd ../acls
# set ACL (it's the IQN of an initiator you permit to connect)
/iscsi/iqn.20...t01/tpg1/acls> create iqn.2024-04.lab.bizantum:node01.initiator
Created Node ACL for iqn.2024-04.lab.bizantum:node01.initiator
Created mapped LUN 0.
/iscsi/iqn.20...t01/tpg1/acls> cd iqn.2024-04.lab.bizantum:node01.initiator
# set UserID and Password for authentication
/iscsi/iqn.20...w.initiator> set auth userid=username
Parameter userid is now 'username'.
/iscsi/iqn.20...w.initiator> set auth password=password
Parameter password is now 'password'.
/iscsi/iqn.20...w.initiator> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
# after configuration above, the target enters in listening like follows
[root@dlp ~]# ss -napt | grep 3260
LISTEN 0 256 0.0.0.0:3260 0.0.0.0:*
[root@dlp ~]# systemctl enable target
Step [3]If Firewalld is running, allow iSCSI Target service.
[root@dlp ~]# firewall-cmd --add-service=iscsi-target
success
[root@dlp ~]# firewall-cmd --runtime-to-permanent
success
iSCSI : Configure Target (tgt)
Configure Storage Server with iSCSI. This is the example of configuring iSCSI Target with scsi-target-utils. (tgt) Storage server with iSCSI on network is called iSCSI Target, Client Host that connects to iSCSI Target is called iSCSI Initiator. This example is based on the environment like follows.
+----------------------+ | +-------------------------+ | [ iSCSI Target ] |10.0.0.30 | 10.0.0.51| [ iSCSI Initiator ] | | dlp.bizantum.lab +----------+----------+ node01.bizantum.lab | | | | | +----------------------+ +-------------------------+
Step [1]Install administration tools.
[root@dlp ~]# dnf -y install scsi-target-utils
Step [2] Configure iSCSI Target. For example, create an disk-image under the [/var/lib/iscsi_disks] directory and set it as a SCSI device.
# create a disk image
[root@dlp ~]# mkdir /var/lib/iscsi_disks
[root@dlp ~]# dd if=/dev/zero of=/var/lib/iscsi_disks/disk01.img count=0 bs=1 seek=10G
[root@dlp ~]# vi /etc/tgt/conf.d/target01.conf
# create new
# if you set some devices, add - and set the same way with follows
# naming rule : [ iqn.(year)-(month).(reverse of domain name):(any name you like) ]
<target iqn.2024-04.lab.bizantum:dlp.target01>
# provided device as a iSCSI target
backing-store /var/lib/iscsi_disks/disk01.img
# iSCSI Initiator's IQN you allow to connect
initiator-name iqn.2024-04.lab.bizantum:node01.initiator
# authentication info ( set anyone you like for "username", "password" )
incominguser username password
</target>
Step [3]If SELinux is enabled, change SELinux Context.
[root@dlp ~]# dnf -y install policycoreutils-python-utils
[root@dlp ~]# chcon -R -t tgtd_var_lib_t /var/lib/iscsi_disks
[root@dlp ~]# semanage fcontext -a -t tgtd_var_lib_t /var/lib/iscsi_disks
Step [4]If SELinux is enabled, change SELinux Context.
[root@dlp ~]# firewall-cmd --add-service=iscsi-target
success
[root@dlp ~]# firewall-cmd --runtime-to-permanent
success
Step [5]Start tgtd and verify status.
[root@dlp ~]# systemctl enable --now tgtd
# show status
[root@dlp ~]# tgtadm --mode target --op show
Target 1: iqn.2024-04.lab.bizantum:dlp.target01
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:
LUN: 1
Type: disk
SCSI ID: IET 00010001
SCSI SN: beaf11
Size: 10737 MB, Block size: 512
Online: Yes
Removable media: No
Prevent removal: No
Readonly: No
SWP: No
Thin-provisioning: No
Backing store type: rdwr
Backing store path: /var/lib/iscsi_disks/disk02.img
Backing store flags:
Account information:
username
ACL information:
ALL
iqn.2024-04.lab.bizantum:node01.initiator
iSCSI : Configure Initiator
Configure iSCSI Initiator. This example is based on the environment like follows.
+----------------------+ | +-------------------------+ | [ iSCSI Target ] |10.0.0.30 | 10.0.0.51| [ iSCSI Initiator ] | | dlp.bizantum.lab +----------+----------+ node01.bizantum.lab | | | | | +----------------------+ +-------------------------+
Step [1]Configure iSCSI Initiator to connect to iSCSI Target.
[root@node01 ~]# dnf -y install iscsi-initiator-utils
[root@node01 ~]# vi /etc/iscsi/initiatorname.iscsi
# set to the same IQN you set on the iSCSI target server
InitiatorName=iqn.2024-04.lab.bizantum:node01.initiator
[root@node01 ~]# vi /etc/iscsi/iscsid.conf
# line 67 : uncomment
node.session.auth.authmethod = CHAP
# line 79,80 : uncomment and specify the username and password you set on the iSCSI target server
node.session.auth.username = username
node.session.auth.password = password
# discover target
[root@node01 ~]# iscsiadm -m discovery -t sendtargets -p 10.0.0.30
10.0.0.30:3260,1 iqn.2024-04.lab.bizantum:dlp.target01
# confirm status after discovery
[root@node01 ~]# iscsiadm -m node -o show
# BEGIN RECORD 6.2.1.9
node.name = iqn.2024-04.lab.bizantum:dlp.target01
node.tpgt = 1
node.startup = automatic
node.leading_login = No
iface.iscsi_ifacename = default
.....
.....
node.conn[0].iscsi.DataDigest = None
node.conn[0].iscsi.IFMarker = No
node.conn[0].iscsi.OFMarker = No
# END RECORD
# login to the target
# if logout ⇒ iscsiadm --mode node --logoutall=all
[root@node01 ~]# iscsiadm -m node --login -p 10.0.0.30
Logging in to [iface: default, target: iqn.2024-04.lab.bizantum:dlp.target01, portal: 10.0.0.30,3260]
Login to [iface: default, target: iqn.2024-04.lab.bizantum:dlp.target01, portal: 10.0.0.30,3260] successful.
# confirm the established session
[root@node01 ~]# iscsiadm -m session -o show
tcp: [1] 10.0.0.30:3260,1 iqn.2024-04.lab.bizantum:dlp.target01 (non-flash)
# confirm the partitions
[root@node01 ~]# cat /proc/partitions
major minor #blocks name
252 0 31457280 sda
252 1 1024 sda1
252 2 1048576 sda2
252 3 30405632 sda3
253 0 15728640 dm-0
251 0 3992576 zram0
8 0 10485760 sdb
# added new device provided from the target server as [sdb]
Step [2]After setting iSCSI device, configure on Initiator to use it like follows.
# create label
[root@node01 ~]# parted --script /dev/sdb "mklabel gpt"
# create partition
[root@node01 ~]# parted --script /dev/sdb "mkpart primary 0% 100%"
# format with XFS
[root@node01 ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655232 blks
= sectsz=4096 attr=2, projid32bit=1
= crc=1 finobt=1, sparse=1, rmapbt=0
= reflink=1 bigtime=1 inobtcount=1
data = bsize=4096 blocks=2620928, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0, ftype=1
log =internal log bsize=4096 blocks=16384, version=2
= sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
[root@node01 ~]# mount /dev/sdb1 /mnt
[root@node01 ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/fedora-root xfs 15G 1.9G 14G 13% /
devtmpfs devtmpfs 4.0M 0 4.0M 0% /dev
tmpfs tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs tmpfs 782M 1.1M 781M 1% /run
tmpfs tmpfs 2.0G 0 2.0G 0% /tmp
/dev/sda2 xfs 960M 344M 617M 36% /boot
tmpfs tmpfs 391M 4.0K 391M 1% /run/user/0
/dev/sdb1 xfs 10G 227M 9.8G 3% /mnt
- Get link
- X
- Other Apps
Comments
Post a Comment
Thank you for your comment! We appreciate your feedback, feel free to check out more of our articles.
Best regards, Bizantum Blog Team.