How to do remote block storage in CENTOS 7

In this entry, i will create a server and client storage connection using remote block storage.


term in this tutorial:-
1- Initiator - this is iSCSi client. it can be in term software or hardware client.
2- Target - this is iSCSi server. this is our storage.
3- ACL - Access control list. Permission access for the target@initiator
4- IQN - iSCSi qualified name. this is unique name to identify individual iSCSi target@initiator.
5- LUN - a type of storage resouce block device in our server.
6- Node - any iSCSi initiator or iSCSi target.
7- Portal - IP address on initiator @ target.


Task:-
1- Install the server storage. we will install targetcli
Server > yum -y install targetcli

dependencies for targetcli

2- run targetcli. we can use the normal folder command in targetcli (cd,ls,rm). (Blue color is in targetcli)
Server > targetcli
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.

/> ls
o- / ........................................................................................................... [...]
  o- backstores ................................................................................................ [...]
  | o- block .................................................................................... [Storage Objects: 0]
  | o- fileio ................................................................................... [Storage Objects: 0]
  | o- pscsi .................................................................................... [Storage Objects: 0]
  | o- ramdisk .................................................................................. [Storage Objects: 0]
  o- iscsi .............................................................................................. [Targets: 0]
  o- loopback ........................................................................................... [Targets: 0]
/> 

3- we will now create backing storage @ backstore. in this tutorial. i will use fileio with 100Mb of size.
  • block - a block device define on the server. eg: disk drive, partition, lvm.
  • fileio - create a file of specific size in the filesystemm.
  • pscsi - physical scsi. permits passthrough to physical scsi device connected to server.
  • ramdisk - create ramdisk device of specific size. not persistent data. data will lost when reboot.
/> cd /backstores/
/backstores> fileio/ create file1 /root/disk1_file 100M
Created fileio file1 with size 104857600
/backstores> 

4- Create IQN for the target. default TPC underneath IQN qill be created. iqn name can be manually assign or auto generated by targetcli.

/backstores> cd /iscsi/
/iscsi> create iqn.2018-01.com.example.remotedisk1
Created target iqn.2018-01.com.example.remotedisk1.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> ls
o- iscsi ......................................................... [Targets: 1]
  o- iqn.2018-01.com.example.remotedisk1 ............................ [TPGs: 1]
    o- tpg1 ............................................ [no-gen-acls, no-auth]
      o- acls ....................................................... [ACLs: 0]
      o- luns ....................................................... [LUNs: 0]
      o- portals ................................................. [Portals: 1]
        o- 0.0.0.0:3260 .................................................. [OK]
/iscsi> 

5- In the TPG, we will create ACL for the client node to be used later.

/iscsi> cd iqn.2018-01.com.example.remotedisk1/tpg1/
/iscsi/iqn.20...otedisk1/tpg1> acls/ create iqn.2018-01.com.example:desktop0
Created Node ACL for iqn.2018-01.com.example:desktop0
/iscsi/iqn.20...otedisk1/tpg1> ls
o- tpg1 ................................................ [no-gen-acls, no-auth]
  o- acls ........................................................... [ACLs: 1]
  | o- iqn.2018-01.com.example:desktop0 ...................... [Mapped LUNs: 0]
  o- luns ........................................................... [LUNs: 0]
  o- portals ..................................................... [Portals: 1]
    o- 0.0.0.0:3260 ...................................................... [OK]
/iscsi/iqn.20...otedisk1/tpg1> 

now we have both iqn for target and initiator.
target iqn: iqn.2018-01.com.example.remotedisk1.
initiator iqn: iqn.2018-01.com.example:desktop0

6- in the TPG, we will create a lun from the backtore we created before. this step will activate the backstore.

/iscsi/iqn.20...otedisk1/tpg1> luns/ create /backstores/fileio/file1 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2018-01.com.example:desktop0
/iscsi/iqn.20...otedisk1/tpg1> ls
o- tpg1 ................................................ [no-gen-acls, no-auth]
  o- acls ........................................................... [ACLs: 1]
  | o- iqn.2018-01.com.example:desktop0 ...................... [Mapped LUNs: 1]
  |   o- mapped_lun0 ................................. [lun0 fileio/file1 (rw)]
  o- luns ........................................................... [LUNs: 1]
  | o- lun0 ................................. [fileio/file1 (/root/disk1_file)]
  o- portals ..................................................... [Portals: 1]
    o- 0.0.0.0:3260 ...................................................... [OK]
/iscsi/iqn.20...otedisk1/tpg1> 

Now we have our LUN. yay!

7- now we need to setup the portal. portal are designed to listen ip address and ports. you can leave it as 0.0.0.0 like before for all ip..or you can specified the client ip. my client ip is 192.168.122.1


8- Exit taget cli
/iscsi/iqn.20...otedisk1/tpg1> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json

9- if your firewall is on. you need to add the port to exemption
Server> firewall-cmd --permanent --add-port=3260/tcp
Server> firewall-cmd reload

-------------------------------------------------------------------------------------------------------------------

lets move on to desktop side.

1- make sure you have iscsi initiator utils installed.
desktop > sudo yum install iscsi-initiator-utils
desktop > echo "InitiatorName=iqn.2018-01.com.example:desktop0" > etc/iscsi/initiatorname.iscsi
desktop > cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2018-01.com.example:desktop0
desktop > systemctl restart iscsi

2- now we will discover the storage iscsi from the server.

desktop > iscsiadm -m discovery -t sendtargets -p testserver:3260   ##testserver is my server name
192.168.122.203:3260,1 iqn.2018-01.com.example.remotedisk1

3- now login 
desktop> sudo iscsiadm -m node -T iqn.2018-01.com.example.remotedisk1 -p testserver -l
Logging in to [iface: default, target: iqn.2018-01.com.example.remotedisk1, portal: 192.168.122.203,3260] (multiple)
Login to [iface: default, target: iqn.2018-01.com.example.remotedisk1, portal: 192.168.122.203,3260] successful.

4- enjoy your new iSCSi disk. it will work just like internal storage. you can continue to format it.
desktop> lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 238.5G  0 disk 
├─sda1            8:1    0   500M  0 part 
├─sda2            8:2    0  48.3G  0 part 
├─sda3            8:3    0     1G  0 part /boot
├─sda4            8:4    0     1K  0 part 
└─sda5            8:5    0 188.7G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   7.5G  0 lvm  [SWAP]
  └─centos-home 253:2    0 131.1G  0 lvm  /home
sdb               8:16   0   100M  0 disk 


------------------------------------------------------------------------------------------------------------------

how to disconnect from iscsi target.


desktop > iscsiadm -m node -T iqn.2018-01.com.example.remotedisk1 -o delete
iscsiadm: This command will remove the record [iface: default, target: iqn.2018-01.com.example.remotedisk1, portal: 192.168.122.203,3260], but a session is using it. Logout session then rerun command to remove record.
iscsiadm: Could not execute operation on all records: session exists

to solve this problem, you can logout and relogin again. or else, you can disconnect the iscsi first before deleting it.

Desktop > iscsiadm -m node -T iqn.2018-01.com.example.remotedisk1 -p 192.168.122.203:3260 -u
Logging out of session [sid: 1, target: iqn.2018-01.com.example.remotedisk1, portal: 192.168.122.203,3260]
Logout of [sid: 1, target: iqn.2018-01.com.example.remotedisk1, portal: 192.168.122.203,3260] successful.

now you can delete it again.

desktop > iscsiadm -m node -T iqn.2018-01.com.example.remotedisk1 -o delete
desktop > lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0 238.5G  0 disk 
├─sda1            8:1    0   500M  0 part 
├─sda2            8:2    0  48.3G  0 part 
├─sda3            8:3    0     1G  0 part /boot
├─sda4            8:4    0     1K  0 part 
└─sda5            8:5    0 188.7G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   7.5G  0 lvm  [SWAP]
  └─centos-home 253:2    0 131.1G  0 lvm  /home



Comments