Computer man
Configure iSCSI Target

Configure Storage Server with iSCSI.

[iSCSI Target] |192.0.0.20 ---------------- 192.0.0.30| [iSCSI Initiator]
Server.example.com <---------------------> Client.example.com

Configure iSCSI Target:-

[root@server ~]# yum install targetcli -y
[root@server ~]# systemctl start target
[root@server ~]# systemctl enable target

Now we can run the targetcli command.

[root@server ~]# targetcli
/> 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]

Creating a Backstore

/> backstores/fileio create filetest /tmp/fileio 500M write_back=false
Created fileio filetest with size 524288000
/> backstores/block create name=block dev=/dev/sdb
Created block storage object block using /dev/sdb.

By ‘ls’ command the backstores should be listed.


/> ls
o- / ...................................................... [...]
o- backstores ........................................... [...]
| o- block ............................... [Storage Objects: 1]
| | o- block ....... [/dev/sdc (1.0GiB) write-thru deactivated]
| o- fileio .............................. [Storage Objects: 1]
| | o- filetest .. [/tmp/filetest (500.0MiB) write-thru deactivated]
| o- pscsi ............................... [Storage Objects: 0]
| o- ramdisk ............................. [Storage Objects: 0]
o- iscsi ......................................... [Targets: 0]
o- loopback ...................................... [Targets: 0]

Create the iSCSI Target and Portal

/> iscsi/
/iscsi> create iqn.2020-04.example.com:taget
Created target iqn.2020-04.example.com:taget.
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.2020-04.example.com:taget ..... [TPGs: 1]
o- tpg1 ................ [n
o-gen-acls, n
o-auth]
o- acls ........................... [ACLs: 0]
o- luns ........................... [LUNs: 0]
o- portals ..................... [Portals: 1]
o- 0.0.0.0:3260 ...................... [OK]

#Create LUN
/iscsi> iqn.2020-04.example.com:taget/tpg1/
/iscsi/iqn.20...m:target/tpg1> luns/ create /backstores/fileio/filetest Created LUN 0.

/iscsi/iqn.20...m:target/tpg1> luns/ create /backstores/block/block Created LUN 1.

Create an ACL

Now we need to configure an access control list (ACL) to define the initiators that are actually allowed to connect to the iSCSI target.

To do this, go to the client system that will be our iSCSI initiator and get the contents of the /etc/iscsi/initiatorname.iscsi file – you can edit this file if you want, otherwise the default is fine.

[root@client ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2020-04.example.com

Now that we have the name of our initiator from the client system, we enter the ACL section on the server within the TPG.

/iscsi/iqn.20...m:target/tpg1> acls/
/iscsi/iqn.20...get/tpg1/acls> create iqn.2020-04.example.com
Created Node ACL for
iqn.2020-04.example.com
Created mapped LUN 1.
Created mapped LUN 0.

Saving Changes

To save the configuration, simply exit

/iscsi/iqn.20...get/tpg1/acls> cd ../..
/iscsi/iqn.20...m:target> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

iSCSI Firewall Rules

[root@server ~]# netstat -antup | grep 3260
tcp 0 0 0.0.0.0:3260 0.0.0.0:* LISTEN -
[root@server ~]# firewall-cmd --permanent --add-port=3260/tcp
success
[root@server ~]# firewall-cmd --reload
success

Configure iSCSI Initiator:-

[root@client ~]# yum install iscsi-initiator-utils -y
[root@client ~]# systemctl enable iscsid iscsi
[root@client ~]# systemctl start iscsid iscsi

Now we need to discover iSCSI targets then login

[root@client ~]# iscsiadm --mode discovery --type sendtargets --portal 192.0.0.0
192.0.0.0:3260,1
iqn.2020-04.example.com

[root@client ~]# iscsiadm -m node -T iqn.2020-04.example.com -l
Logging in to [iface: default, target: iqn.2020-04.example.com, portal: 192.0.0.0,3260] (multiple)
Login to [iface: default, target: iqn.2020-04.example.com, portal: 192.0.0.0,3260] successful.

we can view all active iSCSI sessions as shown below.

[root@client]# iscsiadm -m session -P 0
tcp: [1] 192.0.0.0:3260,1 iqn.2020-04.example.com:target (non-flash)

format with XFS

[root@client ~]# mkfs.xfs /dev/sdb

[root@client ~]# mount /dev/sdb /mnt

[root@client ~]# df -h | grep mnt
Filesystem Size Used Avail Use% Mounted on
/dev/sdb 500M 11M 489M 4% /mnt

In order to log out of the iSCSI target, first unmount the disks then perform the actual log out

[root@client /]# umount /mnt

[root@client ~]# iscsiadm -m node -u
Logging out of session [sid: 1, target: iqn.2020-04.example.com:target, portal: 192.0.0.0,3260]
Logout of [sid: 1, target: iqn.2020-04.example.com:target, portal: 192.0.0.0,3260] successful.
Please email me if you face any issue.

Name:

Email:

Comments:

views
PHP Hits Count