write in front
- Preparing for exams and organizing relevant notes
- The blog post involves using LVM for ISCSI target backend block storage demo
- If you don’t understand enough, please help me correct it.
There is only one true responsibility for everyone: to find themselves. Then stick to it in your heart for the rest of your life, wholeheartedly, and never stop. All other roads are incomplete, human escapes, cowardly returns to popular ideals, drifting, inner fears - Hermann Hesse, "Demian"
Target configuration
Configuration servera
Provide an iSCSI service with a disk named iqn.2014-11.com.example:servera
and meet the following
requirements:
- The service port is
3260
- Use
iscsi_store
as its backend volume its size is3G
- This service can only be
serverb.lab.example.com
accessed by - Backend volumes are of
LVM
the form
LVM preparation
Check disk status
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 20G 0 disk
└─vda1 252:1 0 10G 0 part /
vdb 252:16 0 5G 0 disk
Make a partition for vda
[root@servera iscsi-review]# fdisk /dev/vda
Welcome to fdisk (util-linux 2.32.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2):
First sector (20971487-41943039, default 20971520):
Last sector, +sectors or +size{
K,M,G,T,P} (20971520-41943039, default 41943039):
Created a new partition 2 of type 'Linux' and of size 10 GiB.
Command (m for help): w
The partition table has been altered.
Syncing disks.
[root@servera iscsi-review]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 10G 0 part /
└─vda2 252:2 0 10G 0 part
vdb 252:16 0 5G 0 disk
Create physical volumes, volume groups, and logical volumes
Create a logical volume (Logical Volume) named myvg in the volume group myvg, with a size of 3GB
[root@servera iscsi-review]# pvcreate /dev/vd
vda vda1 vda2 vdb
[root@servera iscsi-review]# pvcreate /dev/vda2
Physical volume "/dev/vda2" successfully created.
[root@servera iscsi-review]# vgcreate myvg /dev/vda2
Volume group "myvg" successfully created
[root@servera iscsi-review]# lvcreate -n myvg -L 3G myvg
Logical volume "myvg" created.
ISCSI related configuration
Install the targetcli package and enable the target service.
[root@servera iscsi-review]# yum -y install targetcli >> /dev/null
[root@servera iscsi-review]# systemctl enable --now target.service
Created symlink /etc/systemd/system/multi-user.target.wants/target.service → /usr/lib/systemd/system/target.service.
[root@servera iscsi-review]#
- Use the targetcli tool to enter the interactive command line interface.
- A block storage object iscsi_store is created and /dev/myvg/myvg is assigned to it.
- An iSCSI target named iqn.2014-11.com.example:servera is created.
- A LUN is created under TPG1 of the iqn.2014-11.com.example:servera target and the iscsi_store block storage object is mapped to the LUN.
- An ACL is created allowing the iSCSI Initiator named iqn.2014-11.com.example:servverb to access the above target.
- A network port named 0.0.0.0:3260 was removed.
- A new network port 172.25.250.10:3260 is created.
[root@servera ~]# targetcli
Warning: Could not load preferences file /root/.targetcli/prefs.bin.
targetcli shell version 2.1.fb49
Copyright 2011-2013 by Datera, Inc and others.
For help on commands, type 'help'.
/> /backstores/block create iscsi_store /dev/myvg/myvg
Created block storage object iscsi_store using /dev/myvg/myvg.
/> /iscsi create iqn.2014-11.com.example:servera
Created target iqn.2014-11.com.example:servera.
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.2014-11.com.example:servera/tpg1/luns create /backstores/block/iscsi_store
Created LUN 0.
/> /iscsi/iqn.2014-11.com.example:servera/tpg1/acls create iqn.2014-11.com.example:serverb
Created Node ACL for iqn.2014-11.com.example:serverb
Created mapped LUN 0.
/> /iscsi/iqn.2014-11.com.example:servera/tpg1/portals delete 0.0.0.0 3260
Deleted network portal 0.0.0.0:3260
/> /iscsi/iqn.2014-11.com.example:servera/tpg1/portals create 172.25.250.10 3260
Using default IP port 3260
Created network portal 172.25.250.10:3260.
Check configuration
/> ls /
o- / ............................................................................................ [...]
o- backstores ................................................................................. [...]
| o- block ..................................................................... [Storage Objects: 1]
| | o- iscsi_store ................................... [/dev/myvg/myvg (3.0GiB) 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.2014-11.com.example:servera ...................................................... [TPGs: 1]
| o- tpg1 .................................................................. [no-gen-acls, no-auth]
| o- acls ............................................................................. [ACLs: 1]
| | o- iqn.2014-11.com.example:serverb ......................................... [Mapped LUNs: 1]
| | o- mapped_lun0 .............................................. [lun0 block/iscsi_store (rw)]
| o- luns ............................................................................. [LUNs: 1]
| | o- lun0 ............................. [block/iscsi_store (/dev/myvg/myvg) (default_tg_pt_gp)]
| o- portals ....................................................................... [Portals: 1]
| o- 172.25.250.10:3260 .................................................................. [OK]
o- loopback ............................................................................ [Targets: 0]
/> exit
Global pref auto_save_on_exit=true
Configuration saved to /etc/target/saveconfig.json
Use the systemctl command to restart the target service. This will restart the iSCSI target service to apply any configuration changes or fix possible issues. Use the firewall-cmd command to add the iscsi-target service to the permanent rules of the firewall
[root@servera ~]# systemctl restart target.service
[root@servera ~]# firewall-cmd --permanent --add-service=iscsi-target
success
[root@servera ~]# firewall-cmd --reload
success
Launcher configuration
Configure the serverb so that it can connect to iqn.2014-11.com.example:servera provided on node1 and meet the following requirements
:
- iSCSI devices are automatically loaded during system startup
- The block device iSCSI contains a partition with a size of 2100MiB and is formatted as ext4
- This partition is mounted on /mnt/data and is automatically mounted during system startup.
[root@serverb ~]# yum search iscsi
[root@serverb ~]# yum -y install iscsi-initiator-utils
[root@serverb ~]# cat /etc/iscsi/initiatorname.iscsi
[root@serverb ~]# echo "InitiatorName=iqn.2014-11.com.example:servera" > /etc/iscsi/initiatorname.iscsi
[root@serverb ~]# cat /etc/iscsi/initiatorname.iscsi
InitiatorName=iqn.2014-11.com.example:servera
[root@serverb ~]# systemctl enable --now iscsid.service
Created symlink /etc/systemd/system/multi-user.target.wants/iscsid.service → /usr/lib/systemd/system/iscsid.service.
[root@serverb ~]# man iscsiadm
The IP address and name of the target server are discovered through an iSCSI discovery operation, and the iscsiadm command is used to log in to the target. Then use the lsblk command to confirm the connected block device
[root@serverb ~]# iscsiadm --mode discoverydb --type sendtargets --portal 172.25.250.10 --discover
172.25.250.10:3260,1 iqn.2014-11.com.example:servera
[root@serverb ~]# man iscsiadm
[root@serverb ~]# iscsiadm --mode node --targetname iqn.2014-11.com.example:servera --portal 172.25.
250.10:3260 -l
Logging in to [iface: default, target: iqn.2014-11.com.example:servera, portal: 172.25.250.10,3260]
Login to [iface: default, target: iqn.2014-11.com.example:servera, portal: 172.25.250.10,3260] successful.
[root@serverb ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3G 0 disk
vda 252:0 0 20G 0 disk
└─vda1 252:1 0 10G 0 part /
vdb 252:16 0 5G 0 disk
[root@serverb ~]# lsblk --fs /dev/sda
NAME FSTYPE LABEL UUID MOUNTPOINT
sda
A new partition table is created through the fdisk command, and a 2.1GB primary partition /dev/sda1 is created on /dev/sda. Then use the mkfs.ext4 command to create an ext4 file system on the partition and verify the creation of the partition and file system.
[root@serverb ~]# fdisk /dev/sda
Welcome to fdisk (util-linux 2.32.1).
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.
Created a new DOS disklabel with disk identifier 0xf9fbdda4.
Command (m for help): n
Partition type
p primary (0 primary, 0 extended, 4 free)
e extended (container for logical partitions)
Select (default p):
Using default response p.
Partition number (1-4, default 1):
First sector (2048-6291455, default 2048):
Last sector, +sectors or +size{
K,M,G,T,P} (2048-6291455, default 6291455): +2100M
Created a new partition 1 of type 'Linux' and of size 2.1 GiB.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[root@serverb ~]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 3G 0 disk
└─sda1 8:1 0 2.1G 0 part
vda 252:0 0 20G 0 disk
└─vda1 252:1 0 10G 0 part /
vdb 252:16 0 5G 0 disk
[root@serverb ~]# mkfs.ext4 /dev/sda1
mke2fs 1.44.6 (5-Mar-2019)
Creating filesystem with 537600 4k blocks and 134640 inodes
Filesystem UUID: 74d0c4f2-cc5f-46cc-a80d-5750690b5f56
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912
Allocating group tables: done
Writing inode tables: done
Creating journal (16384 blocks): done
Writing superblocks and filesystem accounting information: done
[root@serverb ~]# lsblk --fs /dev/sda1
NAME FSTYPE LABEL UUID MOUNTPOINT
sda1 ext4 74d0c4f2-cc5f-46cc-a80d-5750690b5f56
Mount the /dev/sda1 partition (the file system type is ext4) to the /mnt/data directory, and add the mount configuration to the /etc/fstab file to automatically mount the file system when the system starts.
[root@serverb ~]# blkid /dev/sda1
/dev/sda1: UUID="74d0c4f2-cc5f-46cc-a80d-5750690b5f56" TYPE="ext4" PARTUUID="f9fbdda4-01"
[root@serverb ~]# mkdir /mnt/data
[root@serverb ~]# echo "UUID='74d0c4f2-cc5f-46cc-a80d-5750690b5f56' /mnt/data ext4 _netdev 0 0" >> /
etc/fstab
[root@serverb ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Tue Oct 29 16:26:01 2019
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=f7614c41-2835-4125-bb13-50772dc2f30c / xfs defaults 0 0
servera.lab.example.com:/nfsshare /share nfs defaults 0 0
UUID='74d0c4f2-cc5f-46cc-a80d-5750690b5f56' /mnt/data ext4 _netdev 0 0
[root@serverb ~]# mount /mnt/data
[root@serverb ~]# df -ht ext4
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 2.0G 6.2M 1.9G 1% /mnt/data
[root@serverb ~]#
Reference to part of the blog post
© The copyright of the reference links in this article belongs to the original author. Please inform us if there is any infringement.
红帽服务管理与自动化(RH358)
Lecture Notes
© 2018-2023 [email protected], All rights reserved. Keep Attribution-NonCommercial-ShareAlike (CC BY-NC-SA 4.0)