【Linux】Ubuntu 22.04 iSCSI Taget 設定手順

Linux
スポンサーリンク

今回は、Ubuntu Server 22.04にiSCSIのターゲット設定を行っていきたいと思います。
Ubuntu Serverで使用できるiSCSI Targetは2つありますが、[targetcli]をインストールしていきます。

期待する目標

本手順で期待する目標は以下の通りです。

  • Ubuntu Server 22.04でiSCSI Targetの設定ができる
  • Ubuntu Server 22.04でiSCSIディスクの設定ができる

前提条件

本手順で使用する環境は以下の通りです。

  • OS : Ubuntu Server 22.04
  • CPU : 2vCPU
  • MEM : 4GB
  • DISK : 60GB

Ubuntu ServerをiSCSI Targetとして設定しますが、iSCSI用のディスクは1GBを[/]配下に作成します。必要に応じてディスクは追加してください。

targetcliインストール

Ubuntu Serverのターミナル及びSSHをしパッケージのアップデートを行っておきます。

willserver@dev-target:~$ sudo apt update

以下のコマンドを実行し、iSCSI Targetのソフトウェアをインストールしていきます。

willserver@dev-target:~$ sudo apt -y install targetcli-fb
[sudo] password for willserver:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libflashrom1 libftdi1-2
Use 'sudo apt autoremove' to remove them.
The following additional packages will be installed:
  python3-configshell-fb python3-pyudev python3-rtslib-fb python3-urwid
Suggested packages:
  python-urwid-doc
The following NEW packages will be installed:
  python3-configshell-fb python3-pyudev python3-rtslib-fb python3-urwid targetcli-fb
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 322 kB of archives.
After this operation, 2,045 kB of additional disk space will be used.
Get:1 http://jp.archive.ubuntu.com/ubuntu jammy/main amd64 python3-urwid amd64 2.1.2-2build1 [171 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu jammy/main amd64 python3-configshell-fb all 1:1.1.28-2 [28.3 kB]
Get:3 http://jp.archive.ubuntu.com/ubuntu jammy/main amd64 python3-pyudev all 0.22.0-2 [33.2 kB]
Get:4 http://jp.archive.ubuntu.com/ubuntu jammy/main amd64 python3-rtslib-fb all 2.1.74-0ubuntu4 [49.8 kB]
Get:5 http://jp.archive.ubuntu.com/ubuntu jammy/main amd64 targetcli-fb all 1:2.1.53-1ubuntu3 [40.3 kB]
Fetched 322 kB in 3s (103 kB/s)
Selecting previously unselected package python3-urwid.
(Reading database ... 74034 files and directories currently installed.)
Preparing to unpack .../python3-urwid_2.1.2-2build1_amd64.deb ...
Unpacking python3-urwid (2.1.2-2build1) ...
Selecting previously unselected package python3-configshell-fb.
Preparing to unpack .../python3-configshell-fb_1%3a1.1.28-2_all.deb ...
Unpacking python3-configshell-fb (1:1.1.28-2) ...
Selecting previously unselected package python3-pyudev.
Preparing to unpack .../python3-pyudev_0.22.0-2_all.deb ...
Unpacking python3-pyudev (0.22.0-2) ...
Selecting previously unselected package python3-rtslib-fb.
Preparing to unpack .../python3-rtslib-fb_2.1.74-0ubuntu4_all.deb ...
Unpacking python3-rtslib-fb (2.1.74-0ubuntu4) ...
Selecting previously unselected package targetcli-fb.
Preparing to unpack .../targetcli-fb_1%3a2.1.53-1ubuntu3_all.deb ...
Unpacking targetcli-fb (1:2.1.53-1ubuntu3) ...
Setting up python3-urwid (2.1.2-2build1) ...
Setting up python3-configshell-fb (1:1.1.28-2) ...
Setting up python3-pyudev (0.22.0-2) ...
Setting up python3-rtslib-fb (2.1.74-0ubuntu4) ...
Created symlink /etc/systemd/system/multi-user.target.wants/rtslib-fb-targetctl.service → /lib/systemd/system/rtslib-fb-targetctl.service.
Setting up targetcli-fb (1:2.1.53-1ubuntu3) ...
Processing triggers for man-db (2.10.2-1) ...
Scanning processes...
Scanning candidates...
Scanning linux images...

Running kernel seems to be up-to-date.

Restarting services...

Service restarts being deferred:
 /etc/needrestart/restart.d/dbus.service
 systemctl restart getty@tty1.service
 systemctl restart networkd-dispatcher.service
 systemctl restart systemd-logind.service
 systemctl restart unattended-upgrades.service

No containers need to be restarted.

No user sessions are running outdated binaries.

No VM guests are running outdated hypervisor (qemu) binaries on this host.

willserver@dev-target:~$

targetcliの設定

targetcliのインストールが完了したら、targetcliの設定を行っていきます。

willserver@dev-target:~$ sudo targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.53
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/>

[target cli]コマンドを実行すると、targetcliの設定モードに移行することができます。

/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 0]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 0]
  o- loopback ......................................................................................................... [Targets: 0]
  o- vhost ............................................................................................................ [Targets: 0]
/>

[ls]コマンドを実行すると、各メニューが表示されます。
これからの設定の流れとして、[fileio]セクションで、iSCSI用のディスクを作成します。
作成するディスクはイメージファイルとなるので、無理にディスクを追加する必要がありません。

/> cd backstores/fileio
/backstores/fileio>
/backstores/fileio> ls
o- fileio ..................................................................................................... [Storage Objects: 0]
/backstores/fileio>
/backstores/fileio> create disk01 /iscsi001.img 1G
Created fileio disk01 with size 1073741824
/backstores/fileio>
/backstores/fileio> ls
o- fileio ..................................................................................................... [Storage Objects: 1]
  o- disk01 ........................................................................ [/iscsi001.img (1.0GiB) write-back deactivated]
    o- alua ....................................................................................................... [ALUA Groups: 1]
      o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]
/backstores/fileio>

iSCSI用のディスクを作成するため、[cd backstores/fileio]でfileioまで移動します。
移動したら、[create <ディスク名> <ディスクパス>.img <容量>]でディスクを作成します。

/backstores/fileio> cd /iscsi
/iscsi>
/iscsi>
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 0]
/iscsi>
/iscsi> create iqn.2023-07.local.willserver.dev-target:target001
Created target iqn.2023-07.local.willserver.dev-target:target001.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi>

ディスクの作成が完了したら、iSCSI Targetの設定を行っていきます。
[cd /iscsi]でiSCSIの設定へ移動します。
[create iqn.<年>-<月>.<ドメイン名>.<ホスト名>:<iSCSI名>]でiSCSIのIQNを設定します。
iSCSIへのアクセスはこのIQNを使用して接続します。
デフォルトだと、すべてのIPからアクセスを許可されるようです。

iSCSIの設定が終わったら、iSCSIに対して、LUNを割り当てる設定をすることで、iSCSI Targetとして機能します。

/iscsi> cd iqn.2023-07.local.willserver.dev-target:target001/
/iscsi/iqn.20...get:target001>
/iscsi/iqn.20...get:target001>
/iscsi/iqn.20...get:target001>
/iscsi/iqn.20...get:target001> ls
o- iqn.2023-07.local.willserver.dev-target:target001 ..................................................................... [TPGs: 1]
  o- tpg1 ................................................................................................... [no-gen-acls, no-auth]
    o- acls .............................................................................................................. [ACLs: 0]
    o- luns .............................................................................................................. [LUNs: 0]
    o- portals ........................................................................................................ [Portals: 1]
      o- 0.0.0.0:3260 ......................................................................................................... [OK]
/iscsi/iqn.20...get:target001>

iSCSI Targetにディスクの割当を行う前に、必ず[cd]コマンドで場所を移動しておきます。

/iscsi/iqn.20...get:target001> cd tpg1/luns
/iscsi/iqn.20...001/tpg1/luns> create /backstores/fileio/disk01
Created LUN 0.
/iscsi/iqn.20...001/tpg1/luns>

[cd tpg1/luns]に移動し、[create /backstores/fileio/<ディスク名>]コマンドで、iSCSI Targetと作成したディスクを紐付けます。

/iscsi/iqn.20...001/tpg1/luns> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/rtslib-fb-target/backup/.
Configuration saved to /etc/rtslib-fb-target/saveconfig.json
willserver@dev-target:/$

設定が完了したら、[exit]でtargetcliを終了させます。
以上で、targetcliの設定は完了です。
あとは、Windows ServerなどからiSCSIイニシエータで接続をすればiSCSI Targetサーバの設定は完了です。

まとめ

今回は、Ubuntu Server 22.04を使用してiSCSI Targetサーバを作成しました。
実際に業務使用する場合、ストレージ製品を使用する機会が多く、LinuxでiSCSIのターゲットを作成することは少ないと思いますが、家庭用のストレージサーバとしてUbuntuをインストールし、iSCSI Targetとして設定することで、比較的簡単にストレージを作ることはできると思います。

おまけ

本ブログではVMwareやWindows、Linuxのインストール手順等も公開しております。
インフラエンジニアとして有益な記事や無益なコンテンツも作成しておりますので、通勤時間や休憩時間、休日のスキマ時間等に合わせて読んでいただけると幸いです。
また、Youtubeで解説動画も鋭意作成中です。本ブログで記事にしているものも動画にしようと思っておりますので、よろしくお願いいたします。
willserverのnoteも開設したのでフォローお願いします。

コメント

タイトルとURLをコピーしました