iSCSI : iSCSIターゲットの設定 (targetcli)2019/07/17 |
|
iSCSI によるストレージサーバーの構築です。
ネットワーク上のストレージを iSCSI ターゲット、iSCSI ターゲットに接続するクライアントを iSCSI イニシエーターと呼びます。
当例では以下のような環境で iSCSI ストレージサーバーを構築します。 +----------------------+ | +----------------------+ | [ iSCSI Target ] |10.0.0.30 | 10.0.0.31| [ iSCSI Initiator ] | | dlp.srv.world +----------+----------+ www.srv.world | | | | | +----------------------+ +----------------------+ |
| [1] | 管理ツールをインストールします。 |
|
root@dlp:~# apt -y install targetcli-fb
|
| [2] | iSCSI ターゲットの設定です。 例として [/var/lib/iscsi_disks] ディレクトリ内にディスクイメージを作成し、SCSI デバイスとして共有できるよう設定します。 なお、例でのディスクイメージの他にも、ブロックデバイスや RAM ディスク等も SCSI デバイスとして設定可能です。 |
|
# 管理ツール起動 root@dlp:~# targetcli Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.fb48 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> cd backstores/fileio # [disk01] という名前で [/var/lib/iscsi_disks/disk01.img] を 10G で作成 /backstores/fileio> create disk01 /var/lib/iscsi_disks/disk01.img 10G Created fileio disk01 with size 10737418240 /backstores/fileio> cd /iscsi # ターゲットを作成 /iscsi> create iqn.2019-07.world.srv:storage.target01 Created target iqn.2019-07.world.srv:storage.target01. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /iscsi> cd iqn.2019-07.world.srv:storage.target01/tpg1/luns # LUN を設定 /iscsi/iqn.20...t00/tpg1/luns> create /backstores/fileio/disk01 Created LUN 0. /iscsi/iqn.20...t00/tpg1/luns> cd ../acls # ACLを設定 (接続を許可するイニシエーターのIQNを設定) /iscsi/iqn.20...t00/tpg1/acls> create iqn.2019-07.world.srv:www.srv.world Created Node ACL for iqn.2019-07.world.srv:www.srv.world Created mapped LUN 0. /iscsi/iqn.20...t00/tpg1/acls> cd iqn.2019-07.world.srv:www.srv.world # 認証用ユーザーID を設定 /iscsi/iqn.20....srv.world> set auth userid=username Parameter userid is now 'username'. /iscsi/iqn.20....srv.world> set auth password=password Parameter password is now 'password'. /iscsi/iqn.20....srv.world> 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 # 上記設定後、以下のようにターゲットがリスン状態になる root@dlp:~# ss -napt | grep 3260 LISTEN 0 256 *:3260 *:* |
| [3] | 自動起動スクリプトが付属していないため、システムを再起動するとサービスが起動しません。 よって、システム再起動後に手動で上げる場合は以下のように実行します。 |
|
root@dlp:~# targetctl restore |
| [4] | または、自動起動スクリプトは Ubuntu 付属のスクリプトが流用可能ですので、同じ内容のスクリプトを設定することで自動起動可能です。 |
|
root@dlp:~#
vi /etc/init.d/rtslib-fb-targetctl # 以下の内容で新規作成
#!/bin/bash
### BEGIN INIT INFO
# Provides: rtslib-fb-targetctl
# Required-Start: $network $local_fs $remote_fs $syslog
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start LIO targets
# Description: Loads configfs and restores LIO config with targetctl
### END INIT INFO
# Author: Thomas Goirand <zigo@debian.org>
PATH=/sbin:/usr/sbin:/bin:/usr/bin
DESC="rstlib-fb targetctl"
NAME=targetctl
DAEMON=/usr/bin/${NAME}
PIDFILE=/var/run/$NAME.pid
SCRIPTNAME=/etc/init.d/rtslib-fb-targetctl
SYSTEM_USER=trove
[ -x $DAEMON ] || exit 0
. /lib/lsb/init-functions
check_configfs_module () {
if ! modprobe configfs ; then
echo "Could not load configfs module: exiting!"
exit 0
fi
sleep 10
}
check_configfs_mounted () {
WORD_TO_GREP_IN_PROCMOUNT=configfs
NUM_RETRY=50
while ! cat /proc/mounts | grep -q ${WORD_TO_GREP_IN_PROCMOUNT} && [ "${NUM_RETRY}" != 0 ] ; do
NUM_RETRY=$(( $NUM_RETRY - 1 ))
sleep 0.1
done
if ! cat /proc/mounts | grep -q ${WORD_TO_GREP_IN_PROCMOUNT} ; then
echo " ${WORD_TO_GREP_IN_PROCMOUNT} not found in /proc/mount: exiting!"
exit 0
fi
}
case "$1" in
start)
check_configfs_module
check_configfs_mounted
log_daemon_msg "Loading $DESC" "$NAME"
${DAEMON} restore
if [ $? -gt 0 ] ; then
log_end_msg 1
exit 1
fi
log_end_msg 0
;;
stop)
check_configfs_module
log_daemon_msg "Unloading $DESC" "${NAME}"
${DAEMON} clear
if [ $? -gt 0 ] ; then
log_end_msg 1
exit 1
fi
log_end_msg 0
;;
restart|reload|force-reload)
$0 stop
sleep 3
$0 start
;;
status)
echo "Not supported!"
exit 1
;;
*)
echo "usage: $SCRIPTNAME {start|stop|restart|reload|force-reload}"
exit 1
;;
esac
exit 0
chmod 755 /etc/init.d/rtslib-fb-targetctl root@dlp:~# systemctl enable rtslib-fb-targetctl
|
| Sponsored Link |
|
|