# create a directory [root@dlp ~]# mkdir /var/lib/iscsi_disks # enter the admin console [root@dlp ~]# targetcli targetcli shell version 2.1.53 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.2022-01.world.srv:dlp.target01 Created target iqn.2022-01.world.srv:dlp.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.2022-01.world.srv:dlp.target01/tpg1 # enable authentication /iscsi/iqn.20...target01/tpg1> set attribute authentication=1 Parameter authentication is now '1'. /iscsi/iqn.20...target01/tpg1> cd luns # set LUN /iscsi/iqn.20...t01/tpg1/luns> create /backstores/fileio/disk01 Created LUN 0. /iscsi/iqn.20...t01/tpg1/luns> cd ../acls # set ACL (it's the IQN of an initiator you permit to connect) /iscsi/iqn.20...t01/tpg1/acls> create iqn.2022-01.world.srv:node01.initiator01 Created Node ACL for iqn.2022-01.world.srv:node01.initiator01 Created mapped LUN 0. /iscsi/iqn.20...t01/tpg1/acls> cd iqn.2022-01.world.srv:node01.initiator01 # set UserID and Password for authentication /iscsi/iqn.20...w.initiator01> set auth userid=username Parameter userid is now 'username'. /iscsi/iqn.20...w.initiator01> set auth password=password Parameter password is now 'password'. /iscsi/iqn.20...w.initiator01> exit Global pref auto_save_on_exit=true Configuration saved to /etc/target/saveconfig.json # after configuration above, the target enters in listening like follows [root@dlp ~]# ss -napt | grep 3260 LISTEN 0 256 0.0.0.0:3260 0.0.0.0:* [root@dlp ~]# systemctl enable target
테스트환경
* HOST OS : CentOS Linux release 7
* GUEST OS : CentOS Linux release 7
targetcli
는 트리 기반의 파일 시스템과 유사한 방식으로 탐색한다
targetcli
는 커널의 대상 서스 시스템을 구성하고 저장하기 위한 쉘 스크립트 이다
이 문서에서는 공유 디스크로 생성한 LVM 볼륨 구성은 작성하지 않았습니다
현재 등록되어 있는 디스크 정보들을 확인한다
[root@server1 ~]# fdisk -l | grep Disk Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 sectors Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors // ISCSI 구성을 위해 신규 추가된 디스크 Disk /dev/mapper/centos-swap: 2164 MB, 2164260864 bytes, 4227072 sectors Disk /dev/mapper/centos-root: 29.5 GB, 29519511552 bytes, 57655296 sectors
[root@server1 ~]# vgs VG #PV #LV #SN Attr VSize VFree VG_iscsi_Disk1 1 1 0 wz--n- 1020.00m 0 VG_iscsi_Disk2 1 1 0 wz--n- 10.00g 0 centos 1 2 0 wz--n- 29.51g 0 [root@server1 ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert lv_iscsi_Disk1 VG_iscsi_Disk1 -wi-a----- 1020.00m lv_iscsi_Disk2 VG_iscsi_Disk2 -wi-a----- 10.00g root centos -wi-ao---- 27.49g swap centos -wi-ao---- 2.02g
targetcli 설치 및 확인 :
# yum install targetcli
# targetcli --version /usr/bin/targetcli version 2.1.fb37
* target service 구동 :
# systemctl start target
targetcli 명령어로 쉘 스크립트 실행
[root@server1 ~]# targetcli targetcli shell version 2.1.fb37 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] />
backstores 구성
# Discover targets at a given IP address: iscsiadm --mode discoverydb --type sendtargets --portal 192.168.1.10 --discover #Login, must use a node record id found by the discovery: iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260 --login #Logout: iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260 --logout #List node records: iscsiadm --mode node #Display all data for a given node record: iscsiadm --mode node --targetname iqn.2001-05.com.doe:test --portal 192.168.1.1:3260