Tuesday, June 14, 2016

RHEL7 - Configure iSCSI Initiator

Configure iSCSI Initiator on RHEL7

We successfully set up and configured iSCSI target. Now, we will configure the iSCSI

initiator on the client side to connect to the iSCSI target.

1. Install iscsi-initiator-utils lsscsi packages
# yum install iscsi-initiator-utils lsscsi -y

2. Since this is going to be iSCSI initiator, make sure you use the same initiatorname that

you use while configuring iSCSI target. If you change this from default to something else,

then you have to update the ACL on iSCSI target. Make sure they are same on server and

client.
# cat /etc/iscsi/initiatorname.iscsi

if it has been modified, restart the service
# systemctl restart iscsid
# systemctl status iscsid -l

3. Performing the Discovery
Now, lets perform a discovery against the IP address of the target server to see what iSCSI

target configuration is available. Note: iscsiadm command has different modes.

# iscsiadm --mode discovery --type sendtargets --portal 192.168.10.120 --discover
192.168.10.120:3260,1 iqn.2015-12.local.expanor:target

4. Upon a successful discovery, you can get more information about the target using the -P

option. This option shows details about the current mode. In all modes, the print levels 0

and 1 are supported.
# iscsiadm --mode discovery -P 1

5. Make a connection
Now, upon successful iSCSI discovery, you can log in to the target and make a connection

# iscsiadm -m node -T iqn.1026-12.local.expanor:target -l
or

# iscsiadm --mode node --targetname iqn.2016-12.local.expanor:target --portal 192.168.10.120:3260 --login

options detail
-m or --mode
This option specifies iscsiadm to enter into “node” mode where actual connection with the target can be established.

-T or --targetname
This option specifies the name of the target while discovered using the iSCSI discovery process.

-p or --portal
This option is to specify the target IP address and port

-l or --login
This option is to authenticate to the target and stores credentials as well. Connection can be re-established upon reboot.

Note: After successful login in to iSCSI target server, the connections are persistent. iscsid and iscsi services read the iSCSI configuration locally stored so connection is always automatic even on reboot.
If some reason, you don't want to connect to iSCSI target server after reboot, you have to login out to disconnect the session and delete the corresponding IQN subdirectory and all of its contents.

The command below will wipe out all the configuration.
# iscsiadm --mode node --targetname iqn.2016-12.local.expanor:target --logout
# iscsiadm --mode node --targetname 2016-12.local.expanor:target --op=delete

6. Display and review all active iSCSI sessions
# iscsiadm -m session -P 0

note:  You can change -P 0 to 1,2 or 3 for more information

7. Now, all iSCSI devices (block and fileio disks) shared from target server are available to iSCSI initiator. You use lsscsi, lsblk to list these devices along with LIO devices.

# lsscsi
# lsblk --scsi
# fdisk -l

Mounting iSCSI Devices

8. Now, you can create filesystem on presented disks.
Create XFS file system and get BLK id of the devices to find UUID.

# iscsiadm -m session -P3
# cat /proc/partitions

# mkfs.xfs /dev/sdc
# mkfs.xfs /dev/sdd
# mkfs.xfs /dev/sde

Note: Please understand the disk naming convention and know what disk you are using.

# blkid /dev/sdc
# blkid /dev/sdd
# blkid /dev/sde

9. Now, add entry to /etc/fstab and mount it.
# vi /etc/fstab
UUID=XXXXXXXX-XXXX-XXXX-XXXXXX /opt/iscsi1 xfs _netdev 0 2
add entry for all filesystem

# mkdir /opt/iscsi1 /opt/iscsi2 /opt/iscsi3
# grep -i iscsi /etc/fstab

# mount -a
# mount|grep iscsi
# df -hP | grep opt

10. Logout and disconnect
If you are done with your stuff and disconnect the session, perform the following tasks

a. unmount the filesystem
# umount /opt/iscsi1

b. Remove entry from /etc/fstab
# vi /etc/fstab

c. Log out and verify no active sessions are available
# iscsiadm -m node -u
# iscsiadm -m session -P 0

Help tips
# man 8 iscsiadm

Overview

- Configure the iSCSI target on the server and export the storage over the network.
- Set up an iSCSI initiator on a client system to connect to the target server.
- Upon connection, iSCSI initiator should be able to use the exported disk on client and use them like a local storage.


No comments:

Post a Comment