Linux CentOS 7 - iSCSI configuration
Configure the following target on system1: iqn.2019-06.com.example.system1 with 3 GB partition
Configure on system2 an initiator iqn.2019-06.com.example.system2 and automatically mount the iSCSI partion.
On system1
View the partitionsfdisk -l
If there is no space on the present disk, add a new disk.
Configure the new disk.
# fdisk /dev/sdb
n for new
p for primary
1 as the number
first sector: accept default value;
last sector: +4GB
t for type
code 8e for LVM
p to show the configured partition
w to write the configuration and make it permanent
Tell the kernel about the new parttion
# partprobe /dev/sdb
Create a new physical volume
# pvcreate /dev/sdb1
Create a new volume group
# vgcreate vg1 /dev/sdb1
Create a new logical volume
#lvcreate -n lvm1 -l 100%VG vg1
Install packages for target configuration
# yum install -y targetcli
Enable and strart the target service
# systemctl enable target && systemctl start target
Configure the iSCSI target
# targetcli
Configure the block
cd /backstores/block> create block1 /dev/vg1/lvm1
Configure the iscsi target
cd iscsi> create iqn.2019-06.com.example:system1
Configure the ACL
cd iqn.2019-06.com.example:system1/tpg1/acls> create qn.2019-06.com.example:system2
Configure the LUN
cd luns> create /backstores/block/block1
Configure the portal
cd portals> delete 0.0.0.0 3260
create 192.168.189.140:3260
Go to root directory and see the result:
ls
/> ls
o- / ......................................................................................................................... [...]
o- backstores ....................................................................................................... [...]
| o- block .................................................................................... [Storage Objects: 1]
| | o- block1 .......................................... [/dev/vg1/lv1 (2.8GiB) write-thru activated]
| | o- alua ..................................................................................... [ALUA Groups: 1]
| | o- default_tg_pt_gp .......................................... [ALUA state: Active/optimized]
| o- fileio ....................................................................................... [Storage Objects: 0]
| o- pscsi ........................................................................................ [Storage Objects: 0]
| o- ramdisk ................................................................................... [Storage Objects: 0]
o- iscsi ......................................................................................................... [Targets: 1]
| o- iqn.2019-06.com.example:system1 ......................................................... [TPGs: 1]
| o- tpg1 .................................................................................... [no-gen-acls, no-auth]
| o- acls ....................................................................................................... [ACLs: 1]
| | o- iqn.2019-06.com.example:system2 ...................................... [Mapped LUNs: 1]
| | o- mapped_lun0 .............................................................. [lun0 block/block1 (rw)]
| o- luns ........................................................................................................ [LUNs: 1]
| | o- lun0 .........................................[block/block1 (/dev/vg1/lv1) (default_tg_pt_gp)]
| o- portals .................................................................................................. [Portals: 1]
| o- 192.168.189.140:3260 ................................................................................. [OK]
o- loopback ..................................................................................................... [Targets: 0]
/>
Save the configuration
saveconfig
exit
Adjust the firewall
# firewall-cmd --permanent -add-port=3260/tcp
# firewall-cmd --reload
On system2
Install packages for iSCSI initiator
# yum install -y iscsi-initiator-utils
Configure the initiator name
# vim /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2019-06.com.example:system2
See the manual pages to copy and adjust sample commands
# man isciadm
Discover the target on the network
# iscsiadm --mode discoverydb --type sendtargets --portal 192.168.189.140 --discover
Login into the target as user root
# iscsiadm --mode node --targetname iqn.2019-06.com.example:system1 --portal 192.168.189.140:3260 --login root
Enable and start the iscsi daemon
# systemctl enable iscsid && systemctl start iscsid
Install utility to check iscsi
# yum install -y lsscsi
Check iscsi targets
# lsscsi
[0:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda
[2:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[4:0:0:0] disk LIO-ORG block1 4.0 /dev/sdb
[0:0:0:0] disk VMware, VMware Virtual S 1.0 /dev/sda
[2:0:0:0] cd/dvd NECVMWar VMware IDE CDR10 1.00 /dev/sr0
[4:0:0:0] disk LIO-ORG block1 4.0 /dev/sdb
# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 16G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 15G 0 part
├─centos-root 253:0 0 13.4G 0 lvm /
└─centos-swap 253:1 0 1.6G 0 lvm [SWAP]
sdb 8:16 0 2.8G 0 disk
# fdisk -l
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 16G 0 disk
├─sda1 8:1 0 1G 0 part /boot
└─sda2 8:2 0 15G 0 part
├─centos-root 253:0 0 13.4G 0 lvm /
└─centos-swap 253:1 0 1.6G 0 lvm [SWAP]
sdb 8:16 0 2.8G 0 disk
# fdisk -l
Configure the iscsi partition
# fdisk /dev/sdb
n for new
p for primary
1 as the number
first sector: accept default value;
last sector: accept default value;
t for type
code 83 for Linux
p to show configured partition
w to save the partion
Format the new partition
# mkfs -t ext4 /dev/sdb1
or shorter
# mkfs.ext4 /dev/sdb1
p for primary
1 as the number
first sector: accept default value;
last sector: accept default value;
t for type
code 83 for Linux
p to show configured partition
w to save the partion
Format the new partition
# mkfs -t ext4 /dev/sdb1
or shorter
# mkfs.ext4 /dev/sdb1
View the memory blocks for mounting the iscsi partition
# lsblk
Get the UUID of the blocks
# blkid /dev/sdb1
Copy the UUID into the fstab file
# blkid /dev/sdb1 >> /etc/fstab
Create the mount point for the iscsi partition
# mkdir /iscsi
Edit the /etc/fstab file
UUID="b6ed8784-5417-457e-afe4-b117be65e71d" /iscsi ext4 defaults,_netdev 0 0
Mount the whole fstab
# mount -a
Check the configuration can withstand a reboot
# reboot
# mount | grep iscsi
it must show no errors and boot OK.
Commenti
Posta un commento