User Tools

Site Tools


wiki:filesystem:targetcli

Linux IO target (LIO)

Cenário:

  • 192.0.2.252 - storage: Storage rodando no CentOS 7
  • 192.0.2.14 - centos7: Cliente rodndo no CentOS 7

Preparando o disco com lvm

root@storage:~# fdisk -l /dev/sdb 
 
Disk /dev/sdb: 10.7 GB, 10737418240 bytes, 20971520 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
root@storage:~# pvcreate /dev/sdb 
  Physical volume "/dev/sdb" successfully created
root@storage:~# vgcreate vg_storage /dev/sdb 
  Volume group "vg_storage" successfully created
root@storage:~# lvcreate -L 2G -n lv_volume01 vg_storage
  Logical volume "lv_volume01" created.
root@storage:~# lvcreate -L 2G -n lv_volume02 vg_storage
  Logical volume "lv_volume02" created.

Instalação

root@storage:~# yum install targetcli -y
root@storage:~# rpm -qil targetcli
Name        : targetcli
Version     : 2.1.fb41
Release     : 3.el7
Architecture: noarch
Install Date: Ter 02 Fev 2016 19:31:45 BRT
Group       : System Environment/Libraries
Size        : 214175
License     : ASL 2.0
Signature   : RSA/SHA256, Qua 25 Nov 2015 12:43:06 BRT, Key ID 24c6a8a7f4a80eb5
Source RPM  : targetcli-2.1.fb41-3.el7.src.rpm
Build Date  : Sex 20 Nov 2015 05:33:33 BRT
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : https://fedorahosted.org/targetcli-fb/
Summary     : An administration shell for storage targets
Description :
An administration shell for configuring iSCSI, FCoE, and other
SCSI targets, using the TCM/LIO kernel target subsystem. FCoE
users will also need to install and use fcoe-utils.
/etc/target
/etc/target/backup
/usr/bin/targetcli
/usr/lib/python2.7/site-packages/targetcli
/usr/lib/python2.7/site-packages/targetcli/__init__.py
/usr/lib/python2.7/site-packages/targetcli/__init__.pyc
/usr/lib/python2.7/site-packages/targetcli/__init__.pyo
/usr/lib/python2.7/site-packages/targetcli/ui_backstore.py
/usr/lib/python2.7/site-packages/targetcli/ui_backstore.pyc
/usr/lib/python2.7/site-packages/targetcli/ui_backstore.pyo
/usr/lib/python2.7/site-packages/targetcli/ui_node.py
/usr/lib/python2.7/site-packages/targetcli/ui_node.pyc
/usr/lib/python2.7/site-packages/targetcli/ui_node.pyo
/usr/lib/python2.7/site-packages/targetcli/ui_root.py
/usr/lib/python2.7/site-packages/targetcli/ui_root.pyc
/usr/lib/python2.7/site-packages/targetcli/ui_root.pyo
/usr/lib/python2.7/site-packages/targetcli/ui_target.py
/usr/lib/python2.7/site-packages/targetcli/ui_target.pyc
/usr/lib/python2.7/site-packages/targetcli/ui_target.pyo
/usr/lib/python2.7/site-packages/targetcli/version.py
/usr/lib/python2.7/site-packages/targetcli/version.pyc
/usr/lib/python2.7/site-packages/targetcli/version.pyo
/usr/lib/python2.7/site-packages/targetcli_fb-2.1.fb41-py2.7.egg-info
/usr/lib/python2.7/site-packages/targetcli_fb-2.1.fb41-py2.7.egg-info/PKG-INFO
/usr/lib/python2.7/site-packages/targetcli_fb-2.1.fb41-py2.7.egg-info/SOURCES.txt
/usr/lib/python2.7/site-packages/targetcli_fb-2.1.fb41-py2.7.egg-info/dependency_links.txt
/usr/lib/python2.7/site-packages/targetcli_fb-2.1.fb41-py2.7.egg-info/top_level.txt
/usr/share/doc/targetcli-2.1.fb41
/usr/share/doc/targetcli-2.1.fb41/COPYING
/usr/share/doc/targetcli-2.1.fb41/README.md
/usr/share/man/man8/targetcli.8.gz

Configurando

Para limpar configurações existentes execute

root@storage:~# targetcli clearconfig confirm=true
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
All configuration cleared

Acessando a linha de comando

root@storage:~# targetcli 
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
 
/> help
 
GENERALITIES
============
This is a shell in which you can create, delete and configure
configuration objects.
 
The available commands depend on the current path or target
path you want to run a command in: different path have
different sets of available commands, i.e. a path pointing at
an iscsi target will not have the same availaible commands as,
say, a path pointing at a storage object.
 
The prompt that starts each command line indicates your
current path. Alternatively (useful if the prompt displays
an abbreviated path to save space), you can run the
pwd command to display the complete current path.
 
Navigating the tree is done using the cd command. Without
any argument, cd will present you wil the full objects
tree. Just use arrows to select the destination path, and
enter will get you there. Please try help cd for navigation
tips.
 
COMMAND SYNTAX
==============
Commands are built using the following syntax:
 
[TARGET_PATH] COMMAND_NAME [OPTIONS]
 
The TARGET_PATH indicates the path to run the command from.
If ommited, the command will be run from your current path.
 
The OPTIONS depend on the command. Please use help
COMMAND to get more information.
 
 
AVAILABLE COMMANDS
==================
The following commands are available in the
current path:
 
  - bookmarks action [bookmark] 
  - cd [path] 
  - clearconfig [confirm] 
  - exit 
  - get [group] [parameter...] 
  - help [topic] 
  - ls [path] [depth] 
  - pwd 
  - refresh 
  - restoreconfig [savefile] [clear_existing] 
  - saveconfig [savefile] 
  - sessions [action] [sid] 
  - set [group] [parameter=value...] 
  - status 
  - version 
/> 

Criando os blocks sobre os volumes

/> /backstores/block create volume01 /dev/vg_storage/lv_volume01 
Created block storage object volume01 using /dev/vg_storage/lv_volume01.
/> /backstores/block create volume02 /dev/vg_storage/lv_volume02
Created block storage object volume02 using /dev/vg_storage/lv_volume02.
/> 

Desabilitar a autenticação

/> iscsi/ set discovery_auth enable=0
Parameter enable is now 'False'.
/> 

Criando o target

/> iscsi/ create iqn.2016-02.org.exemplo:target-01
Created target iqn.2016-02.org.exemplo:target-01.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> 

Criando portal

FIXME Se quisermos especificar o IP para o portal precisamos primeiro deletar o que foi criado automaticamente quando criamos o target

/> iscsi/iqn.2016-02.org.exemplo:target-01/tpg1/portals/ delete ip_address=0.0.0.0 ip_port=3260
Deleted network portal 0.0.0.0:3260

Agora vamos criar

/> iscsi/iqn.2016-02.org.exemplo:target-01/tpg1/portals/ create ip_address=192.0.2.14 ip_port=3260
Using default IP port 3260
Created network portal 192.0.2.14:3260.
/> iscsi/iqn.2016-02.org.exemplo:target-01/tpg1/portals/ create ip_address=192.0.2.252 ip_port=3260
Using default IP port 3260
Created network portal 192.0.2.252:3260.
/> 

Criando as LUNs

/> iscsi/iqn.2016-02.org.exemplo:target-01/tpg1/luns create /backstores/block/volume01 
Created LUN 0.
/> iscsi/iqn.2016-02.org.exemplo:target-01/tpg1/luns create /backstores/block/volume02 
Created LUN 1.
/> 

Criando as ACLs

/> iscsi/iqn.2016-02.org.exemplo:target-01/tpg1/acls create iqn.2016-02.org.exemplo:cliente01
Created Node ACL for iqn.2016-02.org.exemplo:cliente01
Created mapped LUN 1.
Created mapped LUN 0.
/> iscsi/iqn.2016-02.org.exemplo:target-01/tpg1/acls create iqn.2016-02.org.exemplo:cliente02
Created Node ACL for iqn.2016-02.org.exemplo:cliente02
Created mapped LUN 1.
Created mapped LUN 0.
/> 

Salvando as configurações

/> saveconfig 
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> 

Listando a configuração salva

/> ls
o- / ............................................................................................ [...]
  o- backstores ................................................................................. [...]
  | o- block ..................................................................... [Storage Objects: 2]
  | | o- volume01 ......................... [/dev/vg_storage/lv_volume01 (2.0GiB) write-thru activated]
  | | o- volume02 ......................... [/dev/vg_storage/lv_volume02 (2.0GiB) write-thru activated]
  | o- fileio .................................................................... [Storage Objects: 0]
  | o- pscsi ..................................................................... [Storage Objects: 0]
  | o- ramdisk ................................................................... [Storage Objects: 0]
  o- iscsi ............................................................................... [Targets: 1]
  | o- iqn.2016-02.org.exemplo:target-01 .................................................... [TPGs: 1]
  |   o- tpg1 .................................................................. [no-gen-acls, no-auth]
  |     o- acls ............................................................................. [ACLs: 2]
  |     | o- iqn.2016-02.org.exemplo:cliente01 ....................................... [Mapped LUNs: 2]
  |     | | o- mapped_lun0 ................................................. [lun0 block/volume01 (rw)]
  |     | | o- mapped_lun1 ................................................. [lun1 block/volume02 (rw)]
  |     | o- iqn.2016-02.org.exemplo:cliente02 ....................................... [Mapped LUNs: 2]
  |     |   o- mapped_lun0 ................................................. [lun0 block/volume01 (rw)]
  |     |   o- mapped_lun1 ................................................. [lun1 block/volume02 (rw)]
  |     o- luns ............................................................................. [LUNs: 2]
  |     | o- lun0 ...................................... [block/volume01 (/dev/vg_storage/lv_volume01)]
  |     | o- lun1 ...................................... [block/volume02 (/dev/vg_storage/lv_volume02)]
  |     o- portals ....................................................................... [Portals: 2]
  |       o- 192.0.2.14:3260 ..................................................................... [OK]
  |       o- 192.0.2.252:3260 .................................................................... [OK]
  o- loopback ............................................................................ [Targets: 0]
/> 

Iniciando os serviços e colocando na inicialização

root@storage:~# systemctl start target.service
root@storage:~# systemctl enable target.service 
Created symlink from /etc/systemd/system/multi-user.target.wants/target.service to /usr/lib/systemd/system/target.service.
root@storage:~# systemctl status target.service 
● target.service - Restore LIO kernel target configuration
   Loaded: loaded (/usr/lib/systemd/system/target.service; enabled; vendor preset: disabled)
   Active: active (exited) since Ter 2016-02-02 20:18:56 BRT; 9s ago
  Process: 6014 ExecStart=/usr/bin/targetctl restore (code=exited, status=0/SUCCESS)
 Main PID: 6014 (code=exited, status=0/SUCCESS)
 
Fev 02 20:18:56 storage systemd[1]: Starting Restore LIO kernel target configuration...
Fev 02 20:18:56 storage systemd[1]: Started Restore LIO kernel target configuration.
root@storage:~# ss -nat | grep 3260
LISTEN     0      256    192.0.2.14:3260                     *:*                  
LISTEN     0      256    192.0.2.252:3260                     *:*                  

Liberando o firewall

root@storage:~# firewall-cmd --permanent --add-service=iscsi-target
success
root@storage:~# firewall-cmd --reload
success

Configurando o cliente

root@centos7:~# yum install iscsi-initiator-utils -y
root@centos7:~# rpm -qil iscsi-initiator-utils 
Name        : iscsi-initiator-utils
Version     : 6.2.0.873
Release     : 32.el7
Architecture: x86_64
Install Date: Ter 02 Fev 2016 20:26:29 BRT
Group       : System Environment/Daemons
Size        : 2482427
License     : GPLv2+
Signature   : RSA/SHA256, Qua 25 Nov 2015 11:43:56 BRT, Key ID 24c6a8a7f4a80eb5
Source RPM  : iscsi-initiator-utils-6.2.0.873-32.el7.src.rpm
Build Date  : Sex 20 Nov 2015 10:53:13 BRT
Build Host  : worker1.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.open-iscsi.org
Summary     : iSCSI daemon and utility programs
Description :
The iscsi package provides the server daemon for the iSCSI protocol,
as well as the utility programs used to manage it. iSCSI is a protocol
for distributed disk access using SCSI commands sent over Internet
Protocol networks.
/etc/NetworkManager/dispatcher.d/04-iscsi
/etc/iscsi
/etc/iscsi/iscsid.conf
/usr/lib/systemd/system/iscsi-shutdown.service
/usr/lib/systemd/system/iscsi.service
/usr/lib/systemd/system/iscsid.service
/usr/lib/systemd/system/iscsid.socket
/usr/lib/tmpfiles.d/iscsi.conf
/usr/lib64/libiscsi.so.0
/usr/lib64/python2.7/site-packages/libiscsimodule.so
/usr/libexec/iscsi-mark-root-nodes
/usr/sbin/iscsi-iname
/usr/sbin/iscsiadm
/usr/sbin/iscsid
/usr/sbin/iscsistart
/usr/share/doc/iscsi-initiator-utils-6.2.0.873
/usr/share/doc/iscsi-initiator-utils-6.2.0.873/README
/usr/share/man/man8/iscsi-iname.8.gz
/usr/share/man/man8/iscsiadm.8.gz
/usr/share/man/man8/iscsid.8.gz
/usr/share/man/man8/iscsistart.8.gz
/var/lib/iscsi
/var/lib/iscsi/ifaces
/var/lib/iscsi/isns
/var/lib/iscsi/nodes
/var/lib/iscsi/send_targets
/var/lib/iscsi/slp
/var/lib/iscsi/static
/var/lock/iscsi
/var/lock/iscsi/lock

Setando a ACL

root@centos7:~# cat /etc/iscsi/initiatorname.iscsi 
InitiatorName=iqn.2016-02.org.exemplo:cliente01

Mapeando os target

root@centos7:~# iscsiadm --mode discovery --type sendtargets --portal 192.0.2.252
192.0.2.252:3260,1 iqn.2016-02.org.exemplo:target-01
192.0.2.14:3260,1 iqn.2016-02.org.exemplo:target-01

Iniciando e colocando os serviços na inicialização

root@centos7:~# systemctl start iscsi.service
root@centos7:~# systemctl enable iscsi.service
root@centos7:~# systemctl status iscsi.service -l
● iscsi.service - Login and scanning of iSCSI devices
   Loaded: loaded (/usr/lib/systemd/system/iscsi.service; enabled; vendor preset: disabled)
   Active: active (exited) since Ter 2016-02-02 20:35:47 BRT; 2min 2s ago
     Docs: man:iscsid(8)
           man:iscsiadm(8)
 Main PID: 2667 (code=exited, status=8)
 
Fev 02 20:33:44 centos7 systemd[1]: Starting Login and scanning of iSCSI devices...
Fev 02 20:33:44 centos7 iscsi-mark-root-nodes[2663]: iscsiadm: No active sessions.
Fev 02 20:35:47 centos7 iscsiadm[2667]: iscsiadm: Could not login to [iface: default, target: iqn.2016-02.org.exemplo:target-01, portal: 192.0.2.14,3260].
Fev 02 20:35:47 centos7 iscsiadm[2667]: iscsiadm: initiator reported error (8 - connection timed out)
Fev 02 20:35:47 centos7 iscsiadm[2667]: iscsiadm: Could not log into all portals
Fev 02 20:35:47 centos7 iscsiadm[2667]: Logging in to [iface: default, target: iqn.2016-02.org.exemplo:target-01, portal: 192.0.2.252,3260] (multiple)
Fev 02 20:35:47 centos7 iscsiadm[2667]: Logging in to [iface: default, target: iqn.2016-02.org.exemplo:target-01, portal: 192.0.2.14,3260] (multiple)
Fev 02 20:35:47 centos7 iscsiadm[2667]: Login to [iface: default, target: iqn.2016-02.org.exemplo:target-01, portal: 192.0.2.252,3260] successful.
Fev 02 20:35:47 centos7 systemd[1]: Started Login and scanning of iSCSI devices.

Referências:

wiki/filesystem/targetcli.txt · Last modified: by Wiki Administrator