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
2. Create Volume Group
vgcreate vgsan1 /dev/vdb1
3. Create logical volume (I am using 100% of VG that was created)
lvcreate -l 100%FREE -n lvsan1 vgsan1
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
c. create acl (you should do it first, then only create luns and portals to minimize complication.
/…/tpg1> acl/ create
d. create luns using the block you have created
/…/tpg1> luns/ create backstores/block/block1
e. create portal
/…/tpg1> portals/ create

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 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 “″ > /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 –discover
5. login to the iscsi target
iscsiadm –mode node –targetname –portal –login
6. install lsscsi utility. and use it to identify iscsi device
yum -y install 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
#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.

× 7 = fifty 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
    Updates on Recent activieies