Configuring iSCSI Target on CentOS7


From many years the storage was attached to the servers & sharing staff was through network protocols as NFS “Network File System” or Samba. Nowadays the storage is separated from the physical server, which allows more flexibility in case of the physical server goes down another one is easily attached to the external storage of the failed one. That what SAN “Storage Area Networks” do.
Known iSCSI Terminologies:
Target: The service on an iSCSI server that gives access to backend storage devices.
Initiator: The iSCSI client that connects to an iSCSI target.
IQN: The iSCSI qualified Name, A unique name that is used to identify the iSCSI target.
Backend Storage: The storage devices on the iSCSI target & they are what the iSCSI target provides access to.
ACL: The Access Control List that is based on the iSCSI initiator and used to provide access to a specific target.
Portal: The IP address and port that the target or initiator uses to establish connection Known as “Node”.
LUN: Logical Unit Number, They are the backend storage devices that are shared through the target.
TPG: Target Portal Group, & it is the collection of IP address & TCP ports that iSCSI target will listen.
Discovery: The process that an initiator finds the targets that are configured on a portal.
For our environment we will use two VMs:
1- first VM is called & it will play the iSCSI Target role, attached to it 5 GB storage free.
2- Second VM has no requirements and it will play the iSCSI initiator role.
Creating the Logical volume:
First We need to create LVM on the free space on on the disk in my case called sdb

Type n to create a new partition. Select p to make it a primary partition and use the partition number as it is suggested as the default.

press Enter when asked for the first sector. once you are back on the Fdisk prompt, type t to change the partition type 8e to select LVM partition type then press w to write changes to disk.

Now as the partition is created, you need to flag it as LVM physical volume by typing the following command.

Next, verify that the physical volume has been created successfully.

or Type the following command for more details.

Now, proceed to create the Volume group, by giving it the name vgiscsi.

Setting up the iSCSI target:
Verify the name of LVM volume group and the amount of available disk space.

Provide the backing storage needed for setting up the iSCSI target which in our case we will use lvsan1 & lvsan2.

Now, install Targetcli package.

Open the targetcli interface and display the default interface.

Configure the backstore, by typing cd /backstores to enter the backstores branch of targetcli.
Next, assign the LVM logical volume that you have created earlier as the backstore in the iSCSI target.

Repeat the previous step for lvsan2.
Next, you will create a file-backed block device: fileio/ create file1 /root/diskfile1 100M
Now take an overview of the current configuration.

Next, you can start configuring the unique identifier for your iSCSI target. use cd /iscsi/
Next, create the IQN.
Note: Notice that the name of the IQN starts with year-month (in YY-MM notation) and is followed by the inversed DNS domain name. Make sure you respect this naming standard; otherwise, the IQN will not be created.

At this point, you can create an ACL in the TPG. Remember, you need to create ACLs as well to access the iSCSI target because, without ACLs, any iSCSI initiator will be denied access.
Now type tpg1/acls/ create , which creates a node ACL that allows server1 to access the IQN you just created.
Next, create the LUNs.

At last, verify what you have created so far.

At this point, you can create the portal. This connects the iSCSI configuration to the specific IP address of the iSCSI target server. To make this work, you need to ensure that the iSCSI target is on a fixed IP address. so add the following command tpg1/portals/ create
The configuration has now completed. Get back to the root of the configuration tree by using cd / and take an overview of the whole configuration.

Open the Firewall ports.
Now that the iSCSI target has been configured, you need to make sure that it can be accessed through the firewall and that the service is started automatically.

add the target port 3260/tcp to the firewall zone

At last you are done with your iSCSI target.

I am Egyptian, Working as System Admin & I am Fonded with Linux & Open sources.



Please enter your comment!
Please enter your name here