Thursday, June 2, 2016

How to configure ISCSI Server And Client in OEL 7.2





ISCSI Configuration in server and client


Server Side 


1 install   enable  and start targetcli
 yum install targetcli

systemctl enable targetcli

systemctl start targetcli

firewall-cmd --permanent --add-port=3260/tcp
firewall-cmd --reload 

2 creating partitions


[root@server Desktop]# fdisk -c /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xda7dd536.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-629145599, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-629145599, default 629145599): +5G

Command (m for help): w

[root@server Desktop]# partprobe -s /dev/sdb


3 Creating LVM


[root@server Desktop]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created
[root@server Desktop]# vgcreate /dev/sdb1 vol1
  /dev/sdb1: already exists in filesystem
  Run `vgcreate --help' for more information.
[root@server Desktop]# vgcreate vg1 /dev/sdb1 
  Volume group "vg1" successfully created
[root@server Desktop]# lvcreate -L 4.5G  -n lv1 vg1
  Logical volume "lv1" created.
  
[root@server Desktop]# lvs
  LV   VG   Attr       LSize Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  lv1  vg1  -wi-a----- 4.50g                   

4 Configuring TargetCLI

[root@server Desktop]# targetcli 

/> backstores/block create server:disk1 /dev/vg1/lv1 
Created block storage object server:disk1 using /dev/vg1/lv1.
/> iscsi/ create iqn.2016-06.local.server:server
Created target iqn.2016-06.local.server:server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/> iscsi/iqn.2016-06.local.server:server/tpg1/acls create iqn.2016-06.local.server:client
Created Node ACL for iqn.2016-06.local.server:client
/> iscsi/iqn.2016-06.local.server:server/tpg1/luns create /b
/backstores/block/server:disk1  /bin/                           /boot/                          
/> iscsi/iqn.2016-06.local.server:server/tpg1/luns create /backstores/block/server:disk1 
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2016-06.local.server:client
/> iscsi/iqn.2016-06.local.server:server/tpg1/portals create 192.168.56.102
Using default IP port 3260
Could not create NetworkPortal in configFS
/> iscsi/iqn.2016-06.local.server:server/tpg1/portals/0.0.0.0:3260 
/iscsi/iqn.20.../0.0.0.0:3260> 

/iscsi> ls
o- iscsi .............................................................................................................. [Targets: 1]
  o- iqn.2016-06.local.server:server ..................................................................................... [TPGs: 1]
    o- tpg1 ................................................................................................. [no-gen-acls, no-auth]
      o- acls ............................................................................................................ [ACLs: 1]
      | o- iqn.2016-06.local.server:client ........................................................................ [Mapped LUNs: 1]
      |   o- mapped_lun0 ............................................................................ [lun0 block/server:disk1 (rw)]
      o- luns ............................................................................................................ [LUNs: 1]
      | o- lun0 ................................................................................ [block/server:disk1 (/dev/vg1/lv1)]
      o- portals ...................................................................................................... [Portals: 1]
        o- 0.0.0.0:3260 ....................................................................................................... [OK]
/iscsi> cd ..
/> ls
exit








Client Side

[root@client ~]# yum install iscsi-initiator-utils      
[root@client ~]# vim /etc/iscsi/initiatorname.iscsi 

[root@client ~]# systemctl enable iscsi
[root@client ~]# systemctl start iscsi
[root@client ~]# iscsiadm -m discovery -t st -p 192.168.56.101
192.168.56.101:3260,1 iqn.2016-06.local.server:server
[root@client ~]# iscsiadm  -m node -T iqn.2016-06.local.server:server -p 192.168.56.101 -l
Logging in to [iface: default, target: iqn.2016-06.local.server:server, portal: 192.168.56.101,3260] (multiple)
Login to [iface: default, target: iqn.2016-06.local.server:server, portal: 192.168.56.101,3260] successful.
[root@client ~]# fdisk -c /dev/sdb
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (65528-9437183, default 65528): 
Using default value 65528
Last sector, +sectors or +size{K,M,G} (65528-9437183, default 9437183): +2G
Partition 1 of type Linux and of size 2 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@client ~]# partprobe -s /dev/sd
sda   sda1  sda2  sda3  sdb   sdb1  
[root@client ~]# partprobe -s /dev/sdb
/dev/sdb: msdos partitions 1
[root@client ~]# mkfs.xfs /dev/sdb1 
[root@client ~]# mkdir /mnt/trgt
[root@client ~]# mount -t xfs /dev/sd
sda   sda1  sda2  sda3  sdb   sdb1  
[root@client ~]# mount -t xfs /dev/sdb1 /mnt/trgt/