iSCSI: Provides iSCSI-based network storage (server and initiator configuration)

write in front

  • Preparing for exams and organizing relevant notes
  • The blog post covers a brief introduction to iSCSI, server-side initiator configuration and a usage demo
  • If you don’t understand enough, please help me correct it.

There is only one true responsibility for everyone: to find themselves. Then stick to it in your heart for the rest of your life, wholeheartedly, and never stop. All other roads are incomplete, human escapes, cowardly returns to popular ideals, drifting, inner fears - Hermann Hesse, "Demian"


a brief introdction

iSCSI(Internet Small Computer System Interface)SCSI(Small Computer System Interface)It is a storage protocol for transmitting commands and data on IP networks . It allows remote storage devices to be mapped to local hosts, providing a network-based storage solution.

Insert image description here

The iSCSI service architecture involves the following components:

iSCSI Initiator(客户端): iSCSI发起器Refers to the host or computer system that communicates with remote storage devices through the iSCSI protocol. The initiator sends iSCSI commands and data over the network to access remote storage.

iSCSI Target(服务端): iSCSI目标is a remote storage device or storage server that accepts requests from initiators through the iSCSI protocol. The target converts received iSCSI commands into native SCSI commands to the storage device and transmits the data back to the initiator.

iSCSI Initiator 和 Target 之间的网络连接: The communication between iSCSI Initiator and Target is TCP/IPrealized through the network. Ethernet is usually used as the transmission medium and a standard IP protocol stack is used for communication.

iSCSI Initiator 驱动程序(iscsid): The iSCSI Initiator driver is a software component that runs on the host operating system and is responsible for passing iSCSI commands and data to the network and processing responses received from the network.

iSCSI Target 软件(target.service,targetcli):iSCSI Target software is a software component running on a remote storage device that accepts and processes iSCSI requests from the initiator and converts them into operations on the local storage device.

存储设备: The storage device can be 磁盘阵列、磁盘存储系统or other storage device that supports SCSI protocol, LVM, etc. iSCSI targets provide storage services through local storage devices.

Deploy and use Demo

Provide iSCSI storage (iSCSI target configuration)

Install and configure iSCSI Target (target)

Prepare the backend block device

[root@serverd ~]# lsblk --fs
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
vda
└─vda1 xfs          f7614c41-2835-4125-bb13-50772dc2f30c /
vdb

Here, an empty disk vdb is used as the back-end storage of ISCSI. According to the command output, there are currently two block devices in the system, namely vda和vdb. in,

  • vda has been formatted as an XFS file system and mounted to the root directory (/).
  • vdb does not show the file system type, label or UUID, which means that the device has not been formatted as a file system.

Install targetcli, which is a command-line tool for managing and configuring iSCSI targets. It can create, configure and manage iSCSI targets for other computers to access over the network.

[root@serverd ~]# yum install targetcli -y >> /dev/null
[root@serverd ~]# rpm -ql targetcli
/etc/target
/etc/target/backup
/usr/bin/targetcli
.....

target.serviceIt is the system service unit (systemd unit) of the iSCSI Target service. It is used to start, stop and manage iSCSI Target so that other computers can access shared storage devices through the network.

Configure auto-start at boot and allow the firewall. Here you need to pay attention to the firewall’s allow services name:iscsi-target

[root@serverd ~]# systemctl enable target.service --now
Created symlink /etc/systemd/system/multi-user.target.wants/target.service → /usr/lib/systemd/system/target.service.
[root@serverd ~]#
[root@serverd ~]# firewall-cmd --permanent  --add-service=iscsi-target
success
[root@serverd ~]# firewall-cmd --reload
success

Start the targetcli command line interface:

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

View the configuration of the iSCSI target:

/> ls
o- / ............................................................................................ [...]
  o- backstores ................................................................................. [...]
  | o- block ..................................................................... [Storage Objects: 0]
  | o- fileio .................................................................... [Storage Objects: 0]
  | o- pscsi ..................................................................... [Storage Objects: 0]
  | o- ramdisk ................................................................... [Storage Objects: 0]
  o- iscsi ............................................................................... [Targets: 0]
  o- loopback ............................................................................ [Targets: 0]

There are no iSCSI backend stores (backstores) created in the current system. Currently, backstores/block、backstores/fileio、backstores/pscsi和backstores/ramdiskthere are no storage objects.

iSCSI supports the following four back-end storage types:

  • block: It allows 块设备use as iSCSI backend storage, such as hard drives or logical volumes.
  • fileio: It allows use 文件as iSCSI backend storage, i.e. providing files as virtual disks to iSCSI clients.
  • pscsi:pscsi stands for "pass-through SCSI" and allows SCSI设备direct exposure to iSCSI clients so that the clients can directly access SCSI commands.
  • ramdisk: It allows RAM磁盘use as iSCSI back-end storage, that is, providing a part of the memory as a virtual disk to the iSCSI client.

Create iSCSI backend storage

Create an iSCSI backend storage (backstore) type of block, enter the backstores/block directory: Create a new block backend storage device:

create <name> <path>
  • <name>: Specifies the name of the backend storage device, which can be any unique string used to identify the device.

  • <path>: Specifies the path to the backend storage device, which can be a block device file (for example /dev/sdb) or an LVM logical volume path (for example /dev/mapper/vg-name-lv-name).

/> cd backstores/block
/backstores/block> create serverd.disk1 /dev/vdb
Created block storage object serverd.disk1 using /dev/vdb.

Check configuration

/backstores/block> ls
o- block ......................................................................... [Storage Objects: 1]
  o- serverd.disk1 ......................................... [/dev/vdb (5.0GiB) write-thru deactivated]
    o- alua .......................................................................... [ALUA Groups: 1]
      o- default_tg_pt_gp .............................................. [ALUA state: Active/optimized]
/backstores/block>

create a newiSCSI目标

Create a unique one for the target IQN. Use name iqn.2014-06.com.example:serverdas the IQN.

/backstores/block> cd /iscsi
/iscsi> ls
o- iscsi ................................................................................. [Targets: 0]
/iscsi> create iqn.2014-06.com.example:serverd
Created target iqn.2014-06.com.example:serverd.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.

View goals

/iscsi> ls
o- iscsi ................................................................................. [Targets: 1]
  o- iqn.2023-08.com.example:serverd ........................................................ [TPGs: 1]
    o- tpg1 .................................................................... [no-gen-acls, no-auth]
      o- acls ............................................................................... [ACLs: 0]
      o- luns ............................................................................... [LUNs: 0]
      o- portals ......................................................................... [Portals: 1]
        o- 0.0.0.0:3260 .......................................................................... [OK]
/iscsi>

Create in iSCSI target 逻辑单元号(LUN):

Create a LUN for the target to be provisioned. Use the serverd.disk1 block block storage created above as backing storage.

/iscsi> cd /iscsi/iqn.2023-08.com.example:serverd/tpg1/luns
/iscsi/iqn.20...erd/tpg1/luns> create /backstores/block/serverd.disk1
Created LUN 0.
/iscsi/iqn.20...erd/tpg1/luns> ls
o- luns ..................................................................................... [LUNs: 1]
  o- lun0 ......................................... [block/serverd.disk1 (/dev/vdb) (default_tg_pt_gp)]
/iscsi/iqn.20...erd/tpg1/luns>

Create an ACL to allow servera.lab.example.cominitiators on to access the target. iqn.2014-06.com.example:serveraThe launcher will connect with its launcher name set to

/iscsi/iqn.20...:serverd/tpg1> cd acls
/iscsi/iqn.20...erd/tpg1/acls> ls
o- acls ..................................................................................... [ACLs: 0]
/iscsi/iqn.20...erd/tpg1/acls> create iqn.2023-08.com.example:servera
Created Node ACL for iqn.2023-08.com.example:servera
Created mapped LUN 0.
/iscsi/iqn.20...erd/tpg1/acls> ls
o- acls ..................................................................................... [ACLs: 1]
  o- iqn.2023-08.com.example:servera ................................................. [Mapped LUNs: 1]
    o- mapped_lun0 .................................................... [lun0 block/serverd.disk1 (rw)]

Delete the default Target Port Group (TPG) and create a Target Port Group (TPG) for 仅侦听主⽹络接⼝the port on 172.25.250.133260

Create a Target Port Group (TPG) that listens on port 3260 on the network interface using the 172.25.250.13 address.

/iscsi/iqn.20...:serverd/tpg1> cd 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 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 172.25.250.13 3260
Using default IP port 3260
Created network portal 172.25.250.13:3260.
/iscsi/iqn.20.../tpg1/portals> ls
o- portals ............................................................................... [Portals: 1]
  o- 172.25.250.13:3260 .......................................................................... [OK]
/iscsi/iqn.20.../tpg1/portals>

List the target configuration to verify. Once completed, exit the targetcli command.

/> ls
o- / ............................................................................................ [...]
  o- backstores ................................................................................. [...]
  | o- block ..................................................................... [Storage Objects: 1]
  | | o- serverd.disk1 ....................................... [/dev/vdb (5.0GiB) write-thru activated]
  | |   o- alua ...................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp .......................................... [ALUA state: Active/optimized]
  | o- fileio .................................................................... [Storage Objects: 0]
  | o- pscsi ..................................................................... [Storage Objects: 0]
  | o- ramdisk ................................................................... [Storage Objects: 0]
  o- iscsi ............................................................................... [Targets: 1]
  | o- iqn.2023-08.com.example:serverd ...................................................... [TPGs: 1]
  |   o- tpg1 .................................................................. [no-gen-acls, no-auth]
  |     o- acls ............................................................................. [ACLs: 1]
  |     | o- iqn.2023-08.com.example:servera ......................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ............................................ [lun0 block/serverd.disk1 (rw)]
  |     o- luns ............................................................................. [LUNs: 1]
  |     | o- lun0 ................................. [block/serverd.disk1 (/dev/vdb) (default_tg_pt_gp)]
  |     o- portals ....................................................................... [Portals: 1]
  |       o- 172.25.250.13:3260 .................................................................. [OK]
  o- loopback ............................................................................ [Targets: 0]
/>

It will be automatically saved when exiting, and the configuration file can be viewed in the default directory.

/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
[root@serverd ~]# cat /etc/target/saveconfig.json
{
    
    
  "fabric_modules": [],
  "storage_objects": [
    {
    
    
      "alua_tpgs": [
        {
    
    
          "alua_access_state": 0,
          "alua_access_status": 0,
          "alua_access_type": 3,
          .....................................

Access iSCSI storage

Confirm existing iSCSI storage targets and service status

[root@serverd ~]# systemctl is-active target.service
active

indeed configuration file

[root@serverd ~]# targetcli
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ............................................................................................ [...]
  o- backstores ................................................................................. [...]
  | o- block ..................................................................... [Storage Objects: 1]
  | | o- serverd.disk1 ....................................... [/dev/vdb (5.0GiB) write-thru activated]
  | |   o- alua ...................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp .......................................... [ALUA state: Active/optimized]
  | o- fileio .................................................................... [Storage Objects: 0]
  | o- pscsi ..................................................................... [Storage Objects: 0]
  | o- ramdisk ................................................................... [Storage Objects: 0]
  o- iscsi ............................................................................... [Targets: 1]
  | o- iqn.2014-06.com.example:serverd ...................................................... [TPGs: 1]
  |   o- tpg1 .................................................................. [no-gen-acls, no-auth]
  |     o- acls ............................................................................. [ACLs: 1]
  |     | o- iqn.2014-06.com.example:servera ......................................... [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ............................................ [lun0 block/serverd.disk1 (rw)]
  |     o- luns ............................................................................. [LUNs: 1]
  |     | o- lun0 ................................. [block/serverd.disk1 (/dev/vdb) (default_tg_pt_gp)]
  |     o- portals ....................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ........................................................................ [OK]
  o- loopback ............................................................................ [Targets: 0]
/>

Client preparation

iscsi-initiator-utilsProvides iSCSI client tools and services for managing and configuring iSCSI connections. It contains iscsiadmcommand line tools and other iSCSIrelated components.

Key features and components include:

  • iscsiadmCommand line tools: iscsi-initiator-utils contains the iscsiadm command line tool for managing and configuring iSCSI connections. You can use this tool to discover iSCSI targets, establish sessions, disconnect, manage target lists, and more.
  • iSCSIServices: iscsi-initiator-utils contains the iSCSI service (usually the iscsid daemon), which runs in the background and handles communication with iSCSI storage targets. This service is responsible for managing iSCSI sessions and devices, and providing an interactive interface with iSCSI targets.
  • iSCSIConfiguration files: iscsi-initiator-utilsConfiguration files are provided for configuring iSCSI clients. These configuration files contain iSCSI target information, authentication settings, session options, and more. You can edit these configuration files to customize the behavior of iSCSI connections.

To install the toolkit, do you really need to configure whether iscsidthe service is enabled and whether it is started?

[root@servera ~]# yum search iscsi
[root@servera ~]# yum -y install iscsi-initiator-utils >> /dev/null
[root@servera ~]#
[root@servera ~]# systemctl restart iscsid

Use the discovery subcommand of the iscsiadm command to discover the iSCSI target at the specified IP address (172.25.250.13).

[root@servera ~]# iscsiadm  -m discovery  -t st -p 172.25.250.13
172.25.250.13:3260,1 iqn.2014-06.com.example:serverd

The corresponding naming can be obtained through the help documentation.man iscsiadm

EXAMPLES
       Discover targets at a given IP address:

              iscsiadm --mode discoverydb --type sendtargets --portal 192.168.1.10 --discover

       Login, must use a node record id found by the discovery:

              iscsiadm  --mode  node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260
              --login

       Logout:

              iscsiadm --mode node --targetname iqn.2001-05.com.doe:test  --portal  192.168.1.1:3260
              --logout

       List node records:

              iscsiadm --mode node

       Display all data for a given node record:

              iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260

FILES
       /etc/iscsi/iscsid.conf
              The configuration file read by iscsid and iscsiadm on startup.

       /etc/iscsi/initiatorname.iscsi
              The file containing the iSCSI InitiatorName and InitiatorAlias read by iscsid and isc‐
              siadm on startup.

       /var/lib/iscsi/nodes/
              This directory contains the nodes with their targets.

       /var/lib/iscsi/send_targets
              This directory contains the portals.

Log in to iSCSI target

You used the iscsiadm command to perform iSCSI target discovery, obtain the IQN, change the system's iSCSIhostname, and restart iSCSIthe service for the changes to take effect

[root@servera ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:652a957da83c
[root@servera ~]# iscsiadm  -m discovery  -t st -p 172.25.250.13
172.25.250.13:3260,1 iqn.2014-06.com.example:serverd
[root@servera ~]# echo 'InitiatorName=iqn.2014-06.com.example:servera' >  /etc/iscsi/initiatorname.iscsi
[root@servera ~]#  systemctl restart iscsid

Log in to the iSCSI target

[root@servera ~]# iscsiadm -m node -T iqn.2014-06.com.example:serverd  -p 172.25.250.13 -l
Logging in to [iface: default, target: iqn.2014-06.com.example:serverd, portal: 172.25.250.13,3260]
Login to [iface: default, target: iqn.2014-06.com.example:serverd, portal: 172.25.250.13,3260] successful.
[root@servera ~]#

To determine the new available block device, use the session subcommand of the iscsiadm command to obtain detailed information about the current iSCSI session, and specify an output level of 3 through the -P 3 parameter.

[root@servera ~]# iscsiadm  -m session -P 3
iSCSI Transport Class version 2.0-870
version 6.2.0.877-0
Target: iqn.2014-06.com.example:serverd (non-flash)
        Current Portal: 172.25.250.13:3260,1
        Persistent Portal: 172.25.250.13:3260,1
                **********
                Interface:
                **********
                Iface Name: default
                Iface Transport: tcp
                Iface Initiatorname: iqn.2014-06.com.example:servera
                Iface IPaddress: 172.25.250.10
                Iface HWaddress: default
                Iface Netdev: default
                SID: 8
                iSCSI Connection State: LOGGED IN
                iSCSI Session State: LOGGED_IN
                Internal iscsid Session State: NO CHANGE
                *********
                Timeouts:
                *********
                Recovery Timeout: 120
                Target Reset Timeout: 30
                LUN Reset Timeout: 30
                Abort Timeout: 15
                *****
                CHAP:
                *****
                username: <empty>
                password: ********
                username_in: <empty>
                password_in: ********
                ************************
                Negotiated iSCSI params:
                ************************
                HeaderDigest: None
                DataDigest: None
                MaxRecvDataSegmentLength: 262144
                MaxXmitDataSegmentLength: 262144
                FirstBurstLength: 65536
                MaxBurstLength: 262144
                ImmediateData: Yes
                InitialR2T: Yes
                MaxOutstandingR2T: 1
                ************************
                Attached SCSI devices:
                ************************
                Host Number: 6  State: running
                scsi6 Channel 00 Id 0 Lun: 0
                        Attached scsi disk sda          State: running

Based on the output information provided, you can see that the iSCSI login to the target is successful and a connection is established with the target. Here are some key messages:

  • Target name (Target): iqn.2014-06.com.example:serverd
  • Currently used port (Portal): 172.25.250.13:3260
  • Network interface used: default
  • Initiatorname: iqn.2014-06.com.example:servera
  • Initiator IP address (Iface IPaddress): 172.25.250.10
  • iSCSI Connection State: LOGGED IN
  • iSCSI Session State: Logged in (LOGGED_IN)
  • CHAP settings: You provided an empty username and password
  • Negotiated iSCSI params: Displays the negotiated iSCSI parameters, such as data segment length, burst length, etc.
  • Connected SCSI device: 一个 SCSI 设备 sda 已附加到主机号为 6 的通道 00,ID 0,逻辑单元号 0.

Based on the information provided, it appears that the iSCSI connection was established successfully and the SCSI device was attached to the host. You can perform related operations on the host, such as mounting disks, accessing file systems, etc.

Use the lsblk command with the --fs option to list partitions and file systems on a block device.

[root@servera ~]# iscsiadm  -m session -P 3 | grep disk
                        Attached scsi disk sda          State: running
[root@servera ~]# lsblk --fs
NAME   FSTYPE LABEL UUID                                 MOUNTPOINT
sda
vda
└─vda1 xfs          f7614c41-2835-4125-bb13-50772dc2f30c /
vdb
[root@servera ~]#

Use mkfs.xfsthe command to xfsapply the file system to/dev/sda

[root@servera ~]# mkfs.xfs /dev/sda
meta-data=/dev/sda               isize=512    agcount=4, agsize=327680 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=1, sparse=1, rmapbt=0
         =                       reflink=1
data     =                       bsize=4096   blocks=1310720, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0, ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Edit /etc/fstabthe file and add a line for the new file system. Remember to specify _netdevoptions. Mount the shared above /dev/sdato /datathe directory

[root@servera ~]# mkdir /data
[root@servera ~]# lsblk --fs /dev/sda
NAME FSTYPE LABEL UUID                                 MOUNTPOINT
sda  xfs          e088a91d-ceb7-40de-9536-e990fa7f4f44
[root@servera ~]# echo 'UUID=e088a91d-ceb7-40de-9536-e990fa7f4f44  /data  xfs _netdev 0 0' >> /etc/fstab
[root@servera ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Oct 29 16:26:01 2019
#
# Accessible filesystems, by reference, are maintained under '/dev/disk/'.
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=f7614c41-2835-4125-bb13-50772dc2f30c /                       xfs     defaults        0 0
UUID=e088a91d-ceb7-40de-9536-e990fa7f4f44  /data  xfs _netdev 0 0
[root@servera ~]# mount /data
[root@servera ~]# mount -a

Check the mounting status

[root@servera ~]# df /data/
Filesystem     1K-blocks  Used Available Use% Mounted on
/dev/sda         5232640 69616   5163024   2% /data
[root@servera ~]#

Unmount the file system, iSCSIlog off from the target, and delete all records for the target

[root@servera ~]# umount /data
[root@servera ~]# sed -i '$d' /etc/fstab
[root@servera ~]# iscsiadm  -m node -T iqn.2014-06.com.example:serverd  -p 172.25.250.13 -u
Logging out of session [sid: 8, target: iqn.2014-06.com.example:serverd, portal: 172.25.250.13,3260]
Logout of [sid: 8, target: iqn.2014-06.com.example:serverd, portal: 172.25.250.13,3260] successful.
[root@servera ~]# iscsiadm  -m node -T iqn.2014-06.com.example:serverd -p 172.25.250.13 -o delete
[root@servera ~]#

Reference to part of the blog post

© The copyright of the reference links in this article belongs to the original author. If there is any infringement, please inform us :)


红帽服务管理与自动化(RH358)Lecture Notes


© 2018-2023 [email protected] , All rights reserved. Keep Attribution-NonCommercial-ShareAlike (CC BY-NC-SA 4.0)

Guess you like

Origin blog.csdn.net/sanhewuyang/article/details/132804338