GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come configurare iSCSI Storage Server su Ubuntu 18.04 LTS

iSCSI sta per (Internet Small Computer System Interface) è un protocollo SAN (Storage Area Network) che può essere utilizzato per la gestione dell'archiviazione online. È uno standard di rete di archiviazione basato su IP che fornisce accesso a livello di blocco ai dispositivi di archiviazione trasportando comandi SCSI su una rete TCP/IP.

iSCSI è costituito da due componenti target iSCSI e iniziatore iSCSI. iSCSI target è un servizio sul server iSCSI che offre accesso allo storage condiviso e iSCSI initiator è un client iSCSI che si connette al target e accede allo storage condiviso.

In questo tutorial, ti mostreremo come configurare la destinazione iSCSI e l'iniziatore iSCSI sul server Ubuntu 18.04.

Requisiti

  • Un nuovo server Ubuntu 18.04 per target iSCSI con 2 GB di HDD esterno.
  • Un nuovo server Ubuntu 18.04 per iniziatore iSCSI.
  • Un indirizzo IP statico 192.168.0.103 è configurato sulla destinazione iSCSI e 192.168.0.102 è configurato sull'iniziatore iSCSI.
  • Una password di root è configurata su entrambi i server.

Per iniziare

Prima di iniziare, dovrai aggiornare entrambi i server con l'ultima versione. Puoi aggiornarli eseguendo il seguente comando su entrambi $

apt-get update -y
apt-get upgrade -y

Dopo aver aggiornato entrambi i server, riavviali per applicare le modifiche.

Installa iSCSI Target

Innanzitutto, dovrai installare il pacchetto Target Framework (TGT) sul server di destinazione iSCSI. Puoi installarlo con il seguente comando:

apt-get install tgt -y

Una volta installato TGT, controlla lo stato di TGT eseguendo il comando seguente:

systemctl status tgt

Dovresti vedere il seguente output:

? tgt.service - (i)SCSI target daemon
   Loaded: loaded (/lib/systemd/system/tgt.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2019-11-08 07:40:28 UTC; 27s ago
     Docs: man:tgtd(8)
 Main PID: 2343 (tgtd)
   Status: "Starting event loop..."
    Tasks: 1
   CGroup: /system.slice/tgt.service
           ??2343 /usr/sbin/tgtd -f

Nov 08 07:40:28 ubuntu systemd[1]: Starting (i)SCSI target daemon...
Nov 08 07:40:28 ubuntu tgtd[2343]: tgtd: iser_ib_init(3431) Failed to initialize RDMA; load kernel modules?
Nov 08 07:40:28 ubuntu tgtd[2343]: tgtd: work_timer_start(146) use timer_fd based scheduler
Nov 08 07:40:28 ubuntu tgtd[2343]: tgtd: bs_init(387) use signalfd notification
Nov 08 07:40:28 ubuntu systemd[1]: Started (i)SCSI target daemon.

Una volta terminato, puoi procedere al passaggio successivo.

Configura destinazione iSCSI

Successivamente, dovrai creare un dispositivo LUN (Logical Unit Number) sul tuo server iSCSI. LUN è un dispositivo di archiviazione back-end a cui l'iniziatore si collegherà e utilizzerà in seguito.

Puoi farlo creando il file di configurazione all'interno della directory /etc/tgt/conf.d:

nano /etc/tgt/conf.d/iscsi.conf

Aggiungi le seguenti righe:

<target iqn.2019-11.example.com:lun1>
     # Provided device as an iSCSI target
     backing-store /dev/sdb1                             
     initiator-address 192.168.0.102 
    incominguser iscsi-user password
     outgoinguser iscsi-target secretpass
</target>

Salva e chiudi il file quando hai finito. Quindi, riavvia il servizio TGT per applicare le modifiche alla configurazione:

systemctl restart tgt

Ecco una breve spiegazione di ogni parametro:

obiettivo :Questo è il nome della destinazione particolare.

negozio di supporto :questa opzione specifica il disco di archiviazione che verrà utilizzato dall'iniziatore.

indirizzo-iniziatore :Questo è l'indirizzo IP dell'iniziatore.

utente in arrivo :questo è il nome utente/password in entrata per proteggere il LUN.

utente in uscita :questo è il nome utente/password in uscita per l'autenticazione CHAP reciproca.

Dopo aver riavviato il servizio TGT, controllare il server di destinazione iSCSI con il seguente comando:

tgtadm --mode target --op show

Dovresti vedere che la destinazione iSCSI è stata resa disponibile:

Target 1: iqn.2019-11.example.com:lun1
    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: 2146 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: /dev/sdb1
            Backing store flags: 
    Account information:
        iscsi-user
        iscsi-target (outgoing)
    ACL information:
        192.168.0.102

Installa e configura iSCSI Initiator

Successivamente, sarà necessario installare il pacchetto dell'iniziatore iSCSI sul server dell'iniziatore iSCSI. Puoi installarlo con il seguente comando:

apt-get install open-iscsi -y

Una volta completata l'installazione, esegui il rilevamento della destinazione sul nostro server di destinazione iSCSI per scoprire le destinazioni condivise.

iscsiadm -m discovery -t st -p 192.168.0.103

Dovresti vedere la destinazione disponibile nel seguente output:

192.168.0.103:3260,1 iqn.2019-11.example.com:lun1

Il comando precedente genera anche due file con informazioni LUN. Puoi vederli con il seguente comando:

ls -l /etc/iscsi/nodes/iqn.2019-11.example.com\:lun1/192.168.0.103\,3260\,1/ /etc/iscsi/send_targets/192.168.0.103,3260/

Dovresti vedere i seguenti file:

/etc/iscsi/nodes/iqn.2019-11.example.com:lun1/192.168.0.103,3260,1/:
total 4
-rw------- 1 root root 1840 Nov  8 13:17 default

/etc/iscsi/send_targets/192.168.0.103,3260/:
total 8
lrwxrwxrwx 1 root root  66 Nov  8 13:17 iqn.2019-11.example.com:lun1,192.168.0.103,3260,1,default -> /etc/iscsi/nodes/iqn.2019-11.example.com:lun1/192.168.0.103,3260,1
-rw------- 1 root root 547 Nov  8 13:17 st_config

Successivamente, dovrai modificare il file predefinito e definire le informazioni CHAP che hai configurato sulla destinazione iSCSI per accedere alla destinazione iSCSI dall'iniziatore iSCSI.

nano /etc/iscsi/nodes/iqn.2019-11.example.com\:lun1/192.168.0.103\,3260\,1/default

Aggiungi / Modifica le seguenti righe:

node.session.auth.authmethod = CHAP  
node.session.auth.username = iscsi-user
node.session.auth.password = password          
node.session.auth.username_in = iscsi-target
node.session.auth.password_in = secretpass         
node.startup = automatic

Salva e chiudi il file quando hai finito. Quindi, riavvia il servizio iniziatore iSCSI per applicare le modifiche alla configurazione:

systemctl restart open-iscsi

Dovresti vedere il seguente output:

 * Unmounting iscsi-backed filesystems                                                                                                  [ OK ] 
 * Disconnecting iSCSI targets                                                                                                                 iscsiadm: No matching sessions found
                                                                                                                                        [ OK ]
 * Stopping iSCSI initiator service                                                                                                     [ OK ] 
 * Starting iSCSI initiator service iscsid                                                                                              [ OK ] 
 * Setting up iSCSI targets                                                                                                                    
Logging in to [iface: default, target: iqn.2019-11.example.com:lun1, portal: 192.168.0.103,3260] (multiple)
Login to [iface: default, target: iqn.2019-11.example.com:lun1, portal: 192.168.0.103,3260] successful.
                                                                                                                                        [ OK ]
 * Mounting network filesystems                                                                                                         [ OK ] 

È ora possibile controllare il disco di archiviazione condiviso dalla destinazione iSCSI con il seguente comando:

lsblk

Dovresti vedere che il disco di archiviazione è ora disponibile per l'iniziatore come sdb:

NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 465.8G  0 disk 
??sda1   8:1    0  93.1G  0 part /
??sda2   8:2    0     1K  0 part 
??sda5   8:5    0 186.3G  0 part /home
??sda6   8:6    0 181.6G  0 part /Data
??sda7   8:7    0   4.8G  0 part [SWAP]
sdb      8:16   0     2G  0 disk 

Puoi anche verificare le connessioni iSCSI con il seguente comando:

tgtadm --mode conn --op show --tid 1

Dovresti ottenere il seguente output:

Session: 1
    Connection: 0
        Initiator: iqn.1993-08.org.debian:01:2e1e2383de41
        IP Address: 192.168.0.102

Successivamente, dovrai creare un filesystem su questo dispositivo condiviso (sdb) e montarlo per rendere utilizzabile questo dispositivo.

Innanzitutto, crea un filesystem sul dispositivo condiviso (sdb) con il seguente comando:

fdisk /dev/sdb

Dovresti vedere il seguente output:

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x06091fe8.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1):
First sector (2048-4194303, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-4194303, default 4194303):

Created a new partition 1 of type 'Linux' and of size 2 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Quindi, formatta questa partizione con il seguente comando:

mkfs.ext4 /dev/sdb1

Quindi, monta questa partizione nella directory /mnt con il seguente comando:

mount /dev/sdb1 /mnt

Ora puoi controllare il dispositivo montato con il seguente comando:

df -h

Dovresti vedere il seguente output:

Filesystem      Size  Used Avail Use% Mounted on
udev            1.9G  4.0K  1.9G   1% /dev
tmpfs           384M  1.2M  383M   1% /run
/dev/sda1        92G   36G   51G  42% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none            5.0M     0  5.0M   0% /run/lock
none            1.9G   54M  1.9G   3% /run/shm
none            100M   48K  100M   1% /run/user
/dev/sda5       184G   96G   79G  55% /home
/dev/sda6       179G   32G  138G  19% /Data
/dev/sdb1       2.0G  3.0M  1.9G   1% /mnt

Congratulazioni! è stato installato correttamente il server di destinazione iSCSI e lo si è connesso dall'iniziatore iSCSI. Ora puoi utilizzare questo dispositivo iSCSI condiviso come un normale disco collegato.


Ubuntu
  1. Come configurare server e client Kerberos su Ubuntu 18.04 LTS

  2. Come configurare il server Rsyslog su Ubuntu 18.04 LTS

  3. Come configurare un server di archiviazione iSCSI su Ubuntu 20.04 LTS

  4. Come configurare Elasticsearch su Ubuntu 18.04 e 16.04 LTS

  5. Imposta il server Rsyslog su Ubuntu 20.04 - Come farlo?

Come configurare Git Server su Ubuntu 20.04

Come configurare il server Rsyslog su Ubuntu

Come configurare il server DHCP su Ubuntu

Come eseguire l'aggiornamento a Ubuntu Server 22.04 LTS

Come installare Jellyfin Media Server su Ubuntu 20.04 LTS Server/Desktop

Come configurare server e client NTP su Ubuntu 20.04 LTS