In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
What is the creation of LVM and the use of snapshots? in view of this question, this article introduces the corresponding analysis and solutions in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.
LVM is the abbreviation of logical disk Volume Management (Logical VolumManager). It is a mechanism for managing disk partitions in Linux environment. LVM is a logical layer based on hard disk and partition to improve the flexibility of disk management in LVM areas. As mentioned earlier, LVM is a logical layer added between the disk partition and the file system to shield the underlying disk partition layout for the file system, provide an abstract volume, and establish the file system on the volume. Physical volumes (physical volume) physical volumes refer to hard disk partitions or devices that logically have the same function as disk partitions (such as RAID), which is the basic storage logic block of LVM, but compared with basic physical storage media (such as partitions, disks, etc.), it contains management parameters related to LVM.
Creating a LVM usually goes through the following steps
1. Create a LVM partition type: the method is the same as creating other generic partitions, except that the partition type of LVM is 8e. After creating the partition, use t to change the partition type to 8e
two。 Creating a logical volume requires the following steps
Create physical Volume (PV)-> create Volume Group (VG)-> create Volume Group (LV)
3. Create a physical volume
The command to create a physical volume is pvcreate, which is used to create all partitions or disks that you want to add to the volume group as physical volumes
Usage:
Pvcreate / dev/sdb1 (create a single partition as a physical volume)
Pvdisplay / dev/sdb1 (view the details of the physical volume created) pvs can also view
[root@station55 ~] # pvcreate / dev/sd {bje c} 1Physical volume "/ dev/sdb1" successfully createdPhysical volume "/ dev/sdc1" successfully created
(the above means to create the sdb1 and sdc1 of my partition as physical volumes)
[root@station55] # pvsPV VG Fmt Attr PSize PFree/dev/sda2 vg0 lvm2 Amuri-59.99g 7.99g/dev/sdb1 myvg lvm2 Amure-10.00g 10.00g/dev/sdc1 myvg lvm2 Amure-10.00g 10.00g
(view brief information about the physical volume you just created)
4 create a volume group
The command to create a volume group is vgcreate
The first parameter of the vgcreate VGNAME / dev/sdb1 vgcreate command is to specify the logical name of the volume group, and the latter parameter is to specify all partitions and disks that you want to add to the volume group. The PE size determines the maximum size of the logical volume. The PE of 4MB determines that the maximum capacity of a single logical volume is 256GB. If you want to use a logical volume greater than 256g, specify a larger PE when creating the volume group. The PE size ranges from 8KB to 512MB and must always be a multiple of 2 (specified with-s).
Vgdisplay to view volume group information; vgs can also view
[root@station55 ~] # vgcreate myvg / dev/sd {bmeme c} 1Volume group "myvg" successfully created
(create a volume group myvg and add the sd {bmenade c} 1 of the physical volume)
[root@station55 ~] # vgsVG # PV # LV # SN Attr VSize VFreemyvg 200 wz--n- 20.00g 20.00gvg0 1 40 wz--n- 59.99g 7.99g
(view brief information about the volume group you just created)
5. Create a logical volume
Commands for creating logical volumes
Lvcreate-L SIZE-n LV_NAME VG_NAME
Lvdisplay View the details of the creation vgs can also view
[root@station55] # lvcreate-L 10G-n mylv myvgLogical volume "mylv" created
(the size created is 10G logical volume name mylv, which is added from myvg)
[root@station55] # lvsLV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convertmylv myvg-wi-a---- 10.00groot vg0-wi-ao--- 20.00gswap vg0-wi-ao--- 2.00gusr vg0-wi-ao--- 10.00gvar vg0-wi-ao--- 20.00g
(view brief information about the logical volume you just created)
The path of the created LVM is saved in:
/ dev/VG_NAME/LV_NAME
/ dev/mapper/VG_NAME-LV_NAME
/ dev/mapper/testvg-mylv
[root@station55] # lvdisplay / dev/myvg/mylv--- Logical volume-LV Path / dev/myvg/mylvLV Name mylvVG Name myvgLV UUID Yu0Ja1-uL3H-APbU-KFjj-Bmql-VwA9-FhBItYLV Write Access read/writeLV Creation host, time station55.magelinux.com 2013-07-15 08:39:00 + 0800LV Status available# open 0LV Size 10.00 GiBCurrent LE 2560Segments 1Allocation inheritRead ahead sectors auto- currently set to 256Block device 253VR 4
(view the details of the storage path of the created logical volume)
6. Create a file system
Mke2fs-t ext4 is followed by the path to the created LV.
[root@station55] # mke2fs-t ext4 / dev/myvg/mylvmke2fs 1.41.12 (17-May-2010) Filesystem label=OS type: LinuxBlock size=4096 (log=2) Fragment size=4096 (log=2)
(formatted successfully)
Once you have created the file system, you can load it and use it:
Mount logical volume path mount point
[root@station55 ~] # mount / dev/myvg/mylv / mnt/
If you want the file system to be loaded automatically when the system starts, you also need to add content to / etc/fstab
7. Extended VG
First of all, prepare a PV.
[root@station55 ~] # pvcreate / dev/sdc2Physical volume "/ dev/sdc2" successfully created
Use the vgextend command to complete the extension
Vgextend VG_NAME / PATH/TO/PV
[root@station55 ~] # vgextend myvg / dev/sdc2Volume group "myvg" successfully extended
8. Reduce VG
Determine which PV to remove
Transfer data on this PV to another PV
[root@station55 ~] # pvmove / dev/sdb1/dev/sdb1: Moved: 0.3%/dev/sdb1: Moved: 64.6%/dev/sdb1: Moved: 100.0%
(transfer sdb1 data to another disk)
Remove this PV from the volume group
[root@station55 ~] # vgreduce myvg / dev/sdb1Removed "/ dev/sdb1" from volume group "myvg"
9. Extended logical Volume
Are you sure how big the expansion is?
Make sure that the volume group in which the current logical volume resides has enough free space
Extend:
1.1 physical boundary lvextend-L [+] SIZE / path/to/lv [root@station55 ~] # lvextend-L + 3G / dev/myvg/mylvExtending logical volume mylv to 13.00 GiBLogical volume mylv successfully resized
(add 3 Gs to the logical volume)
1.2 logical boundary
Resize2fs / path/to/lv
[root@station55] # resize2fs / dev/myvg/mylvresize2fs 1.41.12 (17-May-2010) Filesystem at / dev/myvg/mylv is mounted on / mnt; on-line resizing requiredold desc_blocks = 1, new_desc_blocks = 1Performing an on-line resize of / dev/myvg/mylv to 3407872 (4k) blocks.The filesystem on / dev/myvg/mylv is now 3407872 blocks long.
File system detection:
E2fsck / path/to/device
[root@station55] # e2fsck / dev/myvg/mylve2fsck 1.41.12 (17-May-2010) / dev/myvg/mylv: clean, 11 files 851968 files, 92640 blocks 3407872
(it means to insist that there is no problem, clean)
10. Reduce logical Volume
Are you sure how big the reduction will be? The premise is that at least all the original data can be accommodated.
Shrink:
1. Unmount and forcibly detect the file system
E2fsck-f path
[root@station55] # e2fsck-f / dev/myvg/mylve2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizesPass 2: Checking directory structurePass 3: Checking directory connectivityPass 4: Checking reference countsPass 5: Checking group summary information/dev/myvg/mylv: 11 Checking directory connectivityPass 851968 files (0.0% non-contiguous), 92640 Checking directory connectivityPass 3407872 blocks
2. Logical boundary
Resize2fs / path/to/device SIZE [root@station55 ~] # resize2fs / dev/myvg/mylv 10Gresize2fs 1.41.12 (17-May-2010) The filesystem is already 2621440 blocks long. Nothing to do!
(the prompt has been reduced to 10G)
3. Physical boundary
Lvreduce-L [-] SIZE / path/to/lv
[root@station55] # lvreduce-L-3G / dev/myvg/mylvWARNING: Reducing active logical volume to 10.00 GiBTHIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mylv? [y/n]: yReducing logical volume mylv to 10.00 GiBLogical volume mylv successfully resized
(warning of risks, enter y to indicate successful reduction)
11. Snapshot volume creation:
The lifecycle is the entire data duration; during this period, the growth of data cannot exceed the snapshot volume size.
The snapshot volume should be read-only
In the same volume group as the original volume
Lvcreate
-s: snapshot Volum
-p r: restrict snapshot volumes to read-only access
Lvcreate-L SIZE-s-pr-n LV_NAME / path/to/lv
[root@station55] # lvcreate-L 50m-s-p r-n kuaizhao / dev/myvg/mylvRounding up size to full physical extent 52.00 MiBLogical volume "kuaizhao" created
(the snapshot was created successfully. You can see the snapshot volume information with lvs)
After the snapshot volume is created, it can be hung for viewing.
[root@station55 ~] # mount / dev/myvg/kuaizhao / media/mount: block device / dev/mapper/myvg-kuaizhao is write-protected, mounting read-only
(prompt is hung in read-only mode)
twelve。 Remove logical volumes:
Lvremove / path/to/lv
[root@station55 ~] # lvremove / dev/myvg/mylvDo you really want to remove active logical volume mylv? [YBO]: yLogical volume "mylv" successfully removed
(the logical volume was removed successfully. Giving the snapshot to the remove command is the same as removing the logical volume before removing mylv.)
13. Remove the volume group:
Vgremove VG_NAME
[root@station55 ~] # vgremove myvgVolume group "myvg" successfully removed
(remove and fix)
14. Remove physical Volum
[root@station55 ~] # pvremove / dev/sdc1Labels on physical volume "/ dev/sdc1" successfully wiped
(remove and fix)
As you can see from the above discussion, LVM is very scalable and easy to use. You can easily resize volume groups and logical volumes, and further resize the file system.
This is the answer to the question about the creation of LVM and the use of snapshots. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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.