iSCSI : Configure Target (targetcli)2019/07/17 |
|
Configure Storage Server with iSCSI.
A storage on a network is called iSCSI Target, a Client which connects to iSCSI Target is called iSCSI Initiator.
This example is based on the environment below. +----------------------+ | +----------------------+ | [ iSCSI Target ] |10.0.0.30 | 10.0.0.31| [ iSCSI Initiator ] | | dlp.srv.world +----------+----------+ www.srv.world | | | | | +----------------------+ +----------------------+ |
| [1] | Install administration tools first. |
|
root@dlp:~# apt -y install targetcli-fb
|
| [2] | Configure iSCSI Target. For example, create an disk-image under the [/var/lib/iscsi_disks] directory and set it as a SCSI device. |
|
# enter the admin console 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 # create a disk-image with the name [disk01] on [/var/lib/iscsi_disks/disk01.img] with 10G /backstores/fileio> create disk01 /var/lib/iscsi_disks/disk01.img 10G Created fileio disk01 with size 10737418240 /backstores/fileio> cd /iscsi # create a target # naming rule : [iqn.(year)-(month).(reverse of domain name):(any name you like)] /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 # set LUN /iscsi/iqn.20...t00/tpg1/luns> create /backstores/fileio/disk01 Created LUN 0. /iscsi/iqn.20...t00/tpg1/luns> cd ../acls # set ACL (it's the IQN of an initiator you permit to connect) /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 # set UserID for authentication /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 # after configuration above, the target enters in listening like follows root@dlp:~# ss -napt | grep 3260 LISTEN 0 256 *:3260 *:* |
| [3] | The init script is not included in targetcli related packages, so it needs to start manually after restarting System like follows. |
|
root@dlp:~# targetctl restore |
| [4] | Or it's possible to use the init script in Ubuntu like follows. |
|
root@dlp:~#
vi /etc/init.d/rtslib-fb-targetctl # create new
#!/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 |