configuring target and iscsi-initiator in CentOS 7 with Example

Task: In desktop1, you are require to deploy iscsi (from server1) and create 1GB LVM. Finally, you should mount created logical volume to /data using UUID. Server1 is hosting iSCSI targets, where you have /dev/vdb of 2GB size.

In Server


1. Create partition of type LVM  of 1GB (I assume you can do it with fdisk)
fdisk /dev/vdb
partprobe
2. Create Volume Group
vgcreate vgsan1 /dev/vdb1
vgdisplay
3. Create logical volume (I am using 100% of VG that was created)
lvcreate -l 100%FREE -n lvsan1 vgsan1
lvdisplay
4. Now, you are ready to configure target, so use targetcli to config target
targetcli <enter>
a. create block
/> cd backstores/block
/…/block> create block1 /dev/vdb1
b. create iqn
/…/block>cd /iscsi
/…/iscsi> create iqn.2015-08.np.com.shiba:tg1
c. create acl (you should do it first, then only create luns and portals to minimize complication.
/…/iscsi>cd iqn.2015-08.np.com.shiba:tg1/tpg1
/…/tpg1> acl/ create iqn.2015-08.np.com.shiba:tg1/desktop1
d. create luns using the block you have created
/…/tpg1> luns/ create backstores/block/block1
e. create portal
/…/tpg1> portals/ create 192.168.122.58
/…/tpg1>exit

5. Allow port 3269/tcp in firewalld
firewall-cmd –add-port=3260/tcp –permanent
firewall-cmd –reload

Note: If you are hosting service in non-standard port  (using say: portals/ create 192.168.122.58 to_port 7002). You will have to add SELinux port label of iscsi_port_t to 7002 in both server and client (server1 and desktop1). and allod port 7002/tcp in firewall as well.


In desktop1:

1. change iqn entry in /etc/iscsi/initiatorname.iscsi file
echo “InitiatorName=iqn.2015-08.com.shiba:desktop1″ > /etc/iscsi/initiatorname.iscsi

2. restart iscsid service (don’t be confused with iscsi service)
systemctl restart iscsid

3. use man page of iscsiadm to get discovery command details. I am greping EXAMPLES and showing 15 lines after the match, where the examples are located. (replace IP and iqn in example with hour setting)
man iscsiadm | grep -A 10 “EXAMPLES”

4. Discover the iscsi target
iscsiadm –mode discoverydb –type sendtargets –portal 192.168.122.58 –discover
5. login to the iscsi target
iscsiadm –mode node –targetname iqn.2015-08.com.shiba:tg1 –portal 192.168.122.58:3260 –login
6. install lsscsi utility. and use it to identify iscsi device
yum -y install lsscsi
lsscsi
Note: will display iscsi details (say /dev/sdb1 is the device)
4. Create partition of 1GB using fdisk command and change type to 8e (I assume you can do it)
5. Create Volume Group of of /dev/sdb1. (If we don’t create Physical Volume, vgcreate will create physical volume automatically)
vgcreate vgiscsi1 /dev/sdb1
6. Create Create logical volume (100% of VG)
lvcreate -L 100%FREE -n lvscsi1 vgscsi1
7. Create /data directory and add entry to /etc/fstab
mkdir /data
blkid
#copy UUID of /vgscsi1
echo ” UUID=”28a7ee0a-b153-44ed-aeb1-06c9dfbaae52″  /data     xfs     _netdev 0 0″ >>/etc/fstab
Note: don’t use > redirection, it will flush all setting in /etc/fstab, if you are no confident, use vi to add above information. _netdev, will wait for network to start before mounting the device.
8. mount the device
mount -a
9. verify rebooting  if the device mounts or not automatically.

Leave a Reply

Your email address will not be published.


6 × six =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Recent Posts
Recent Comments
    Archives
    Categories
    Updates on Recent activieies
    Meta