iSCSIは(Internet Small Computer System Interface)の略で、オンラインストレージ管理に使用できるストレージエリアネットワーク(SAN)プロトコルです。これは、TCP / IPネットワークを介してSCSIコマンドを実行することにより、ストレージデバイスへのブロックレベルのアクセスを提供するIPベースのストレージネットワーク標準です。
iSCSIは、iSCSIターゲットとiSCSIイニシエーターの2つのコンポーネントで構成されています。 iSCSIターゲットは、共有ストレージへのアクセスを提供するiSCSIサーバー上のサービスであり、iSCSIイニシエーターは、ターゲットに接続して共有ストレージにアクセスするiSCSIクライアントです。
このチュートリアルでは、Ubuntu18.04サーバーでiSCSIターゲットとiSCSIイニシエーターをセットアップする方法を示します。
- 2GBの外付けHDDを備えたiSCSIターゲット用の新しいUbuntu18.04サーバー。
- iSCSIイニシエーター用の新しいUbuntu18.04サーバー。
- 静的IPアドレス192.168.0.103がiSCSIターゲットに構成され、192.168.0.102がiSCSIイニシエーターに構成されています。
- ルートパスワードは両方のサーバーで構成されています。
開始する前に、両方のサーバーを最新バージョンに更新する必要があります。両方の$
で次のコマンドを実行することにより、それらを更新できます。apt-get update -y
apt-get upgrade -y
両方のサーバーが更新されたら、それらを再起動して変更を適用します。
まず、iSCSIターゲットサーバーにTarget Framework(TGT)パッケージをインストールする必要があります。次のコマンドでインストールできます:
apt-get install tgt -y
TGTをインストールしたら、次のコマンドを実行してTGTのステータスを確認します。
systemctl status tgt
次の出力が表示されます。
? 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.
完了したら、次のステップに進むことができます。
次に、iSCSIサーバー上にLUN(論理ユニット番号)デバイスを作成する必要があります。 LUNは、イニシエーターが接続して後で使用するバックエンドストレージデバイスです。
これを行うには、/ etc / tgt/conf.dディレクトリ内に構成ファイルを作成します。
nano /etc/tgt/conf.d/iscsi.conf
次の行を追加します:
<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>
終了したら、ファイルを保存して閉じます。次に、TGTサービスを再起動して、構成の変更を適用します。
systemctl restart tgt
各パラメータの簡単な説明は次のとおりです。
ターゲット :これは特定のターゲットの名前です。
バッキングストア :このオプションは、イニシエーターが使用するストレージディスクを指定します。
イニシエーターアドレス :これはイニシエーターのIPアドレスです。
着信ユーザー :これは、LUNを保護するための着信ユーザー名/パスワードです。
発信ユーザー :これは、相互CHAP認証の送信ユーザー名/パスワードです。
TGTサービスを再起動した後、次のコマンドを使用してiSCSIターゲットサーバーを確認します。
tgtadm --mode target --op show
iSCSIターゲットが使用可能になっていることを確認する必要があります:
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
iSCSIイニシエーターのインストールと構成
次に、iSCSIイニシエーターサーバーにiSCSIイニシエーターパッケージをインストールする必要があります。次のコマンドでインストールできます:
apt-get install open-iscsi -y
インストールが完了したら、iSCSIターゲットサーバーに対してターゲット検出を実行して、共有ターゲットを見つけます。
iscsiadm -m discovery -t st -p 192.168.0.103
次の出力に使用可能なターゲットが表示されます。
192.168.0.103:3260,1 iqn.2019-11.example.com:lun1
上記のコマンドは、LUN情報を含む2つのファイルも生成します。次のコマンドでそれらを見ることができます:
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/
次のファイルが表示されます。
/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
次に、デフォルトファイルを編集し、iSCSIイニシエーターからiSCSIターゲットにアクセスするためにiSCSIターゲットで構成したCHAP情報を定義する必要があります。
nano /etc/iscsi/nodes/iqn.2019-11.example.com\:lun1/192.168.0.103\,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
次の出力が表示されます。
* 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 ]
次のコマンドを使用して、iSCSIターゲットから共有されているストレージディスクを確認できるようになりました。
lsblk
これで、イニシエーターが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
次のコマンドを使用してiSCSI接続を確認することもできます。
tgtadm --mode conn --op show --tid 1
次の出力が得られるはずです:
Session: 1 Connection: 0 Initiator: iqn.1993-08.org.debian:01:2e1e2383de41 IP Address: 192.168.0.102
次に、この共有デバイス(sdb)にファイルシステムを作成してマウントし、このデバイスを使用できるようにする必要があります。
まず、次のコマンドを使用して、共有デバイス(sdb)にファイルシステムを作成します。
fdisk /dev/sdb
次の出力が表示されます。
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.
次に、次のコマンドを使用してこのパーティションをフォーマットします。
mkfs.ext4 /dev/sdb1
次に、次のコマンドを使用して、このパーティションを/mntディレクトリにマウントします。
mount /dev/sdb1 /mnt
これで、次のコマンドを使用して、マウントされたデバイスを確認できます。
df -h
次の出力が表示されます。
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
おめでとう!これで、iSCSIターゲットサーバーが正常にインストールされ、iSCSIイニシエーターから接続されました。これで、この共有iSCSIデバイスを通常の接続ディスクとして使用できます。