DOCS/UNIX/RHEL/ISCSI/Config iSCSI Initiator

De MonPtitSite
Sauter à la navigation Sauter à la recherche
Accueil SysAdmin Hobbies                  
QEMU - Configure iSCSI Initiator on CentOS 9

Sites Références

Cet article est une transposition sous MediaWiki de ces 2 adresses :

iSCSI is an acronym that stands for Internet Small Computer Systems Interface. It is a Storage Area Network (SAN) Protocol that enables block-level SCSI data transport from Storage arrays to client computers that are not directly connected to them. iSCSI SAN consists of iSCSI Initiators which are the clients and iSCSI targets which are the servers on Storage Array controllers. They are connected by an iSCSI protocol and represented by a unique string known as iSCSI Qualified Name (iQN).

In iSCSI technology, the iSCSI initiator or commonly known as the iSCSI client needs to be installed on your system. It is then added to an initiator group or what is also known as the Client definition. These groups help identify which clients are allowed to connect with the storage server (the iSCSI targets). Logical Unit Numbers (LUNs) are created and assigned to a group or client definition. LUNs are representations of devices that are part of the physical iSCSI target. If the Client and server are on the same IP network, The initiator can automatically discover the target. Once connected, the LUN is available for use.

iSCSI Initiator

Setup pre-reqs

An IP of the Target needs to be known. I will use the iSCSI target from the Configure iSCSI target guide. You can also follow the steps in that guide to create a target.

Configure iSCSI Initiator on CentOS 9|AlmaLinux 9|RHEL 9 systems

- Update your system packages.

sudo yum update -y

or

sudo dnf update -y

- Install iSCSI initiator utilities with the following command.

sudo dnf -y install iscsi-initiator-utils

- Check the initiator name using the following command

$ cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.1994-05.com.redhat:4e8ff68af729

If you changed the name while setting up iSCSI target ACLs. You will have to configure the initiator file to the new name.

sudo vi /etc/iscsi/initiatorname.iscsi

- Change the initiator’s name to match the one set on the target server.

InitiatorName=iqn.1994-05.com.redhat:4e8ff68af729

- Save and exit the file. - [OPTIONAL] Edit the iSCSI configuration file to add the authentication details.

sudo vi /etc/iscsi/iscsid.conf

- Uncomment the following lines and edit as shown.

node.session.auth.authmethod = CHAP
node.session.auth.username = technix
node.session.auth.password = technix_passwd

- Save and exit the file, then start the iSCSI daemon.

sudo systemctl start iscsid.service
sudo systemctl enable iscsid.service

- Discover the target by using the target’s IP address as shown below. The response will be the target’s IP address and iQN address.

$ sudo iscsiadm -m discovery -t st -p 192.168.200.40
192.168.200.40:3260,1 iqn.2022-06.com.redhat:technixleo

- Confirm its status after discovery.

$ sudo iscsiadm -m node -o show

##Sample Outpout ##
# BEGIN RECORD 2.1.4
node.name = iqn.2022-06.com.redhat:technixleo
node.tpgt = 1
node.startup = automatic
node.leading_login = No
iface.iscsi_ifacename = default
.....
.....

- You can log in to the server using the iQN

$ sudo iscsiadm -m node -T iqn.2022-06.com.redhat:technixleo -l
Logging in to [iface: default, target: iqn.2022-06.com.redhat:technixleo, portal: 192.168.200.40,3260]
Login to [iface: default, target: iqn.2022-06.com.redhat:technixleo, portal: 192.168.200.40,3260] successful.

- Confirm the established session.

$ sudo iscsiadm -m session -o show
tcp: [2] 192.168.200.40:3260,1 iqn.2022-06.com.redhat:technixleo (non-flash)

- Confirm the partitions with the following command.

$ cat /proc/partitions

major minor  #blocks  name

   8        0   33554432 sda
   8        1    1048576 sda1
   8        2   32504832 sda2
  11        0    8519680 sr0
 253        0   29143040 dm-0
 253        1    3358720 dm-1
   8       16    5242880 sdb
   8       32   33554432 sdc

The new partition ‘sdb‘ of size 5GB has been added from the target server. To find the iSCSI disk name you can also use the following command.

$ sudo grep "Attached SCSI" /var/log/messages
Jul 30 10:30:02 cent9 kernel: sd 3:0:0:0: [sdb] Attached SCSI disk

Next, we are going to create a file on that disk.

$ sudo mkfs.ext4 /dev/sdb
Creating filesystem with 1310720 4k blocks and 327680 inodes
Filesystem UUID: b0acbfbc-106d-41aa-9446-b26182841ac8
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736

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

Mount the file system. This is done by first creating a directory to mount the file and then mounting the file.

sudo mkdir /mnt/iscsi
sudo mount /dev/sdb /mnt/iscsi

- Verify the file system has been mounted:

$ df -hT
Filesystem          Type      Size  Used Avail Use% Mounted on
devtmpfs            devtmpfs  4.0M     0  4.0M   0% /dev
tmpfs               tmpfs     3.8G     0  3.8G   0% /dev/shm
tmpfs               tmpfs     1.6G  9.2M  1.5G   1% /run
/dev/mapper/cs-root xfs        28G  4.6G   24G  17% /
/dev/sda1           xfs      1014M  466M  549M  46% /boot
tmpfs               tmpfs     769M   96K  768M   1% /run/user/1000
/dev/sr0            iso9660   8.2G  8.2G     0 100% /run/media/technixleo/CentOS-Stream-9-BaseOS-x86_64
/dev/sdb            ext4      4.9G   24K  4.6G   1% /mnt/iscsi

Automount ISCSI storage

To make the file persistent even on boot, edit the fstab file. But first Identify the UUID of the ISCSI disk.

$ sudo blkid /dev/sdb
/dev/sdb: UUID="b0acbfbc-106d-41aa-9446-b26182841ac8" BLOCK_SIZE="4096" TYPE="ext4"

- Open the fstab file and add the UUID of the ISCSI disk.

$ sudo vi /etc/fstab
UUID=b0acbfbc-106d-41aa-9446-b26182841ac8 /mnt/iscsi      ext4         _netdev                      0 0

- Save and exit the file.

You can verify the disk has been mounted.

$ mount
....
/dev/sdb on /mnt/iscsi type ext4 (rw,relatime,seclabel,stripe=2048)

To unmount a disk

sudo umount /mnt/iscsi

To log out of a session, use the following command.

$ sudo iscsiadm -m node -T  iqn.2022-06.com.redhat:technixleo -u
Logging out of session [sid: 1, target: iqn.2022-06.com.redhat:technixleo, portal: 192.168.200.40,3260]
Logout of [sid: 1, target: iqn.2022-06.com.redhat:technixleo, portal: 192.168.200.40,3260] successful.