We already showed you how to configure iSCSI target in your RHEL 7 or CentOS 7 machine and share the storage device to the client. In this article, we are going to see how to configure the iSCSI initiator in RHEL 7 / CentOS 7 and then use that storage to create and mount a file system.
This is very simple configuration and requires very fewer steps. You just have to install the iscsi-initiator-utils RPM and then discover the shared storage from the target. After that, login to the discovered target and create & mount your file system. Below are the steps.
Stpes to Configure iSCSI initiator in RHEL 7/CentOS 7
1. First of all, install iscsi-initiator-utils package.
# yum install iscsi-initiator-utils -y
2. Now enable and start the service.
[root@client1 ~]# systemctl enable iscsi.service [root@client1 ~]# systemctl start iscsi.service [root@client1 ~]#
3. Add initiator name to /etc/iscsi/initiatorname.iscsi file as shown below.
[root@client1 ~]# vi /etc/iscsi/initiatorname.iscsi [root@client1 ~]# [root@client1 ~]# cat /etc/iscsi/initiatorname.iscsi InitiatorName=iqn.2018-06.com.server:client2 [root@client1 ~]#
4. Now discover the target by using below command.
[root@client1 ~]# iscsiadm -m discovery -t st -p 192.168.1.16 –discover 192.168.1.16:3260,1 iqn.2018-06.com.server:client1.disk1 [root@client1 ~]#
The IP mentioned above is of the target server.
5. Once you have discovered the target, login to the target as shown below.
[root@client1 ~]# iscsiadm -m node -T iqn.2018-06.com.server:client1.disk1 -l Logging in to [iface: default, target: iqn.2018-06.com.server:client1.disk1, portal: 192.168.1.16,3260] (multiple) Login to [iface: default, target: iqn.2018-06.com.server:client1.disk1, portal: 192.168.1.16,3260] successful.
You can now verify if the disk is attached or not.
[root@client1 ~]# dmesg | tail [ 3356.968984] scsi 3:0:0:0: alua: supports implicit and explicit TPGS [ 3356.973742] scsi 3:0:0:0: alua: port group 00 rel port 01 [ 3356.974040] scsi 3:0:0:0: alua: port group 00 state A non-preferred supports TOlUSNA [ 3356.974043] scsi 3:0:0:0: alua: Attached [ 3356.974853] sd 3:0:0:0: Attached scsi generic sg2 type 0 [ 3357.001503] sd 3:0:0:0: [sdb] 401408 512-byte logical blocks: (205 MB/196 MiB) [ 3357.003386] sd 3:0:0:0: [sdb] Write Protect is off [ 3357.003391] sd 3:0:0:0: [sdb] Mode Sense: 43 00 00 08 [ 3357.004722] sd 3:0:0:0: [sdb] Write cache: disabled, read cache: enabled, doesn't support DPO or FUA [ 3357.036372] sd 3:0:0:0: [sdb] Attached SCSI disk [root@client1 ~]# [root@client1 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 205 MB, 205520896 bytes, 401408 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
6. Now you can create your filesystem and mount it. Here, for example, we are going to create a XFS filesystem and will mount it under /iscsi directory.
[root@client1 ~]# pvcreate /dev/sdb Physical volume "/dev/sdb" successfully created. [root@client1 ~]# vgcreate initiator_vg /dev/sdb Volume group "initiator_vg" successfully created [root@client1 ~]# [root@client1 ~]# mkfs.xfs /dev/initiator_vg/client1_lv meta-data=/dev/initiator_vg/client1_lv isize=512 agcount=4, agsize=12288 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=49152, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=855, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [root@client1 ~]# [root@client1 ~]# mkdir /iscsi [root@client1 ~]# mount -t xfs /dev/initiator_vg/client1_lv /iscsi [root@client1 ~]# df -hP /iscsi/ Filesystem Size Used Avail Use% Mounted on /dev/mapper/initiator_vg-client1_lv 189M 9.8M 179M 6% /iscsi [root@client1 ~]#
Logging out from the iSCSI initiator
First, unmount the file system and then logout. Please note that once you logout, you will get “Input/output error”.
[root@client1 ~]# iscsiadm -m node -T iqn.2018-06.com.server:client1.disk1 -u Logging out of session [sid: 1, target: iqn.2018-06.com.server:client1.disk1, portal: 192.168.1.16,3260] Logout of [sid: 1, target: iqn.2018-06.com.server:client1.disk1, portal: 192.168.1.16,3260] successful. [root@client1 ~]#
Troubleshooting iSCSI initiator
It may happen that you run into an issue and you are not able to discover the target and getting connection refused messages.
iscsiadm: cannot make connection to 192.168.1.16: Connection refused iscsiadm: cannot make connection to 192.168.1.16: Connection refused iscsiadm: cannot make connection to 192.168.1.16: Connection refused
1. Check at the target server that you have added 3260 port permanently to firewall rule.
2. If firewall rule is fine, check the portal in the target. Delete the existing portal containing the IP of the client server and add default portal i.e. 0.0.0.0:3260. Now restart the target service and retry to discover.
Check our article on setting up iSCSI target on RHEL 7 for fixing above to 2 issues.
Hope you like this article and now know how to configure iSCSI initiator in RHEL 7/CentOS 7. If you have any doubts or confusion, do let us know through your comments below.
Do not forget to Subscribe to our blog by Email and do share it on your social network.