Sunday, December 27, 2020

How to Configure iSCSI Storage in CentOS

Prerequisites 

  • Two Linux servers with OS centos 7.
    • server.example.com - 192.168.10.17
    • desktop.example.com - 192.168.10.18
  • "/etc/hosts" entry should be added on both servers.

  • server.example.com should have additional disk for iSCSI.

Configure iSCSI Server

Step 1: Install "targetcli.noarch" package on server host and enable the service.

# yum install targetcli.noarch
# systemctl enable target
# systemctl start target


Step 2: Create iSCSI partition

# fdisk /dev/sdb


Step 3: Create block device with name data_block

    # targetcli 
/> backstores/block create name=data_block dev=/dev/sdb1
/> iscsi/ create iqn.2020-12.com.example:server
/> iscsi/iqn.2020-12.com.example:server/tpg1/acls create iqn.2020-12.com.example:desktop
/> iscsi/iqn.2020-12.com.example:server/tpg1/luns create /backstores/block/data_block
/> saveconfig
/> exit 
 

Configure ISCSI Initiator

Step 1: Install "iscsi-initiator-utils.x86_64" package on desktop server.

# yum install iscsi-initiator-utils.x86_64

Step 2: Put below content to "/etc/iscsi/initiatorname.iscsi" this file.

InitiatorName=iqn.2020-12.com.example:desktop


Step 3: To verify the iSCSI initiator working fine, execute below command.

# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.10.17 --discover
 

Step 4: Attached iSCSI device

Before attached output of "lsblk" command.


Execute below command to attache 

# iscsiadm --mode node --targetname  iqn.2020-12.com.example:server --portal 192.168.10.17:3260 --login

Verify whether iSCSI device is attached or not using "lsblk" command.


Now you can use this iSCSI device to store your data. Before that you have to format and mount to your server.
  • Create Partition
  • Format the Partition
  • Mount partition with fstab.
Add below entry to "/etc/fstab". UUID you can get from blkid command.

UUID="a6376d6c-25dd-4224-9c33-5a318c0d41e6" /mnt/iSCSI        ext4     _netdev,defaults        0 0


Now execute "mount -a" command to mount the partition.

No comments:

Post a Comment