In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
I. introduction of logical volumes
Logical volumes also group multiple hard disks or multiple partition logic together. From this point of view, logical volumes are much like raid. Logical volumes also group multiple hard disks or multiple partition logic together to form a single unit. With volume groups, the total capacity of this volume group is composed of multiple partitions or multiple hard disks. The difference between logical volumes and raid is that raid requires that each member must be the same size. Logical volumes are not required, and logical volumes are not required to be placed on that hard disk, different partitions of the same hard disk or different hard disks are fine, and the requirements are not so strict. In addition, after the logical volume has created a volume group, this volume group is a logical unit that can think of it as a large logical hard disk. After you have a volume group, you can divide small storage from above. The small storage unit is the logical volume, the small logical volume is combined from the space allocated in the volume group, and the volume group is composed of multiple hard disks or partitions, of course, the space of the logical volume comes from the volume group, and the space of the volume group comes from multiple hard disks, which means that the space of the logical volume may also come from multiple hard disks, but once the logical volume is created, there is not enough space for the logical volume. If the volume group has space, you can expand the logical volume by using the remaining space in the volume group space.
Second, the management tool of logical volume
PV: a physical volume, a hard disk partition or a device (such as a Raid) that logically has the same function as a disk partition, is the basic storage logic block of LVM. However, compared with the basic force storage medium, it has its own management commands; pvcreate: make ordinary disks as physical volumes and can specify multiple physical disks at a time; pvdisplay: display information about logical volumes on the current system; pvscan: scan disks with logical volumes in the system; pvremove: delete logical volumes so that disks do not have the attributes of logical volumes. VG: volume group, composed of physical volumes, can create one or more LVM logical volumes on the volume group, and LVM volume group consists of one or more physical volumes; vgcreate: create volume group; vgdisplay: display information about volume groups on the system; vgextend: add physical volumes to volume groups; vgreduce: remove physical volumes from volume groups; vgremove: delete a volume group Vgchange: configure whether the volume group is started; vgscan: scan the disks on the system with volume group attributes; LV: logical volumes, similar to hard disk partitions, on which file systems can be created. Lvcreate: create logical volume;-n: specify logical volume name when creating;-L: specify logical volume size when creating;-s: specify as snapshot volume;-p: specify permissions, ro read-only, rw read-write, etc.; lvdisplay: display information about logical volume Lvextend: expand the capacity of logical volumes without unmounting;-L: specify the size when expanding, and + # G indicates how many gigabytes of capacity are added on the original basis;-r: directly format the newly added space into the same file system as the original space during expansion Common format: lvextend-r-L + # G / dev/vg_name/lv_name lvreduce: reduce the capacity of logical volumes;-L: specify the size when shrinking, ext series support shrinking, xfs does not support shrinking; lvremove: delete a logical volume; lvresize: resize logical volumes; lvscan: scan logical volumes on the system
Third, implement a LVM logic volume
Requirements: disk lvm management, complete the following requirements, and write out the detailed process:
1) create a 20G VG; named testvg with at least two PV and require the PE size to be 16MB, and then create a logical volume with a size of 5G in the volume group testlv; to mount to the / users directory
2) extend testlv to 7G, requiring that the files of archlinux users cannot be lost
3) shrink testlv to 3G, requiring archlinux users' files not to be lost
4) create a snapshot of the testlv and try to back up the data based on the snapshot to verify the functionality of the snapshot
IV. The process of realization
Create a logical volume with a testlv size of 5g
First prepare two free disks, partition them with fdisk, and change the partition type id to lvm
View disk information, / dev/sdc and / dev/sdd as experimental disks
Use fdisk to partition the disk and change the type here take / dev/sdc as an example, sdd is the same as sdc.
Type t to change the type, L to see what the partition types are.
Type w to save the partition information and exit
/ dev/sdd is the same partitioning method!
Create pv physical volumes and view them using pvdisplay
Create a vg volume group, specify a PE size of 16m, a volume group name of testvg, and use vgdisplay to view volume group information
Create a rate logical volume testlv with a size of 5G, and view the logical volume information through lvdisplay
Create a file system type of ext4 for the logical volume testlv and mount it to the / users/ directory
two。 Expand the logical volume of testlv
First, vgdisplay checks whether there is still room in the volume group. If there is no new disk, you can add a new disk as a physical volume to achieve VG growth, and then expand the logical volume.
Expand testlv to 7G online and view it using df
3. Reduce the space of testlv (it takes 5 steps) to reduce the capacity of testlv to 3G, as long as the original file in the logical volume is smaller than testlv.
1) first use umount to cancel all mount relationships
2) e2fsck-f / dev/testvg/testlv: force disk detection
3) resize2fs / dev/testvg/testlv 3G: define how many gigabytes the logical volume is reduced to, which must be the same as the size specified by lvreduce below, otherwise an error will be reported.
4) lvreduce-L 3G / dev/testvg/testlv: defines how many gigabytes the logical volume is reduced to, which must be the same as the size specified by resize2fs above, otherwise an error will be reported.
5) then mount it, and use df-h to see that the logical volume has been reduced.
4. Create a snapshot of the logical volume testlv, create a snapshot of testlv, and try to back up data based on the snapshot to verify the functionality of the snapshot
1) the role of snapshots:
Record the system data at that time, and if there is any change in the data in the future, the data before the change will be saved in the snapshot area and used for backup. The snapshot only backs up the changed files, and the files that have not been changed are still in the original location. When you modify the data, the snapshot will automatically put a copy of the original file cp into the snapshot area. Even if you modify the file in the future, the original file can still be restored. If someone deletes a file, it will also cp a copy to the snapshot area, and the original properties of the original file remain unchanged, and multiple snapshots can be created, and the time when the snapshot is created is the time it considers the initial state of the original file.
2) disadvantages of snapshots:
Because they are all in the same logical volume, when the logical volume is damaged, the backed-up data naturally cannot be used, so snapshots cannot play the role of full backup. When we create a snapshot, if we do not use it, delete the snapshot immediately, because the existence of snapshots can affect the performance of the server.
3) Snapshot capacity definition: the volume size of the snapshot needs only 15% or 20% of the original logical volume. You can also use lvextend to enlarge the snapshot.
5. To backup the snapshot, testlv_snap and mount the created snapshot to / mnt/snap
6. Verify the role of the snapshot:
Before the logical volume creates a snapshot, the data already exists under the mount directory of the logical volume. If there is no data to create a snapshot, it is meaningless to demonstrate the role of the snapshot now. By default, you can see these files when you enter the snapshot mount directory by default. Don't panic, just to prove that the snapshot has been created, and now the file is still in its original location, when we modify F1 and delete f2. The snapshot volume automatically copies the original F1 and f2 to the directory of the snapshot volume. This gives you a backup.
7. Restore snapshot
First unmount the logical volume and snapshot volume, and the snapshot volume is automatically deleted after the snapshot restore is complete.
8. Delete logical Volum
1) unmount umount first
2) delete logical volumes sequentially
3) lvremove / dev/testvg/testlv: delete logical volumes
4) vgremove testvg: delete volume group
5) pvremove / dev/sdb / dev/sdc: delete physical volumes
At this time, you can no longer view any information about the logical volume testlv using pvdisplay, vgdisplay, and lvdisplay.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.