2020.11.09 Monday Formal class D25
13.7 LVM
13.7.1 lvm brief introduction
-
lvm Introduce
Logical management volume LVM It's a system tool for hard disk .
adopt LVM Technology can mask the underlying differences in disk partitioning , Logically provides the file system with the concept of a volume , Suggest the appropriate file system on the volume .
Physical volume (PV):physical volume Pass a regular disk device through pvcreate Command to initialize it , Form a physical volume , It's a hard disk or partition .( Compare it to flour )
The volume group (VG):volume group To make multiple physical volumes into a logical whole , The size of the volume group is the sum of multiple hard disks , By one or more PV The whole of composition .( It's like dough )
Logic volume (LV):logical volume Divide the required space size from the volume group , Users only need to format it to mount and use , from VG The space cut out in is used to create a file system .( Compared to steamed bread )
Basic unit (PE):physical extend The smallest unit of allocated logical size , Default 4MB The basic block of , namely 100MB Logical space needs to be created 25 individual PE.
-
Use lvm Why
fdisk、gdisk The tool is to fix the size of the partition
If the partition is set too large , Wasted disk space
If the partition is set too small , There will be insufficient space
-
lvm Advantages and disadvantages
advantage :
1、 You can dynamically expand the size of the file system while the system is running
2、 File systems can span multiple disks , So the file system size is not limited by the physical disk
3、 You can add new disks to LVM In the storage pool
4、 You can mirror important data to multiple physical disks
5、 It is easy to export the whole volume group to another machine
shortcoming :
1、 Because there are extra operations , Storage performance is affected
2、 When a disk in a volume group is damaged , The entire volume group will be affected
LVM One of the disks is damaged , Whole LVM It's broken ,LVM Only the dynamic expansion function
Solutions : The underlying use RAID+ The upper LVM= Both redundancy and dynamic expansion
3、 When you remove a disk from a volume group, you must use reducevg command ( requirement root jurisdiction , And is not allowed in snapshot volume groups )
13.7.2 lvm Basic use
-
Download the installation package
[root@ccc ~]# yum install -y lvm2
-
Make pv: You can do this for partitions , It can also be done on the whole plate
# 1、 Make [root@ccc ~]# pvcreate /dev/sdb1 WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n]: y Wiping xfs signature on /dev/sdb1. Physical volume "/dev/sdb1" successfully created. [root@ccc ~]# pvcreate /dev/sdb2 Wiping xfs signature on /dev/sdb2. Physical volume "/dev/sdb2" successfully created. [root@ccc ~]# pvcreate /dev/sdb3 Wiping swap signature on /dev/sdb3. Physical volume "/dev/sdb3" successfully created. # 2、 see [root@ccc ~]# pvs PV VG Fmt Attr PSize PFree /dev/sdb1 lvm2 --- 1.00g 1.00g /dev/sdb2 lvm2 --- 1.00g 1.00g /dev/sdb3 lvm2 --- 1.00g 1.00g [root@ccc ~]# pvscan PV /dev/sdb2 lvm2 [1.00 GiB] PV /dev/sdb3 lvm2 [1.00 GiB] PV /dev/sdb1 lvm2 [1.00 GiB] Total: 3 [3.00 GiB] / in use: 0 [0 ] / in no VG: 3 [3.00 GiB]
-
Make vg: take pv Transfer in vg in
# To make a vg1( contain /dev/sdb1 and /dev/sdb2 Two pv) [root@ccc ~]# vgcreate vg1 /dev/sdb1 /dev/sdb2 Volume group "vg1" successfully created [root@ccc ~]# vgs VG #PV #LV #SN Attr VSize VFree vg1 2 0 0 wz--n- 1.99g 1.99g # Make vg2( contain /dev/sdb3 One pv) [root@ccc ~]# vgcreate vg2 /dev/sdb3 Volume group "vg2" successfully created [root@ccc ~]# vgs VG #PV #LV #SN Attr VSize VFree vg1 2 0 0 wz--n- 1.99g 1.99g vg2 1 0 0 wz--n- 1020.00m 1020.00m
-
Create logical volumes lvm
Options
-L # Logical volume size
-n # Logical volume name
# from vg1 The logic volume is divided out of it lv1_from_vg1、lv2_from_vg1 [root@ccc ~]# lvcreate -L 100M -n lv1_from_vg1 vg1 Logical volume "lv1_from_vg1" created. [root@ccc ~]# lvcreate -L 200M -n lv2_from_vg1 vg1 Logical volume "lv2_from_vg1" created. # from vg2 The logic volume is divided out of it lv1_from_vg2、lv2_from_vg2 [root@ccc ~]# lvcreate -L 300M -n lv1_from_vg2 vg2 Logical volume "lv1_from_vg2" created. [root@ccc ~]# lvcreate -L 400M -n lv2_from_vg2 vg2 Logical volume "lv2_from_vg2" created. # see [root@ccc ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv1_from_vg1 vg1 -wi-a----- 100.00m lv2_from_vg1 vg1 -wi-a----- 200.00m lv1_from_vg2 vg2 -wi-a----- 300.00m lv2_from_vg2 vg2 -wi-a----- 400.00m
-
Format and mount
[root@ccc ~]# mkfs.xfs /dev/vg1/lv1_from_vg1 [root@ccc ~]# mkfs.xfs /dev/vg1/lv2_from_vg1 [root@ccc ~]# mkfs.xfs /dev/vg2/lv1_from_vg2 [root@ccc ~]# mkfs.xfs /dev/vg2/lv2_from_vg2 [root@ccc ~]# mount /dev/vg1/lv1_from_vg1 /test1/ [root@ccc ~]# mount /dev/vg1/lv2_from_vg1 /test2/ [root@ccc ~]# mount /dev/vg2/lv1_from_vg2 /test3/ [root@ccc ~]# mount /dev/vg2/lv2_from_vg2 /test4/ # see [root@ccc ~]# df file system 1K- block Already used You can use Already used % Mount point ... /dev/mapper/vg1-lv1_from_vg1 98980 5344 93636 6% /test1 /dev/mapper/vg1-lv2_from_vg1 201380 10464 190916 6% /test2 /dev/mapper/vg2-lv1_from_vg2 303780 15584 288196 6% /test3 /dev/mapper/vg2-lv2_from_vg2 406180 20704 385476 6% /test4
13.7.3 Online dynamic capacity expansion
-
command
lvextend -L [+]MGT /dev/VG_NAME/VL_NAME # -L 100M And -L +100M It's not the same thing ,+100M It means expanding the capacity of the original
-
Example
[root@ccc ~]# lvextend -L +100M /dev/vg1/lv2_from_vg1 Size of logical volume vg1/lv2_from_vg1 changed from 200.00 MiB (50 extents) to 300.00 MiB (75 extents). Logical volume vg1/lv2_from_vg1 successfully resized. [root@ccc ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv1_from_vg1 vg1 -wi-ao---- 100.00m lv2_from_vg1 vg1 -wi-ao---- 300.00m lv1_from_vg2 vg2 -wi-ao---- 300.00m lv2_from_vg2 vg2 -wi-ao---- 400.00m [root@ccc ~]# xfs_growfs /dev/vg1/lv1_from_vg1 # After expanding the logical volume, it needs to be updated xfs file system
13.7.4 Online dynamic reduction and deletion
-
!!!!!!!!!!!!!!! Don't shrink !!!!!!!!!!!!!
-
xfs Shrinking is not supported
lvreduce -L [-]MGT /dev/VG_NAME/LV_NAME # Reduced logical volume
-
Delete
# Delete lv You need to uninstall the mount point before [root@ccc ~]# umount /test1 [root@ccc ~]# lvremove /dev/vg1/lv1_from_vg1 Do you really want to remove active logical volume vg1/lv1_from_vg1? [y/n]: y Logical volume "lv1_from_vg1" successfully removed [root@ccc ~]# umount /test2 [root@ccc ~]# lvremove /dev/vg1/lv2_from_vg1 -y Logical volume "lv2_from_vg1" successfully removed # Delete vg [root@ccc ~]# vgremove vg1 Volume group "vg1" successfully removed # Delete pv: Can only delete does not belong to any vg Of pv [root@ccc ~]# pvremove /dev/sdb1 Labels on physical volume "/dev/sdb1" successfully wiped.
13.7.5 snapshot
-
lvm The snapshot function USES write - time replication technology (Copy-On-Write,COW)
-
When creating a snapshot, the data can be backed up without stopping the service
-
Snapshots are special in nature lv, After the snapshot is created, the old data will be assigned to the snapshot space
# Prepare the initial data [root@ccc ~]# df file system 1K- block Already used You can use Already used % Mount point ... /dev/mapper/vg1-lv1_from_vg1 98980 5344 93636 6% /test1 [root@ccc ~]# echo 111 > /test1/1.txt # see vg1 Is the capacity sufficient [root@ccc ~]# vgs VG #PV #LV #SN Attr VSize VFree vg1 1 1 0 wz--n- <10.00g <9.90g # stay vg1 Create a lv1_from_vg1 Snapshot [root@ccc ~]# lvcreate -L 1G -s -n lv1_from_vg1_snap /dev/vg1/lv1_from_vg1 Reducing COW size 1.00 GiB down to maximum usable size 104.00 MiB. Logical volume "lv1_from_vg1_snap" created. # see [root@ccc ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert lv1_from_vg1 vg1 owi-aos--- 100.00m lv1_from_vg1_snap vg1 swi-a-s--- 104.00m lv1_from_vg1 0.01 # Modify file /test/1.txt [root@ccc ~]# echo 11111111 >> /test1/1.txt [root@ccc ~]# cat /test1/1.txt 111 11111111 # Restore data # Mount the snapshot , And original lvm Use the same UUID, Don't be xfs allow , You need to add options -o nouuid [root@ccc ~]# mount -o nouuid /dev/vg1/lv1_from_vg1_snap /opt/ [root@ccc ~]# cat /opt/1.txt 111 [root@ccc ~]# cp /opt/1.txt /test1/1.txt cp: Is it covered? "/test1/1.txt"? y [root@ccc ~]# cat /test1/1.txt 111
-
Too many files to recover , Direct merger
[root@ccc ~]# mount /dev/vg1/lv1_freom_vg1 /test1 [root@ccc ~]# echo ccc > /test1/2.txt [root@ccc ~]# cat /test1/2.txt ccc [root@ccc ~]# lvcreate -L 1G -n lv1_from_vg1_snap /dev/vg1/lv1_freom_vg1 Volume group name expected (no slash) Run `lvcreate --help' for more information. [root@ccc ~]# lvcreate -L 1G -s -n lv1_from_vg1_snap /dev/vg1/lv1_freom_vg1 Reducing COW size 1.00 GiB down to maximum usable size 104.00 MiB. Logical volume "lv1_from_vg1_snap" created. [root@ccc ~]# echo 1111 >> /test1/2.txt [root@ccc ~]# echo 1111 >> /test1/2.txt [root@ccc ~]# echo 1111 >> /test1/2.txt [root@ccc ~]# echo 1111 >> /test1/2.txt [root@ccc ~]# cat /test1/2.txt ccc 1111 1111 1111 1111 [root@ccc ~]# mount -o nouuid /dev/vg1/lv1_from_vg1_snap /opt/ [root@ccc ~]# cat /opt/2.txt ccc # Unload the data source and snapshot first , Merge again , The snapshot is one-time and will be deleted automatically [root@ccc ~]# umount /opt/ [root@ccc ~]# umount /test1/ [root@ccc ~]# lvconvert --mergesnapshot /dev/vg1/lv1_from_vg1_snap Merging of volume vg1/lv1_from_vg1_snap started. vg1/lv1_freom_vg1: Merged: 100.00% [root@ccc ~]# mount /dev/vg1/lv1_freom_vg1 /test1 [root@ccc ~]# cat /test1/2.txt ccc
14 Network management
14.1 Network card name
-
Return to the traditional naming method
# Modify the name of network card configuration file [root@ccc ~]# cd /etc/sysconfig/network-scripts/ [root@ccc network-scripts]# mv ifcfg-ens33 ifcfg-eth0 # Modify network card configuration file device name [root@ccc network-scripts]# sed -i "s@ens33@eth0@g" ifcfg-eth0 # GRUB add to kernel Parameters [root@ccc network-scripts]# vim /etc/sysconfig/grub [root@ccc network-scripts]# tail -2 /etc/sysconfig/grub | head -1 GRUB_CMDLINE_LINUX="spectre_v2=retpoline rhgb quiet 'net.ifnames=0 biosdevname=0'" # Load to boot partition [root@ccc network-scripts]# grub2-mkconfig -o /boot/grub2/grub.cfg Generating grub configuration file ... Found linux image: /boot/vmlinuz-3.10.0-1127.el7.x86_64 Found initrd image: /boot/initramfs-3.10.0-1127.el7.x86_64.img Found linux image: /boot/vmlinuz-0-rescue-d756bc9b1bf84350b002ec5d9e37360d Found initrd image: /boot/initramfs-0-rescue-d756bc9b1bf84350b002ec5d9e37360d.img done # Restart the system to take effect [root@ccc ~]# reboot
14.2 Basic network configuration
14.2.1 View network card information
-
View network card information
# View all network cards connected to the current system [root@ccc ~]# lspci | grep -i eth 02:01.0 Ethernet controller: Intel Corporation 82545EM Gigabit Ethernet Controller (Copper) (rev 01) # Make sure the cable is connected [root@ccc ~]# ethtool eth0 Settings for eth0: Supported ports: [ TP ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Supported FEC modes: Not reported Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Advertised pause frame use: No Advertised auto-negotiation: Yes Advertised FEC modes: Not reported Speed: 1000Mb/s Duplex: Full Port: Twisted Pair PHYAD: 0 Transceiver: internal Auto-negotiation: on MDI-X: off (auto) Supports Wake-on: d Wake-on: d Current message level: 0x00000007 (7) drv probe link Link detected: yes [root@ccc ~]# mii-tool eth0 eth0: negotiated 1000baseT-FD flow-control, link ok # link ok The network card can be identified , And connected to the effective network cable
14.2.2 ifconfig command
-
ifconfig command
ifconfig -a # View all network card information ifconfig eth0 # View individual network card information ifconfig eth0 192.168.1.122 netmask 255.255.255.0 # Set temporary IP And mask ( Restart failure ) ifconfig eth0 192.168.1.122/24 # Temporary settings IP Address ifconfig eth0:1 192.168.0.2 netmask 255.255.255.0 # Configure sub interfaces ifconfig eth0:0 down # Delete ifconfig eth0:1 del 192.168.0.2 # Delete , No mask Opening and closing ifconfig eth0 down|up # Do not load network card configuration file ifdown eth0 |ifup eth0 # Load network card configuration file
14.2.3 ping command
-
ping
ping The goal is IP Address # ctrl+c end , Test whether the two host networks are interlinked ping -c frequency The goal is IP Address # Execute on your own machine , Forbid others to ping own [root@ccc ~]# echo 1 > /proc/sys/net/ipv4/icmp_echo_ignore_all
14.2.4 NetworkManager service
-
effect : yes redhat6 Built in detection network 、 Graphical tools for automatically connecting to the web .
-
NetworkManager Services interfere with network configuration , Such as DNS It's often brushed off , So often shut down .
-
Network card related configuration files /etc/sysconfig/network-scripts/ifcfg-ethX Interface network profile
# Open the network card configuration file , Complete static IP To configure # Restart the network service after modification systemctl restart network 1 TYPE=Ethernet 2 PROXY_METHOD=none 3 BROWSER_ONLY=no 4 BOOTPROTO=none # dhcp Get dynamic IP # none Depending on the other options, decide whether dynamic or static # static Specify manually IP 5 DEFROUTE=yes 6 IPV4_FAILURE_FATAL=no 7 NAME=eth0 8 UUID=39e06fd4-3081-4cfe-8937-65fd357b6727 9 DEVICE=eth0 # Network card name 10 ONBOOT=yes # yes active no Ban 11 IPADDR=192.168.29.55 # IP Address 12 NETMASK=255.255.255.0 # Subnet mask 13 DNS1=8.8.8.8 # DNS The server 14 PREFIX=24 15 GATEWAY=192.168.29.1 # The default gateway
14.2.5 DNS The configuration file
-
DNS Parsing files /etc/resolv.conf
[root@ccc ~]# cat /etc/resolv.conf # Set up DNS Point to , Three at most # Generated by NetworkManager nameserver 8.8.8.8 # Corresponding to the configuration item in the network card configuration file DNS
-
Local name resolution file ( Prior to the DNS)/etc/hosts
dns priority browser dns cache --> The local system DNS cache --> Local computer HOSTS file -->ISP DNS cache --> recursive / Iterative query
14.2.6 Set the host name permanently
-
hostnamectl
-
/etc/hostname
[root@ccc ~]# hostnamectl set-hostname zzz [root@ccc ~]# hostname zzz [root@ccc ~]# vim /etc/hostname
14.2.7 The correspondence between port and service
-
Corresponding relation
[root@ccc ~]# grep '^ftp\ | ^ssh' /etc/services