ISCSI. AlmaLinux 8. ISCSI-Initiator

Материал из Wiki
Перейти к навигации Перейти к поиску

Links

https://computingforgeeks.com/how-to-configure-iscsi-initiator-on-centos-rhel/

Configuring

Connect to target and mount a device

Install

dnf -y install iscsi-initiator-utils

Initiator name (IMPORTANT! like a unique hostname of this host for iscsi environment)

nano /etc/iscsi/initiatorname.iscsi

    InitiatorName=iqn.2023-01.alef:al8-test01

Automatic connect to each server with iscsi-target

Use it when you have several servers with iscsi-target

iscsiadm -m discovery -t st -p 192.168.199.187

    ...
    192.168.199.187:3260,1 iqn.2023-03.nas-test:esxi-v1
    192.168.199.187:3260,1 iqn.2023-03.nas-test:pve-v1
    192.168.199.187:3260,1 iqn.2023-03.nas-test:vmail
    ...

iscsiadm -m node --targetname "iqn.2023-03.nas-test:pve-v1" --portal "192.168.199.187:3260" --op=update --name node.session.auth.authmethod --value=CHAP

iscsiadm -m node --targetname "iqn.2023-03.nas-test:pve-v1" --portal "192.168.199.187:3260" --op=update --name node.session.auth.chap_algs --value=SHA3-256,SHA256,SHA1,MD5

iscsiadm -m node --targetname "iqn.2023-03.nas-test:pve-v1" --portal "192.168.199.187:3260" --op=update --name node.session.auth.username --value=pve

iscsiadm -m node --targetname "iqn.2023-03.nas-test:pve-v1" --portal "192.168.199.187:3260" --op=update --name node.session.auth.password --value=PassWord#1

iscsiadm -m node --targetname "iqn.2023-03.nas-test:pve-v1" --portal "192.168.199.187:3260" --op=update --name node.startup --value=automatic

iscsiadm -m node --targetname "iqn.2023-03.nas-test:pve-v1" --portal "192.168.199.187:3260" --login

Now you can see above settings in the separated config file for each target:

/etc/iscsi/nodes/iqn.2023-03.nas-test\:pve-v1/192.168.199.187\,3260\,1/default

This settings will remain after reboot.

reboot

Check if iscsi disk is UP. Show connected block device.

lsblk

    ...
    sdb                       8:16   0  100G  0 disk
    ...

Automatic connect to ONE server with iscsi-target

Use it when you have only ONE server with iscsi-target

Login and password for target (CHAP only)    

nano /etc/iscsi/iscsid.conf

...
node.session.auth.username = vmail
node.session.auth.password = PassWord
...

Discovery target (target discovery auth disabled)

iscsiadm -m discovery -t sendtargets -p 192.168.199.250

    ...
    192.168.199.250:3260,1 iqn.2023-01.alef:vmail
    ...

Target info

iscsiadm -m node -o show

Login to ALL targets

iscsiadm -m node --login

    ...
    Logging in to [iface: default, target: iqn.2023-01.alef:vmail, portal: 192.168.199.250,3260]
    Login to [iface: default, target: iqn.2023-01.alef:vmail, portal: 192.168.199.250,3260] successful.
    ...

Login to specific targets

iscsiadm -m node --login --targetname iqn.2023-01.alef:vmail.zfs -p 192.168.199.250,3260    

Show connected session info

iscsiadm -m session -o show

    ...
    tcp: [6] 192.168.199.250:3260,1 iqn.2023-01.alef:vmail (non-flash)
    ...

Show connected block device

lsblk

    ...
    sdb                       8:16   0  100G  0 disk
    ...

Create and mount partition

Create partition

fdisk /dev/sdb

    n - Next - Next...

Create FS

mkfs.ext4 /dev/sdb1

Getting partition UUID

blkid

    ...
    /dev/sdb1: UUID="d13097d0-1b54-47b0-b504-ffc56d9bceff" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="797c5bc8-01"
    ...

Auto mount after OS boot

mkdir /var/vmail

nano /etc/fstab

...
# iscsi vmail
UUID="d13097d0-1b54-47b0-b504-ffc56d9bceff" /var/vmail ext4 _netdev 0 0
...

reboot

df -h

    ...
    /dev/sdb1                         98G  4.1G   89G   5% /var/vmail
    ...

Unmount and disconnect a target

Unmount device

umount /var/vmail

Logout target

iscsiadm --mode node --targetname iqn.2023-01.alef:vmail --portal 192.168.199.250 -u

   ...
   Logging out of session [sid: 1, target: iqn.2023-01.alef:vmail, portal: 192.168.199.250,3260]
   Logout of [sid: 1, target: iqn.2023-01.alef:vmail, portal: 192.168.199.250,3260] successful.
   ...

Delete connection

iscsiadm --mode node --targetname iqn.2023-01.alef:vmail --portal 192.168.199.250 -o delete

Increase a size of the an extent (block device)

Server ISCSI-target

Increase size of the extent

For example, on Nas4free you just have to type bigger size of the file-extent instead of old size of the file-extent in the web-interface and restart ISCSI-target service

Client ISCSI-initiator

Unmount device (don't logout from target, otherwise you wil not be able to work with sdb - it will disappear)

umount /dev/sdb1

Run parted util

parted

Select device

> select /dev/sdb

Get device full size (it will be bigger than actual size)

> print

    ...
    Disk /dev/sdb: 129GB
    ...

Increaze size to full disk size

> resizepart 1 129GB

Exit

> quit

Increase FS size

resize2fs /dev/sdb1

Mount device

mount /dev/sdb1

Check new size

df -h

    ...
    /dev/sdb1                        118G  4.1G  108G   4% /var/vmail
    ...

Success!