Configure the iSCSI Server
1. Install the targetcli in iSCSI Server
[root@iscsiserver ~]# yum install targetcli
2. Enable and start the target service
[root@iscsiserver ~]# systemctl enable target; systemctl start target
3. Open SCSI server port on the firewall as permanent change and reload the configuration for immediate user
[root@iscsiserver ~]# firewall-cmd --permanent --add-port=3260/tcp [root@iscsiserver ~]# firewall-cmd --reload
4. We have a disk /dev/sdb (2GB) and we are going add that as a Backstores block device using targetcli tool.
[root@iscsiserver ~]# targetcli targetcli shell version 2.1.53 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> cd backstores/ /backstores> block/ create blocklun1 /dev/sdb Created block storage object blocklun1 using /dev/sdb. /backstores> ls o- backstores .................................................................................................. [...] o- block ...................................................................................... [Storage Objects: 1] | o- blocklun1 .......................................................... [/dev/sdb (2.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] /backstores>
5. Create a unique iSCSI qualified Name (IQN) for the target . IQN will be iqn.2021-12.com.example:iscsiserver
[root@iscsiserver ~]# targetcli targetcli shell version 2.1.53 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> iscsi/ create iqn.2021-12.com.example:iscsiserver Created target iqn.2021-12.com.example:iscsiserver. Created TPG 1. Global pref auto_add_default_portal=true Created default portal listening on all IPs (0.0.0.0), port 3260. /> ls iscsi/ o- iscsi ................................................................................................ [Targets: 1] o- iqn.2021-12.com.example:iscsiserver ................................................................... [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]
6. Create an ACL for the iscsiclient (initiator). The initiator will be connecting with the name iqn.2021-12.com.example:iscsiclient.
[root@iscsiserver ~]# targetcli targetcli shell version 2.1.53 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> iscsi/iqn.2021-12.com.example:iscsiserver/tpg1/acls create iqn.2021-12.com.example:iscsiclient Created Node ACL for iqn.2021-12.com.example:iscsiclient /> ls iscsi/ o- iscsi ........................................................................................ [Targets: 1] o- iqn.2021-12.com.example:iscsiserver ........................................................... [TPGs: 1] o- tpg1 ........................................................................... [no-gen-acls, no-auth] o- acls ...................................................................................... [ACLs: 1] | o- iqn.2021-12.com.example:iscsiclient .............................................. [Mapped LUNs: 0] o- luns ...................................................................................... [LUNs: 0] o- portals ................................................................................ [Portals: 1] o- 0.0.0.0:3260 ................................................................................. [OK]
7. Create the LUN under the target, the LUN should use the previously defined backing storage device name blocklun1.
[root@iscsiserver ~]# targetcli targetcli shell version 2.1.53 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> /iscsi/iqn.2021-12.com.example:iscsiserver/tpg1/luns create /backstores/block/blocklun1 Created LUN 0. Created LUN 0->0 mapping in node ACL iqn.2021-12.com.example:iscsiclient /> ls /iscsi/ o- iscsi ...................................................................................... [Targets: 1] o- iqn.2021-12.com.example:iscsiserver ......................................................... [TPGs: 1] o- tpg1 ......................................................................... [no-gen-acls, no-auth] o- acls .................................................................................... [ACLs: 1] | o- iqn.2021-12.com.example:iscsiclient ............................................ [Mapped LUNs: 1] | o- mapped_lun0 ....................................................... [lun0 block/blocklun1 (rw)] o- luns .................................................................................... [LUNs: 1] | o- lun0 ..............................................block/blocklun1 (/dev/sdb) (default_tg_pt_gp)] o- portals .............................................................................. [Portals: 1] o- 0.0.0.0:3260 ............................................................................... [OK]
8. Delete port 0.0.0.0:3260 and Configure the portal for the target to listen on specific IP Address 192.168.31.252.
[root@iscsiserver ~]# targetcli targetcli shell version 2.1.53 Copyright 2011-2013 by Datera, Inc and others. For help on commands, type 'help'. /> /iscsi/iqn.2021-12.com.example:iscsiserver/tpg1/portals delete 0.0.0.0 3260 Deleted network portal 0.0.0.0:3260 /> /iscsi/iqn.2021-12.com.example:iscsiserver/tpg1/portals create 192.168.31.252 3260 Using default IP port 3260 Created network portal 192.168.31.252:3260. /> ls iscsi/ o- iscsi ....................................................................................... [Targets: 1] o- iqn.2021-12.com.example:iscsiserver .......................................................... [TPGs: 1] o- tpg1 .......................................................................... [no-gen-acls, no-auth] o- acls ..................................................................................... [ACLs: 1] | o- iqn.2021-12.com.example:iscsiclient ............................................. [Mapped LUNs: 1] | o- mapped_lun0 ........................................................ [lun0 block/blocklun1 (rw)] o- luns ..................................................................................... [LUNs: 1] | o- lun0 ............................................. [block/blocklun1 (/dev/sdb) (default_tg_pt_gp)] o- portals ............................................................................... [Portals: 1] o- 192.168.31.252:3260 ......................................................................... [OK]
9. View the full configruation.
[root@iscsiserver ~]# targetcli 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: 1] | | o- blocklun1 ............................................ [/dev/sdb (2.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.2021-12.com.example:iscsiserver ................................................... [TPGs: 1] | o- tpg1 ................................................................... [no-gen-acls, no-auth] | o- acls .............................................................................. [ACLs: 1] | | o- iqn.2021-12.com.example:iscsiclient ...................................... [Mapped LUNs: 1] | | o- mapped_lun0 ................................................. [lun0 block/blocklun1 (rw)] | o- luns .............................................................................. [LUNs: 1] | | o- lun0 ...................................... [block/blocklun1 (/dev/sdb) (default_tg_pt_gp)] | o- portals ........................................................................ [Portals: 1] | o- 192.168.31.252:3260 .................................................................. [OK] o- loopback ............................................................................. [Targets: 0]
10. Exit and save the configuration to the default file /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
No comments:
Post a Comment