Ubuntu 20.04 LTSでiSCSIストレージサーバーをセットアップする方法

Ubuntu/Debian ハードウェア

目次

iSCSIは、Internet Small Computer System Interfaceの略です。ネットワーク上のHDD / SSDパーティション、LVMパーティション、ブロックファイルなどのブロックデバイスを共有するために使用できるストレージエリアネットワークプロトコルです。 iSCSIはクライアント/サーバーモデルで動作し、TCP / IPネットワークに依存して、イニシエータークライアントとターゲット間でSCSIコマンドを送信します。 iSCSIターゲットは、iSCSIサーバー上のサービスで、共有ストレージへのアクセスを提供します。iSCSIイニシエーターは、ターゲットに接続して共有ストレージにアクセスするiSCSIクライアントです。

このチュートリアルでは、Ubuntu 20.04サーバーでiSCSIターゲットとiSCSIイニシエーターをセットアップする方法を説明します。

必要条件

  • 1 GBの外部HDDを備えたiSCSIターゲット用のUbuntu 20.04を実行するシステム。
  • iSCSIイニシエーター用の新しいUbuntu 20.04を実行しているシステム。
  • 静的IPアドレス192.168.1.10はiSCSIターゲットで構成され、192.168.1.20はiSCSIイニシエーターで構成されます。
  • 両方のサーバーでrootパスワードが構成されています。

システムを更新する

開始する前に、システムを最新のパッケージで更新することをお勧めします。次のコマンドで更新できます。

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

すべてのパッケージが更新されたら、システムを再起動して変更を適用します。

iSCSIターゲットをインストールする

デフォルトでは、iSCSIターゲットパッケージはUbuntu 20.04のデフォルトリポジトリで利用できます。 iSCSIターゲットサーバーで次のコマンドを実行してインストールできます。

apt-get install tgt -y

iSCSIターゲットをインストールした後、次のコマンドでサーバーのステータスを確認します。

systemctl status tgt

次の出力が表示されます。

? tgt.service - (i)SCSI target daemon
     Loaded: loaded (/lib/systemd/system/tgt.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2020-07-11 07:13:04 UTC; 23s ago
       Docs: man:tgtd(8)
   Main PID: 7770 (tgtd)
     Status: "Starting event loop..."
      Tasks: 1
     Memory: 1.1M
     CGroup: /system.slice/tgt.service
             ??7770 /usr/sbin/tgtd -f

Jul 11 07:13:04 ubuntu2004 systemd[1]: Starting (i)SCSI target daemon...
Jul 11 07:13:04 ubuntu2004 tgtd[7770]: tgtd: iser_ib_init(3431) Failed to initialize RDMA; load kernel modules?
Jul 11 07:13:04 ubuntu2004 tgtd[7770]: tgtd: work_timer_start(146) use timer_fd based scheduler
Jul 11 07:13:04 ubuntu2004 tgtd[7770]: tgtd: bs_init(387) use signalfd notification
Jul 11 07:13:04 ubuntu2004 systemd[1]: Started (i)SCSI target daemon.

この時点で、iSCSIターゲットがサーバーにインストールされているので、次のステップに進むことができます。

iSCSIターゲットの構成

まず、iSCSIサーバーにLUN(論理ユニット番号)デバイスを作成する必要があります。 LUNは、物理SCSIデバイスの一部であるバックエンドストレージデバイスです。 iSCSIターゲットにマッピングされたすべてのLUNは、クライアントのオペレーティングシステムに仮想的に接続されます。したがって、イニシエーターはiSCSI LUN上でファイルシステムを確立および管理できます。

新しい設定ファイルを作成することで設定できます:

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

次の行を追加します。

<target iqn.2020-07.example.com:lun1>
     backing-store /dev/sdb
     initiator-address 192.168.1.20
    incominguser iscsi-user password
     outgoinguser iscsi-target secretpass
</target>

終了したら、ファイルを保存して閉じます。

どこ:

  • 最初の行は、LUNの名前を定義します。
  • 2行目は、iSCSIターゲットサーバー上のストレージデバイスの場所と名前を定義します。
  • 3行目は、iSCSIイニシエーターのIPアドレスを定義します。
  • 4行目は、着信するユーザー名/パスワードを定義します。
  • 5行目は、ターゲットがイニシエーターに提供するユーザー名/パスワードを定義して、相互CHAP認証を実行できるようにします。

次に、iSCSIサービスを再起動して変更を適用します。

systemctl restart tgt

次に、次のコマンドでiSCSIターゲットサーバーを確認します。

tgtadm --mode target --op show

次の出力が表示されます。

Target 1: iqn.2020-07.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: 
    Account information:
        iscsi-user
        iscsi-target (outgoing)
    ACL information:
        192.168.1.10

この時点で、iSCSIターゲットサーバーがインストールされ、構成されています。これで、次のステップに進むことができます。

iSCSIイニシエーターのインストールと構成

次に、iSCSIイニシエーターマシンに移動し、次のコマンドでiSCSIイニシエーターパッケージをインストールします。

apt-get install open-iscsi -y

インストールが完了したら、次のコマンドを使用して、iSCSIターゲットサーバーを検出し、共有ターゲットを見つけます。

iscsiadm -m discovery -t st -p 192.168.1.10

次の出力が表示されます。

192.168.1.10:3260,1 iqn.2020-07.example.com:lun1

次に、initiatorname.iscsiファイルでLUNデバイスの名前を定義する必要があります。

nano /etc/iscsi/initiatorname.iscsi

次に示すように、iSCSIターゲットLUN名を追加します。

InitiatorName=iqn.2020-07.example.com:lun1

終了したら、ファイルを保存して閉じます。

次に、iSCSIイニシエーターからiSCSIターゲットにアクセスするために、iSCSIターゲットで構成したCHAP情報を定義する必要があります。ノード構成ファイルは「/ etc / iscsi / nodes /」ディレクトリに存在し、使用可能なLUNごとのディレクトリを持ちます。

次のファイルを編集して定義できます。

nano /etc/iscsi/nodes/iqn.2020-07.example.com\:lun1/192.168.1.10\,3260\,1/default

次の行を追加/変更します。

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

ファイルを保存して閉じ、次のコマンドでiSCSIイニシエーターサービスを再起動します。

systemctl restart open-iscsi iscsid

次のコマンドを使用して、サービスのステータスを確認することもできます。

systemctl status open-iscsi

次の出力が表示されます。

? open-iscsi.service - Login to default iSCSI targets
     Loaded: loaded (/lib/systemd/system/open-iscsi.service; enabled; vendor preset: enabled)
     Active: active (exited) since Sat 2020-07-11 07:24:19 UTC; 10s ago
       Docs: man:iscsiadm(8)
             man:iscsid(8)
    Process: 3861 ExecStart=/sbin/iscsiadm -m node --loginall=automatic (code=exited, status=0/SUCCESS)
    Process: 3867 ExecStart=/lib/open-iscsi/activate-storage.sh (code=exited, status=0/SUCCESS)
   Main PID: 3867 (code=exited, status=0/SUCCESS)

Jul 11 07:24:19 initiator systemd[1]: Starting Login to default iSCSI targets...
Jul 11 07:24:19 initiator iscsiadm[3861]: Logging in to [iface: default, target: iqn.2020-07.example.com:lun1, portal: 104.245.33.142,3260] (m>
Jul 11 07:24:19 initiator iscsiadm[3861]: Login to [iface: default, target: iqn.2020-07.example.com:lun1, portal: 104.245.33.142,3260] success>
Jul 11 07:24:19 initiator systemd[1]: Finished Login to default iSCSI targets.

次のコマンドを使用して、iSCSI接続を確認することもできます。

iscsiadm -m session -o show

次の出力が表示されます。

tcp: [2] 192.168.1.10:3260,1 iqn.2020-07.example.com:lun1 (non-flash)

次のコマンドを使用して、iSCSIターゲットから共有されているストレージデバイスを確認することもできます。

lsblk

次の出力に共有デバイスsdbが表示されます。

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   80G  0 disk 
??sda1   8:1    0   80G  0 part /
sdb      8:16   0 1000M  0 disk

共有デバイスにファイルシステムを作成する

iSCSIイニシエーターで共有デバイスを使用するには、共有デバイス(sdb)にファイルシステムを作成してマウントし、このデバイスを有効にする必要があります。

最初に、次のコマンドを使用して、共有デバイス(sdb)にファイルシステムを作成します。

fdisk /dev/sdb

以下に示すすべての質問に答えて、ファイルシステムを作成します。

Welcome to fdisk (util-linux 2.34).
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 0x9743ddcf.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-2047999, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-2047999, default 2047999): 

Created a new partition 1 of type 'Linux' and of size 999 MiB.

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

次に、次のコマンドでパーティションをフォーマットします。

mkfs.ext4 /dev/sdb1

次の出力が表示されます。

mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 255744 4k blocks and 64000 inodes
Filesystem UUID: e7f06605-a0f5-41e1-b1b2-e85bd7a2d6a3
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376

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

次に、次のコマンドを使用して、パーティションを/ mntディレクトリにマウントします。

mount /dev/sdb1 /mnt

次のコマンドを使用して、マウントされたパーティションを確認できます。

df -h

次の出力が表示されます。

Filesystem      Size  Used Avail Use% Mounted on
udev            981M     0  981M   0% /dev
tmpfs           199M  588K  199M   1% /run
/dev/sda1        79G  1.8G   74G   3% /
tmpfs           994M     0  994M   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           994M     0  994M   0% /sys/fs/cgroup
tmpfs           199M     0  199M   0% /run/user/0
/dev/sdb1       968M  2.5M  899M   1% /mnt

結論

上記のガイドでは、Ubuntu 20.04サーバーでiSCSIターゲットとイニシエーターをセットアップする方法を学びました。また、ターゲットサーバー上のデバイスを共有し、イニシエーターからアクセスする方法も学びました。ご不明な点がございましたら、お気軽にお問い合わせください。

Source

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です