Remote Block Storage
Define iSCSI.Its Principle
Getting ready
$ vagrant up
$ vagrant ssh
How to do it
From the man pages targetcli, it administration shell for storage targets. Note :Now create LVM Disk without create file system
Installing/Creating/providing iSCSI target in server
$ sudo yum install targetcli
$ sudo systemctl enable target.service
$ sudo systemctl start target.service
$ sudo firewall-cmd --add-port=3260/tcp --permanent
$ sudo firewall-cmd --reload
$ sudo targetcli
targetcli shell version 2.1.fb41
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> cd backstores/block
/backstores/block> create iscsiblock /dev/vg2/iscsistorage
Created block storage object iscsiblock using /dev/vg2/iscsistorage.
/backstores/block> cd /iscsi
/iscsi> create iqn.2016-10.example.com:centos7server
Created target iqn.2016-10.example.com:centos7server.
Created TPG 1.
Global pref auto_add_default_portal=true
Created default portal listening on all IPs (0.0.0.0), port 3260.
/iscsi> cd iqn.2016-10.example.com:centos7server/tpg1/acls
/iscsi/iqn.20.../tpg1/acls> create iqn.2016-10.example.com:centos7client
Created Node ACL for iqn.2016-10.example.com:centos7client
/iscsi/iqn.20...server/tpg1/acls> cd ../luns
/iscsi/iqn.20...server/tpg1/luns> create /backstores/block/iscsiblock
Created LUN 0.
Created LUN 0->0 mapping in node ACL iqn.2016-10.example.com:centos7client
/iscsi/iqn.20.../tpg1/portals> delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/iscsi/iqn.20.../tpg1/portals> create 192.168.56.102
Using default IP port 3260
Created network portal 192.168.56.102:3260.
/iscsi/iqn.20.../tpg1/portals> cd /
/> saveconfig
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
/> exit
Global pref auto_save_on_exit=true
Last 10 configs saved in /etc/target/backup.
Configuration saved to /etc/target/saveconfig.json
$ sudo 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: 1]
| | o- iscsiblock ...... [/dev/vg2/iscsistorage (2.0GiB) write-thru activated]
| o- fileio ............................................. [Storage Objects: 0]
| o- pscsi .............................................. [Storage Objects: 0]
| o- ramdisk ............................................ [Storage Objects: 0]
o- iscsi ........................................................ [Targets: 1]
| o- iqn.2016-10.example.com:centos7server ........................ [TPGs: 1]
| o- tpg1 ........................................... [no-gen-acls, no-auth]
| o- acls ...................................................... [ACLs: 1]
| | o- iqn.2016-10.example.com:centos7client ........... [Mapped LUNs: 1]
| | o- mapped_lun0 ........................ [lun0 block/iscsiblock (rw)]
| o- luns ...................................................... [LUNs: 1]
| | o- lun0 ................... [block/iscsiblock (/dev/vg2/iscsistorage)]
| o- portals ................................................ [Portals: 1]
| o- 192.168.56.102:3260 .......................................... [OK]
o- loopback ..................................................... [Targets: 0]
$ sudo systemctl restart target.service
Acessing iSCSI target in Client
Install the package
$ sudo yum install iscsi-initiator-utils
$ sudo systemctl enable iscsid
Created symlink from /etc/systemd/system/multi-user.target.wants/iscsid.service to /usr/lib/systemd/system/iscsid.service.
$ iscsiadm -m discovery -t st -p 192.168.56.102
192.168.56.102:3260,1 iqn.2016-10.example.com:centos7server
$ sudo vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2016-10.example.com:centos7client
~
~
~
~
~
~
"/etc/iscsi/initiatorname.iscsi" 1L, 53C 1,1 All
$ sudo iscsiadm -m node -T iqn.2016-10.example.com:centos7server -p 192.168.56.102 -l
Logging in to [iface: default, target: iqn.2016-10.example.com:centos7server, portal: 192.168.56.102,3260] (multiple)
Login to [iface: default, target: iqn.2016-10.example.com:centos7server, portal: 192.168.56.102,3260] successful.
Providing Block Based Storage in Client
fdisk -l
Disk /dev/sda: 12.8 GB, 12815622144 bytes, 25030512 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x0007d98e
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 1026047 512000 83 Linux
/dev/sda2 1026048 25028607 12001280 8e Linux LVM
Disk /dev/mapper/centos-root: 11.0 GB, 10959716352 bytes, 21405696 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/mapper/centos-swap: 1283 MB, 1283457024 bytes, 2506752 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk /dev/sdb: 2147 MB, 2147483648 bytes, 4194304 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 33550336 bytes
# fdisk /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 0x0c52d8d7.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p):
Using default response p
Partition number (1-4, default 1):
First sector (65528-4194303, default 65528):
Using default value 65528
Last sector, +sectors or +size{K,M,G} (65528-4194303, default 4194303): +1500M
Partition 1 of type Linux and of size 1.5 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
$ sudo mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=256 agcount=4, agsize=96245 blks
= sectsz=512 attr=2, projid32bit=1
= crc=0 finobt=0
data = bsize=4096 blocks=384977, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=0
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
$ sudo mkdir /iscsiblock
$ sudo vim /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue May 24 14:32:56 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root / xfs defaults 0 0
UUID=f0065d52-3f43-4efb-ba1d-04d966062799 /boot xfs defaults 0 0
/dev/mapper/centos-swap swap swap defaults 0 0
//192.168.56.102/devops /sambadate cifs credentials=/root/multi-user.txt,multiuser,sec=ntlmssp 0 0
/dev/sdb1 /iscsiblock xfs _netdev 0 0
$ sudo mount -a
$ df -TH
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/centos-root xfs 11G 1.1G 9.9G 10% /
devtmpfs devtmpfs 799M 0 799M 0% /dev
tmpfs tmpfs 809M 0 809M 0% /dev/shm
tmpfs tmpfs 809M 8.8M 801M 2% /run
tmpfs tmpfs 809M 0 809M 0% /sys/fs/cgroup
/dev/sda1 xfs 521M 128M 394M 25% /boot
tmpfs tmpfs 162M 0 162M 0% /run/user/0
//192.168.56.102/devops cifs 14G 5.7G 7.8G 43% /sambadate
/dev/sdb1 xfs 1.6G 34M 1.6G 3% /iscsiblock