참고 페이지:https://wiki.rvijay.in/index.php/Configuring_iSCSI_target_using_targetcli
https://www.rootusers.com/how-to-configure-an-iscsi-target-and-initiator-in-linux/
http://atodorov.org/blog/2015/04/07/how-to-configure-iscsi-target-on-red-hat-enterprise-linux-7/
iscsi-server
targetcli 설치
[root@centos74 ~]# yum install -y targetcli
targetcli 실행
[root@centos74 ~]# systemctl start target
[root@centos74 ~]# targetcli Warning: Could not load preferences file /root/.targetcli/prefs.bin. targetcli shell version 2.1.fb46 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. />
몇가지가 더 있지만 자주 사용하는것 위주로 작성 하였습니다.
fileio: file 을 지정 ex) disk.img
block: block Device 를 지정 ex) lvm 및 /dev/sdb1
fileio Test 진행
[root@centos74 ~]# mkdir /images [root@centos74 ~]# targetcli /> backstores/fileio create disk1 /images/disk1.img 10G Created fileio disk1 with size 10737418240 />
/> 위치에서 생성을 해야 합니다. 위치 이동은 cd 명령어를 통하여 이동하실수 있습니다.
/> iscsi/ create iqn.2017-12.com.example:target1 Created target iqn.2017-12.com.example:target1. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /> cd iscsi/iqn.2017-12.com.example:target1/tpg1/ /iscsi/iqn.20...:target1/tpg1> ls 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/iqn.20...:target1/tpg1> portals/ create Using default IP port 3260 Binding to INADDR_ANY (0.0.0.0) This NetworkPortal already exists in configFS /iscsi/iqn.20...:target1/tpg1> luns/ create /backstores/fileio/disk1 Created LUN 0.
ACL Disable 및 read/write mode
/iscsi/iqn.20...:target1/tpg1> set attribute authentication=0 Parameter authentication is now '0'. /iscsi/iqn.20...:target1/tpg1> set attribute demo_mode_write_protect=0 Parameter demo_mode_write_protect is now '0'. /iscsi/iqn.20...:target1/tpg1> set attribute generate_node_acls=1 Parameter generate_node_acls is now '1'. /iscsi/iqn.20...:target1/tpg1> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json [root@centos74 ~]#
block Test 진행
/dev/sdb lvm Type 으로 지정 (별도로 지정 하지 않고 lvm 을 생성 하여도 무방합니다)
[root@centos74 ~]# fdisk -l 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 Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 Disk label type: dos Disk identifier: 0x000bfdf3 Device Boot Start End Blocks Id System /dev/sda1 * 2048 4196351 2097152 83 Linux /dev/sda2 4196352 12584959 4194304 82 Linux swap / Solaris /dev/sda3 12584960 83886079 35650560 83 Linux [root@centos74 ~]# fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x4f132fd5. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): 1 First sector (2048-20971519, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-20971519, default 20971519): Using default value 20971519 Partition 1 of type Linux and of size 10 GiB is set Command (m for help): t Selected partition 1 Hex code (type L to list all codes): 8e Changed type of partition 'Linux' to 'Linux LVM' Command (m for help): wq The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@centos74 ~]#
lvm 생성
[root@centos74 ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created. [root@centos74 ~]# vgcreate vg00 /dev/sdb1 Volume group "vg00" successfully created [root@centos74 ~]# [root@centos74 ~]# lvcreate -L 1G -n lv-vol1 vg00 Logical volume "lv-vol1" created. [root@centos74 ~]# lvcreate -L 1G -n lv-vol2 vg00 Logical volume "lv-vol2" created. [root@centos74 ~]# lvcreate -L 1G -n lv-vol3 vg00 Logical volume "lv-vol3" created. [root@centos74 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv-vol1 vg00 -wi-a----- 1.00g lv-vol2 vg00 -wi-a----- 1.00g lv-vol3 vg00 -wi-a----- 1.00g [root@centos74 ~]#
iscsi block Device 생성
[root@centos74 ~]# targetcli targetcli shell version 2.1.fb46 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> cd /backstores/block /> cd /backstores/block /backstores/block> create lv-vol1 /dev/vg00/lv-vol1 Created block storage object lv-vol1 using /dev/vg00/lv-vol1. /backstores/block> create lv-vol2 /dev/vg00/lv-vol2 Created block storage object lv-vol2 using /dev/vg00/lv-vol2. /backstores/block> create lv-vol3 /dev/vg00/lv-vol3 Created block storage object lv-vol3 using /dev/vg00/lv-vol3. /backstores/block>
wwn 생성 ( cd iscsi or iscsi/ create)
/iscsi> create iqn.2017-12.com.example:target2 Created target iqn.2017-12.com.example:target2. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /iscsi>
lun 생성
/iscsi> cd iqn.2017-12.com.example:target2/ /iscsi/iqn.20...ample:target2> ls o- iqn.2017-12.com.example:target2 .......................................................................... [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/iqn.20...ample:target2> cd tpg1/luns /iscsi/iqn.20...et2/tpg1/luns> create /backstores/block/lv-vol1 Created LUN 0. /iscsi/iqn.20...et2/tpg1/luns> create /backstores/block/lv-vol2 Created LUN 1. /iscsi/iqn.20...et2/tpg1/luns> create /backstores/block/lv-vol3 Created LUN 2. /iscsi/iqn.20...et2/tpg1/luns> /iscsi/iqn.20...et2/tpg1/luns> ls o- luns ..................................................................................................... [LUNs: 3] o- lun0 ...................................................... [block/lv-vol1 (/dev/vg00/lv-vol1) (default_tg_pt_gp)] o- lun1 ...................................................... [block/lv-vol2 (/dev/vg00/lv-vol2) (default_tg_pt_gp)] o- lun2 ...................................................... [block/lv-vol3 (/dev/vg00/lv-vol3) (default_tg_pt_gp)] /iscsi/iqn.20...et2/tpg1/luns>
ACL Disable 및 read/write mode
/iscsi/iqn.20...et2/tpg1/luns> cd /iscsi/iqn.20...:target2/tpg1> set attribute authentication=0 Parameter authentication is now '0'. /iscsi/iqn.20...:target2/tpg1> set attribute demo_mode_write_protect=0 Parameter demo_mode_write_protect is now '0'. /iscsi/iqn.20...:target2/tpg1> set attribute generate_node_acls=1 Parameter generate_node_acls is now '1'. /iscsi/iqn.20...:target2/tpg1> exit Global pref auto_save_on_exit=true Last 10 configs saved in /etc/target/backup. Configuration saved to /etc/target/saveconfig.json [root@centos74 ~]#
iscsi-Client
[root@centos7-test ~]# yum install -y iscsi-initiator-utils
fileio Test
iscsi lun 확인
[root@centos7-test ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.186.100 --discover 192.168.186.100:3260,1 iqn.2017-12.com.example:target1 [root@centos7-test ~]#
iscsi login
[root@centos7-test ~]# iscsiadm --mode node --targetname iqn.2017-12.com.example:target1 --portal 192.168.186.100 --login Logging in to [iface: default, target: iqn.2017-12.com.example:target1, portal: 192.168.186.100,3260] (multiple) Login to [iface: default, target: iqn.2017-12.com.example:target1, portal: 192.168.186.100,3260] successful. [root@centos7-test ~]#
scsi 확인
[root@centos7-test ~]# cat /proc/scsi/scsi Attached devices: Host: scsi2 Channel: 00 Id: 00 Lun: 00 Vendor: VMware, Model: VMware Virtual S Rev: 1.0 Type: Direct-Access ANSI SCSI revision: 02 Host: scsi4 Channel: 00 Id: 00 Lun: 00 Vendor: NECVMWar Model: VMware SATA CD01 Rev: 1.00 Type: CD-ROM ANSI SCSI revision: 05 Host: scsi34 Channel: 00 Id: 00 Lun: 00 Vendor: LIO-ORG Model: disk1 Rev: 4.0 Type: Direct-Access ANSI SCSI revision: 05 [root@centos7-test ~]#
fdisk 확인
[root@centos7-test ~]# fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 Disk label type: dos Disk identifier: 0x000bfdf3 Device Boot Start End Blocks Id System /dev/sda1 * 2048 4196351 2097152 83 Linux /dev/sda2 4196352 12584959 4194304 82 Linux swap / Solaris /dev/sda3 12584960 83886079 35650560 83 Linux 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 / 4194304 bytes [root@centos7-test ~]#
iscsi logout
[root@centos7-test ~]# iscsiadm --mode node --targetname iqn.2017-12.com.example:target1 --portal 192.168.186.100 -u Logging out of session [sid: 2, target: iqn.2017-12.com.example:target1, portal: 192.168.186.100,3260] Logout of [sid: 2, target: iqn.2017-12.com.example:target1, portal: 192.168.186.100,3260] successful. [root@centos7-test ~]# iscsiadm --mode node --targetname iqn.2017-12.com.example:target1 --portal 192.168.186.100 -o delete
fdisk 확인
[root@centos7-test ~]# fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 Disk label type: dos Disk identifier: 0x000bfdf3 Device Boot Start End Blocks Id System /dev/sda1 * 2048 4196351 2097152 83 Linux /dev/sda2 4196352 12584959 4194304 82 Linux swap / Solaris /dev/sda3 12584960 83886079 35650560 83 Linux [root@centos7-test ~]#
block Test
iscsi lun 확인
[root@centos7-test ~]# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.186.100 --discover 192.168.186.100:3260,1 iqn.2017-12.com.example:target1 192.168.186.100:3260,1 iqn.2017-12.com.example:target2 [root@centos7-test ~]#
iscsi login
[root@centos7-test ~]# iscsiadm --mode node --targetname iqn.2017-12.com.example:target2 --portal 192.168.186.100 --login Logging in to [iface: default, target: iqn.2017-12.com.example:target2, portal: 192.168.186.100,3260] (multiple) Login to [iface: default, target: iqn.2017-12.com.example:target2, portal: 192.168.186.100,3260] successful. [root@centos7-test ~]#
scsi 확인
[root@centos7-test ~]# cat /proc/scsi/scsi Attached devices: Host: scsi2 Channel: 00 Id: 00 Lun: 00 Vendor: VMware, Model: VMware Virtual S Rev: 1.0 Type: Direct-Access ANSI SCSI revision: 02 Host: scsi4 Channel: 00 Id: 00 Lun: 00 Vendor: NECVMWar Model: VMware SATA CD01 Rev: 1.00 Type: CD-ROM ANSI SCSI revision: 05 Host: scsi35 Channel: 00 Id: 00 Lun: 00 Vendor: LIO-ORG Model: lv-vol1 Rev: 4.0 Type: Direct-Access ANSI SCSI revision: 05 Host: scsi35 Channel: 00 Id: 00 Lun: 01 Vendor: LIO-ORG Model: lv-vol2 Rev: 4.0 Type: Direct-Access ANSI SCSI revision: 05 Host: scsi35 Channel: 00 Id: 00 Lun: 02 Vendor: LIO-ORG Model: lv-vol3 Rev: 4.0 Type: Direct-Access ANSI SCSI revision: 05 [root@centos7-test ~]#
fdisk 확인
[root@centos7-test ~]# fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 Disk label type: dos Disk identifier: 0x000bfdf3 Device Boot Start End Blocks Id System /dev/sda1 * 2048 4196351 2097152 83 Linux /dev/sda2 4196352 12584959 4194304 82 Linux swap / Solaris /dev/sda3 12584960 83886079 35650560 83 Linux Disk /dev/sdb: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 4194304 bytes Disk /dev/sdc: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 4194304 bytes Disk /dev/sdd: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 4194304 bytes [root@centos7-test ~]#
iscsi logout
[root@centos7-test ~]# iscsiadm --mode node --targetname iqn.2017-12.com.example:target2 --portal 192.168.186.100 -u Logging out of session [sid: 3, target: iqn.2017-12.com.example:target2, portal: 192.168.186.100,3260] Logout of [sid: 3, target: iqn.2017-12.com.example:target2, portal: 192.168.186.100,3260] successful. [root@centos7-test ~]# iscsiadm --mode node --targetname iqn.2017-12.com.example:target2 --portal 192.168.186.100 -o delete [root@centos7-test ~]#
fdisk 확인
[root@centos7-test ~]# fdisk -l Disk /dev/sda: 42.9 GB, 42949672960 bytes, 83886080 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 Disk label type: dos Disk identifier: 0x000bfdf3 Device Boot Start End Blocks Id System /dev/sda1 * 2048 4196351 2097152 83 Linux /dev/sda2 4196352 12584959 4194304 82 Linux swap / Solaris /dev/sda3 12584960 83886079 35650560 83 Linux [root@centos7-test ~]#
방화벽 사용시
[root@centos74 ~]# firewall-cmd --add-service=iscsi-target --permanent success [root@centos74 ~]# firewall-cmd --reload
추가적인 내용은 차후 정리하도록 하겠습니다.