iSCSIはInternetSmallComputer System Interfaceの略で、HDD / SSDパーティションやLVMパーティションなどのブロックデバイスを共有したり、ファイルをブロックしたりするために使用できるストレージエリアネットワークプロトコルです。ネットワーク。 iSCSIはクライアントサーバーモデルで動作し、TCP/IPネットワークに依存してイニシエータークライアントとターゲットの間でSCSIコマンドを送信します。 iSCSI Targetは、共有ストレージへのアクセスを提供するiSCSIサーバー上のサービスであり、iSCSI Initiatorは、ターゲットに接続して共有ストレージにアクセスするiSCSIクライアントです。
このチュートリアルでは、Ubuntu20.04サーバーでiSCSIターゲットとiSCSIイニシエーターをセットアップする方法について説明します。
- 1GBの外付けHDDを備えたiSCSIターゲット用のUbuntu20.04を実行しているシステム。
- iSCSIイニシエーター用に新しいUbuntu20.04を実行しているシステム。
- 静的IPアドレス192.168.1.10がiSCSIターゲットに構成され、192.168.1.20がiSCSIイニシエーターに構成されています。
- ルートパスワードは両方のサーバーで構成されています。
開始する前に、システムを最新のパッケージで更新することをお勧めします。次のコマンドで更新できます:
apt-get update -y
apt-get upgrade -y
すべてのパッケージが更新されたら、システムを再起動して変更を適用します。
デフォルトでは、iSCSIターゲットパッケージはUbuntu20.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サーバー上にLUN(論理ユニット番号)デバイスを作成する必要があります。 LUNは、物理SCSIデバイスの一部であるバックエンドストレージデバイスです。 iSCSIターゲットにマップされたすべてのLUNは、クライアントのオペレーティングシステムに仮想的に接続されています。したがって、イニシエーターはiSCSILUN上でファイルシステムを確立および管理できます。
新しい構成ファイルを作成して構成できます:
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 / ノード/‘に存在し、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
上記のガイドでは、Ubuntu20.04サーバーでiSCSIターゲットとイニシエーターをセットアップする方法を学習しました。また、ターゲットサーバーでデバイスを共有し、イニシエーターからデバイスにアクセスする方法も学習しました。ご不明な点がございましたら、お気軽にお問い合わせください。