본문 바로가기

Linux

targetcli (iSCSI Target 생성)

반응형

targetcli overview

targetcli는 리눅스에서 iscsi target(iscsi server)를 구성하는 명령어 모음이다. Target Discovery Port는 기본 3260/TCP 이며, 이 실험에서는 Firewalld / SELinux를 종료해 놓고 실험을 진행했다.

 

Lab 환경

OS : Rocky 9.3 - Minumal Installed

 

targetcli install

[root@iSCSI-Target ~]# yum install targetcli
Last metadata expiration check: 0:20:25 ago on Tue 02 Apr 2024 03:57:30 PM KST.
Dependencies resolved.
==============================================================================================================================================================================================================
 Package                                                 Architecture                               Version                                               Repository                                     Size
==============================================================================================================================================================================================================
Installing:
 targetcli                                               noarch                                     2.1.53-7.el9                                          appstream                                      71 k
Installing dependencies:
 python3-configshell                                     noarch                                     1:1.1.28-7.el9                                        baseos                                         65 k
 python3-kmod                                            x86_64                                     0.9-32.el9.0.1                                        baseos                                         81 k
 python3-pyparsing                                       noarch                                     2.4.7-9.el9                                           baseos                                        150 k
 python3-pyudev                                          noarch                                     0.22.0-6.el9                                          baseos                                         76 k
 python3-rtslib                                          noarch                                     2.1.75-1.el9                                          appstream                                      90 k
 python3-urwid                                           x86_64                                     2.1.2-4.el9                                           baseos                                        768 k
 target-restore                                          noarch                                     2.1.75-1.el9                                          appstream                                      14 k

Transaction Summary
==============================================================================================================================================================================================================
Install  8 Packages

[root@iSCSI-Target ~]# 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'.

/> 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]
/>

 

iSCSI Target 구성 1 - Block Device 생성

# LUN으로 던져줄 Block Device를 생성하여 준비
# ACTIVE            '/dev/target-volume/target-lun01' [30.00 GiB] inherit
# targetcli block device 생성
/> cd /backstores/block
/backstores/block> create LUN01 /dev/target-volume/target-lun01
Created block storage object LUN01 using /dev/target-volume/target-lun01.
/backstores/block> ls
o- block ...................................................................................................... [Storage Objects: 1]
  o- LUN01 ...................................................... [/dev/target-volume/target-lun01 (30.0GiB) write-thru deactivated]
    o- alua ....................................................................................................... [ALUA Groups: 1]
      o- default_tg_pt_gp ........................................................................... [ALUA state: Active/optimized]
/backstores/block>

 

iSCSI Target 구성 2 - iqn 및 portal 생성

# iqn 이름은 target의 고유 이름으로 RFC3720에 정의 되어 있습니다.
# 제안된 형식 = iqn.[날짜].[도메인]:[장치 식별자]
# RFC3720에 따르면 날짜는 이 이름을 소유하고자 하는 만료날짜를 의미합니다. # 부록 참조
/> cd /iscsi
/iscsi> create iqn.2024-05.local.rocky:iSCSITarget
Created target iqn.2024-05.local.rocky:iscsitarget.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 1]
  o- iqn.2024-05.local.rocky:iscsitarget ................................................................................. [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>

 

iSCSI Target 구성 3 - LUN 생성 및 Device 매핑

# 생성한 iqn Target에서 LUN 생성
/iscsi> cd /iscsi/iqn.2024-05.local.rocky:iscsitarget/tpg1/luns
/iscsi/iqn.20...get/tpg1/luns> create /backstores/block/LUN01
Created LUN 0.
/iscsi/iqn.20...get/tpg1/luns> ls
o- luns .................................................................................................................. [LUNs: 1]
  o- lun0 ....................................................... [block/LUN01 (/dev/target-volume/target-lun01) (default_tg_pt_gp)]
/iscsi/iqn.20...get/tpg1/luns>

 

iSCSI Target 구성 4 - ACL 설정(접근가능한 WhiteList)

# ACL 설정시 접근하려는 Client의 iqn을 설정해줘서 해당 iqn의 client만 접속 할 수 있게 해준다.
/iscsi/iqn.20...get/tpg1/luns> cd /iscsi/iqn.2024-05.local.rocky:iscsitarget/tpg1/acls
/iscsi/iqn.20...get/tpg1/acls> create iqn.1994-05.com.redhat:e33825e1bd50
Created Node ACL for iqn.1994-05.com.redhat:e33825e1bd50
Created mapped LUN 0.
/iscsi/iqn.20...get/tpg1/acls> ls
o- acls .................................................................................................................. [ACLs: 1]
  o- iqn.1994-05.com.redhat:e33825e1bd50 .......................................................................... [Mapped LUNs: 1]
    o- mapped_lun0 ......................................................................................... [lun0 block/LUN01 (rw)]
/iscsi/iqn.20...get/tpg1/acls>

 

iSCSI Target 구성 5 - 설정 확인 및 설정 저장

/iscsi/iqn.20...get/tpg1/acls> cd /
/> ls
o- / ......................................................................................................................... [...]
  o- backstores .............................................................................................................. [...]
  | o- block .................................................................................................. [Storage Objects: 1]
  | | o- LUN01 .................................................... [/dev/target-volume/target-lun01 (30.0GiB) write-thru activated]
  | |   o- alua ................................................................................................... [ALUA Groups: 1]
  | |     o- default_tg_pt_gp ....................................................................... [ALUA state: Active/optimized]
  | o- fileio ................................................................................................. [Storage Objects: 0]
  | o- pscsi .................................................................................................. [Storage Objects: 0]
  | o- ramdisk ................................................................................................ [Storage Objects: 0]
  o- iscsi ............................................................................................................ [Targets: 1]
  | o- iqn.2024-05.local.rocky:iscsitarget ............................................................................... [TPGs: 1]
  |   o- tpg1 ............................................................................................... [no-gen-acls, no-auth]
  |     o- acls .......................................................................................................... [ACLs: 1]
  |     | o- iqn.1994-05.com.redhat:e33825e1bd50 .................................................................. [Mapped LUNs: 1]
  |     |   o- mapped_lun0 ................................................................................. [lun0 block/LUN01 (rw)]
  |     o- luns .......................................................................................................... [LUNs: 1]
  |     | o- lun0 ............................................... [block/LUN01 (/dev/target-volume/target-lun01) (default_tg_pt_gp)]
  |     o- portals .................................................................................................... [Portals: 1]
  |       o- 0.0.0.0:3260 ..................................................................................................... [OK]
  o- loopback ......................................................................................................... [Targets: 0]
/> saveconfig
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup/.
Configuration saved to /etc/target/saveconfig.json
# 구성 저장이 완료된 후 target 서비스를 실행시켜 준다.
[root@iSCSI-Target ~]# systemctl start target.service
[root@iSCSI-Target ~]# systemctl enable target.service
Created symlink /etc/systemd/system/multi-user.target.wants/target.service → /usr/lib/systemd/system/target.service.
[root@iSCSI-Target ~]#

 

  • 부록 : IQN Naming 규칙

RFC3720 인용: https://www.rfc-editor.org/rfc/rfc3720#page-32

The iSCSI qualified name string consists of:

      -  The string "iqn.", used to distinguish these names from "eui."
         formatted names.
      -  A date code, in yyyy-mm format.  This date MUST be a date
         during which the naming authority owned the domain name used in
         this format, and SHOULD be the first month in which the domain
         name was owned by this naming authority at 00:01 GMT of the
         first day of the month.  This date code uses the Gregorian
         calendar.  All four digits in the year must be present.  Both
         digits of the month must be present, with January == "01" and
         December == "12".  The dash must be included.
      -  A dot "."
      -  The reversed domain name of the naming authority (person or
         organization) creating this iSCSI name.
      -  An optional, colon (:) prefixed, string within the character
         set and length boundaries that the owner of the domain name
         deems appropriate.  This may contain product types, serial
         numbers, host identifiers, or software keys (e.g., it may
         include colons to separate organization boundaries).  With the
         exception of the colon prefix, the owner of the domain name can
         assign everything after the reversed domain name as desired.
         It is the responsibility of the entity that is the naming
         authority to ensure that the iSCSI names it assigns are
         worldwide unique.  For example, "Example Storage Arrays, Inc.",
         might own the domain name "example.com".

   The following are examples of iSCSI qualified names that might be
   generated by "EXAMPLE Storage Arrays, Inc."

                   Naming     String defined by
      Type  Date    Auth      "example.com" naming authority
     +--++-----+ +---------+ +--------------------------------+
     |  ||     | |         | |                                |

     iqn.2001-04.com.example:storage:diskarrays-sn-a8675309
     iqn.2001-04.com.example
     iqn.2001-04.com.example:storage.tape1.sys1.xyz
     iqn.2001-04.com.example:storage.disk2.sys1.xyz
반응형

'Linux' 카테고리의 다른 글

Linux LVM on CentOS 7  (0) 2024.04.03
iscsi multipath IO 구성  (0) 2024.04.03
iscsiadm (iSCSI Initiator 설정)  (0) 2024.04.03