[root@server ~]# yum -y install targetcli
[root@server ~]# systemctl restart target
[root@server ~]# systemctl enable target
[root@server ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
Backstores 구조
/> 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]
Block 생성
/> backstores/block create name=test_block dev=/dev/sdb
Created block storage object test_block using /dev/sdb.
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ............................................ [Storage Objects: 1]
| | o- test_block .............. [/dev/sdb (10.0GiB) write-thru deactivated]
| | 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: 0]
o- loopback ................................................... [Targets: 0]
Fileio 생성
/> backstores/fileio create name=test_file file_or_dev=/root/fileA size=100M write_back=false
Created fileio test_file with size 104857600
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ............................................ [Storage Objects: 1]
| | o- test_block .............. [/dev/sdb (10.0GiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- fileio ........................................... [Storage Objects: 1]
| | o- test_file ........... [/root/fileA (100.0MiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- pscsi ............................................ [Storage Objects: 0]
| o- ramdisk .......................................... [Storage Objects: 0]
o- iscsi ...................................................... [Targets: 0]
o- loopback ................................................... [Targets: 0]
pscsi 생성
/> backstores/pscsi create name=test_pscsi dev=/dev/sdc
Note: block backstore recommended for SCSI block devices
Created pscsi storage object test_pscsi using /dev/sdc
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ............................................ [Storage Objects: 1]
| | o- test_block .............. [/dev/sdb (10.0GiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- fileio ........................................... [Storage Objects: 1]
| | o- test_file ........... [/root/fileA (100.0MiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- pscsi ............................................ [Storage Objects: 1]
| | o- test_pscsi ................................... [/dev/sdc deactivated]
| | o- alua ............................................. [ALUA Groups: 0]
| o- ramdisk .......................................... [Storage Objects: 0]
o- iscsi ...................................................... [Targets: 0]
o- loopback ................................................... [Targets: 0]
ramdisk 생성
/> backstores/ramdisk create name=test_ramdisk size=100M
Created ramdisk test_ramdisk with size 100M.
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ............................................ [Storage Objects: 1]
| | o- test_block .............. [/dev/sdb (10.0GiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- fileio ........................................... [Storage Objects: 1]
| | o- test_file ........... [/root/fileA (100.0MiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- pscsi ............................................ [Storage Objects: 1]
| | o- test_pscsi ................................... [/dev/sdc deactivated]
| | o- alua ............................................. [ALUA Groups: 0]
| o- ramdisk .......................................... [Storage Objects: 1]
| o- test_ramdisk ............................... [(100.0MiB) deactivated]
| o- alua ............................................. [ALUA Groups: 1]
| o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
o- iscsi ...................................................... [Targets: 0]
o- loopback ................................................... [Targets: 0]
ISCSI 연결 설정
/> /iscsi create wwn=iqn.2020-04.kr.co.redhat:server
Created target iqn.2020-04.kr.co.redhat:server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ............................................ [Storage Objects: 1]
| | o- test_block .............. [/dev/sdb (10.0GiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- fileio ........................................... [Storage Objects: 1]
| | o- test_file ........... [/root/fileA (100.0MiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- pscsi ............................................ [Storage Objects: 1]
| | o- test_pscsi ................................... [/dev/sdc deactivated]
| | o- alua ............................................. [ALUA Groups: 0]
| o- ramdisk .......................................... [Storage Objects: 1]
| o- test_ramdisk ............................... [(100.0MiB) deactivated]
| o- alua ............................................. [ALUA Groups: 1]
| o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
o- iscsi ...................................................... [Targets: 1]
| o- iqn.2020-04.kr.co.redhat:server ............................. [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]
o- loopback ................................................... [Targets: 0]
ISCSI ACL 설정
/> /iscsi/iqn.2020-04.kr.co.redhat:server/tpg1/acls create wwn=iqn.2020-04.kr.co.redhat:client
Created Node ACL for iqn.2020-04.kr.co.redhat:client
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ............................................ [Storage Objects: 1]
| | o- test_block .............. [/dev/sdb (10.0GiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- fileio ........................................... [Storage Objects: 1]
| | o- test_file ........... [/root/fileA (100.0MiB) write-thru deactivated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- pscsi ............................................ [Storage Objects: 1]
| | o- test_pscsi ................................... [/dev/sdc deactivated]
| | o- alua ............................................. [ALUA Groups: 0]
| o- ramdisk .......................................... [Storage Objects: 1]
| o- test_ramdisk ............................... [(100.0MiB) deactivated]
| o- alua ............................................. [ALUA Groups: 1]
| o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
o- iscsi ...................................................... [Targets: 1]
| o- iqn.2020-04.kr.co.redhat:server ............................. [TPGs: 1]
| o- tpg1 ......................................... [no-gen-acls, no-auth]
| o- acls .................................................... [ACLs: 1]
| | o- iqn.2020-04.kr.co.redhat:client ................ [Mapped LUNs: 0]
| o- luns .................................................... [LUNs: 0]
| o- portals .............................................. [Portals: 1]
| o- 0.0.0.0:3260 ............................................... [OK]
o- loopback ................................................... [Targets: 0]
LUN 설정
/> /iscsi/iqn.2020-04.kr.co.redhat:server/tpg1/luns create storage_object=/backstores/block/test_block lun=lun0
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2020-04.kr.co.redhat:client
/> /iscsi/iqn.2020-04.kr.co.redhat:server/tpg1/luns create storage_object=/backstores/fileio/test_file lun=lun1 add_mapped_luns=false
Created LUN 1.
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ............................................ [Storage Objects: 1]
| | o- test_block ................ [/dev/sdb (10.0GiB) write-thru activated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- fileio ........................................... [Storage Objects: 1]
| | o- test_file ............. [/root/fileA (100.0MiB) write-thru activated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- pscsi ............................................ [Storage Objects: 1]
| | o- test_pscsi ................................... [/dev/sdc deactivated]
| | o- alua ............................................. [ALUA Groups: 0]
| o- ramdisk .......................................... [Storage Objects: 1]
| o- test_ramdisk ............................... [(100.0MiB) deactivated]
| o- alua ............................................. [ALUA Groups: 1]
| o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
o- iscsi ...................................................... [Targets: 1]
| o- iqn.2020-04.kr.co.redhat:server ............................. [TPGs: 1]
| o- tpg1 ......................................... [no-gen-acls, no-auth]
| o- acls .................................................... [ACLs: 1]
| | o- iqn.2020-04.kr.co.redhat:client ................ [Mapped LUNs: 1]
| | o- mapped_lun0 ...................... [lun0 block/test_block (rw)]
| o- luns .................................................... [LUNs: 2]
| | o- lun0 ........... [block/test_block (/dev/sdb) (default_tg_pt_gp)]
| | o- lun1 ........ [fileio/test_file (/root/fileA) (default_tg_pt_gp)]
| o- portals .............................................. [Portals: 1]
| o- 0.0.0.0:3260 ............................................... [OK]
o- loopback ................................................... [Targets: 0]
LUN 설정 2
/> /iscsi/iqn.2020-04.kr.co.redhat:server/tpg1/acls/iqn.2020-04.kr.co.redhat:client create mapped_lun=1 tpg_lun_or_backstore=/backstores/fileio/test_file write_protect=1
Created Mapped LUN 1.
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ............................................ [Storage Objects: 1]
| | o- test_block ................ [/dev/sdb (10.0GiB) write-thru activated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- fileio ........................................... [Storage Objects: 1]
| | o- test_file ............. [/root/fileA (100.0MiB) write-thru activated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- pscsi ............................................ [Storage Objects: 1]
| | o- test_pscsi ................................... [/dev/sdc deactivated]
| | o- alua ............................................. [ALUA Groups: 0]
| o- ramdisk .......................................... [Storage Objects: 1]
| o- test_ramdisk ............................... [(100.0MiB) deactivated]
| o- alua ............................................. [ALUA Groups: 1]
| o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
o- iscsi ...................................................... [Targets: 1]
| o- iqn.2020-04.kr.co.redhat:server ............................. [TPGs: 1]
| o- tpg1 ......................................... [no-gen-acls, no-auth]
| o- acls .................................................... [ACLs: 1]
| | o- iqn.2020-04.kr.co.redhat:client ................ [Mapped LUNs: 2]
| | o- mapped_lun0 ...................... [lun0 block/test_block (rw)]
| | o- mapped_lun1 ...................... [lun1 fileio/test_file (ro)]
| o- luns .................................................... [LUNs: 2]
| | o- lun0 ........... [block/test_block (/dev/sdb) (default_tg_pt_gp)]
| | o- lun1 ........ [fileio/test_file (/root/fileA) (default_tg_pt_gp)]
| o- portals .............................................. [Portals: 1]
| o- 0.0.0.0:3260 ............................................... [OK]
o- loopback ................................................... [Targets: 0]
Portal 설정
/> /iscsi/iqn.2020-04.kr.co.redhat:server/tpg1/portals/ delete ip_address=0.0.0.0 ip_port=3260
Deleted network portal 0.0.0.0:3260
/> /iscsi/iqn.2020-04.kr.co.redhat:server/tpg1/portals create 192.168.10.10
Using default IP port 3260
Created network portal 192.168.10.10:3260.
/> /iscsi/iqn.2020-04.kr.co.redhat:server/tpg1/portals create 192.168.10.20
Using default IP port 3260
Created network portal 192.168.10.20:3260.
/> ls
o- / ................................................................... [...]
o- backstores ........................................................ [...]
| o- block ............................................ [Storage Objects: 1]
| | o- test_block ................ [/dev/sdb (10.0GiB) write-thru activated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- fileio ........................................... [Storage Objects: 1]
| | o- test_file ............. [/root/fileA (100.0MiB) write-thru activated]
| | o- alua ............................................. [ALUA Groups: 1]
| | o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
| o- pscsi ............................................ [Storage Objects: 1]
| | o- test_pscsi ................................... [/dev/sdc deactivated]
| | o- alua ............................................. [ALUA Groups: 0]
| o- ramdisk .......................................... [Storage Objects: 1]
| o- test_ramdisk ............................... [(100.0MiB) deactivated]
| o- alua ............................................. [ALUA Groups: 1]
| o- default_tg_pt_gp ................. [ALUA state: Active/optimized]
o- iscsi ...................................................... [Targets: 1]
| o- iqn.2020-04.kr.co.redhat:server ............................. [TPGs: 1]
| o- tpg1 ......................................... [no-gen-acls, no-auth]
| o- acls .................................................... [ACLs: 1]
| | o- iqn.2020-04.kr.co.redhat:client ................ [Mapped LUNs: 2]
| | o- mapped_lun0 ...................... [lun0 block/test_block (rw)]
| | o- mapped_lun1 ...................... [lun1 fileio/test_file (ro)]
| o- luns .................................................... [LUNs: 2]
| | o- lun0 ........... [block/test_block (/dev/sdb) (default_tg_pt_gp)]
| | o- lun1 ........ [fileio/test_file (/root/fileA) (default_tg_pt_gp)]
| o- portals .............................................. [Portals: 2]
| o- 192.168.10.10:3260 ......................................... [OK]
| o- 192.168.10.20:3260 ......................................... [OK]
o- loopback ................................................... [Targets: 0]
방화벽 설정
[root@server ~]# firewall-cmd --permanent --zone=public --add-port=3260/tcp success [root@server ~]# firewall-cmd --reload success
ISCSI 클라이언트 설정
[root@client samba]# yum -y install iscsi-initiator-utils [root@client ~]# vi /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2020-04.kr.co.redhat:client [root@client ~]# systemctl restart iscsi [root@client ~]# systemctl enable iscsi
로그인
[root@client ~]# iscsiadm -m node -T iqn.2020-04.kr.co.redhat:server -l Logging in to [iface: default, target: iqn.2020-04.kr.co.redhat:server, portal: 192.168.10.10,3260] (multiple) Logging in to [iface: default, target: iqn.2020-04.kr.co.redhat:server, portal: 192.168.10.20,3260] (multiple) Login to [iface: default, target: iqn.2020-04.kr.co.redhat:server, portal: 192.168.10.10,3260] successful.
세션 확인
[root@client ~]# iscsiadm -m session -P 3 iSCSI Transport Class version 2.0-870 version 6.2.0.874-10 Target: iqn.2020-04.kr.co.redhat:server (non-flash) Current Portal: 192.168.10.10:3260,1 Persistent Portal: 192.168.10.10:3260,1 ********** Interface: ********** Iface Name: default Iface Transport: tcp Iface Initiatorname: iqn.2020-04.kr.co.redhat:client Iface IPaddress: 192.168.10.20 Iface HWaddress: <empty> Iface Netdev: <empty> SID: 1 iSCSI Connection State: LOGGED IN iSCSI Session State: LOGGED_IN Internal iscsid Session State: NO CHANGE ********* Timeouts: ********* Recovery Timeout: 120 Target Reset Timeout: 30 LUN Reset Timeout: 30 Abort Timeout: 15 ***** CHAP: ***** username: <empty> password: ******** username_in: <empty> password_in: ******** ************************ Negotiated iSCSI params: ************************ HeaderDigest: None DataDigest: None MaxRecvDataSegmentLength: 262144 MaxXmitDataSegmentLength: 262144 FirstBurstLength: 65536 MaxBurstLength: 262144 ImmediateData: Yes InitialR2T: Yes MaxOutstandingR2T: 1 ************************ Attached SCSI devices: ************************ Host Number: 3 State: running scsi3 Channel 00 Id 0 Lun: 0 Attached scsi disk sdd State: running scsi3 Channel 00 Id 0 Lun: 1 Attached scsi disk sde State: running
로그아웃
[root@client ~]# iscsiadm -m node -T iqn.2020-04.kr.co.redhat:server -u Logging out of session [sid: 1, target: iqn.2020-04.kr.co.redhat:server, portal: 192.168.10.10,3260] Logout of [sid: 1, target: iqn.2020-04.kr.co.redhat:server, portal: 192.168.10.10,3260] successful.
파티션 생성 후 사용
[root@client ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 30G 0 disk ├─sda1 8:1 0 1G 0 part /boot └─sda2 8:2 0 29G 0 part ├─centos-root 253:0 0 27G 0 lvm / └─centos-swap 253:1 0 2G 0 lvm [SWAP] sdb 8:16 0 10G 0 disk sdc 8:32 0 10G 0 disk sdd 8:48 0 10G 0 disk └─sdd1 8:49 0 10G 0 part << iscsi 서버하드 sde 8:64 0 100M 1 disk sr0 11:0 1 4.3G 0 rom /run/media/root/CentOS 7 x86_64 [root@client ~]# mkdir /mnt/iscsi [root@client ~]# mount /dev/sdd1 /mnt/iscsi/ [root@client ~]# df -hT Filesystem Type Size Used Avail Use% Mounted on devtmpfs devtmpfs 894M 0 894M 0% /dev tmpfs tmpfs 910M 0 910M 0% /dev/shm tmpfs tmpfs 910M 11M 900M 2% /run tmpfs tmpfs 910M 0 910M 0% /sys/fs/cgroup /dev/mapper/centos-root xfs 27G 4.4G 23G 17% / /dev/sda1 xfs 1014M 232M 783M 23% /boot 192.168.10.10:/share/nfs nfs4 27G 4.3G 23G 16% /mnt/nfsclient tmpfs tmpfs 182M 4.0K 182M 1% /run/user/42 tmpfs tmpfs 182M 24K 182M 1% /run/user/0 /dev/sr0 iso9660 4.3G 4.3G 0 100% /run/media/root/CentOS 7 x86_64 //192.168.10.10/share cifs 27G 4.3G 23G 16% /mnt/samba /dev/sdd1 ext4 9.8G 37M 9.2G 1% /mnt/iscsi << 정상 mount 확인