网站建设资讯

NEWS

网站建设资讯

Linux磁盘管理之LVM的使用-创新互联

一、LVM介绍

创新互联长期为上1000+客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为城关企业提供专业的成都网站设计、网站制作、外贸营销网站建设城关网站改版等技术服务。拥有十多年丰富建站经验和众多成功案例,为您定制开发。

在我们管理Linux磁盘的时候,通常会遇到这么一种情况。在最初规划Linux的磁盘的时候,我们给某个分区划分了一定量的磁盘空间,使用一段时间后,发现我们规划的磁盘空间不足了,这个时候怎么办?我们肯定要想办法给扩容呀,找一块磁盘分区,格式化,然后挂载,然后把数据拷贝到新加的磁盘上,然后把原有的磁盘卸载掉,通常我们是这样做的。这样一来虽然达到了扩容的目的,但是费时费力;如果第二次扩容,空间还是不够,我们又要重复上面的步骤;如果分配的磁盘空间过大,使用了很久才发现它根本用不到那么多空间,这个时候是不是又要调整呀,听着就感觉很繁琐。这时候你肯定要想有没有那种可挂载上一块盘,我们利用某种管理手段,可以在线的调整磁盘的空间,这样有节约了时间,也可实现弹性管理磁盘。对,lvm就有这样的功能。

LVM(logical volume manager)逻辑卷管理,它可以弹性的管理文件系统的容量,LVM的工作原理是将一个或多个底层块设备组织成一个逻辑设备,这个逻辑设备可以在未来新增或移除其他的分区到这个逻辑设备中,从而实现了弹性管理磁盘。

Linux磁盘管理之LVM的使用

PV:物理卷(physical volume);物理卷就是指硬盘分区或从逻辑上与磁盘分区具有同样功能的设备(如raid),是LVM的基本储存逻辑块,但和基本的物理存储介质(如分区,磁盘等)比较,却包含有与LVM相关的管理参数

VG:卷组(volume group)LVM卷组类似于非LVM系统中的物理硬盘,尤其物理卷组成,可以在卷组上创建一个或多个LVM分区(逻辑卷),LVM卷组由一个或多个物理卷组成

LV:逻辑卷(logical volume)LVM的逻辑卷类似非LVM系统中的硬盘分区,在逻辑卷之上可以创建文件系统。

LVM就是将一些零碎的磁盘分区(PV)合并成一个较大的磁盘(VG),然后在根据需要对这个较大的磁盘(VG)进行划分成不同的大小分区(LV),这些小的分区(LV)是可以动态的扩展和缩小的,这就是LVM的逻辑卷管理过程。所谓LVM的大磁盘就是将许多PV整合成的VG,那么这个大磁盘大可达到多少容量呢?我们知道在文件系统里面数据存储的最小单位是块(block),不过在LVM当中数据储存的最小单位是PE,PE的的作用同block的作用一样,需要注意到是LVM默认使用的PE大小是4M,而LVM的VG最多能包含65534个PE,也就是说默认LVM的VG会有4×65534M/1024M=256G,所以PE的大小决定了VG的大容量,当然我们在创建VG的时候可指定PE大小,从而来决定VG的大小。

二、LVM实现

1)前期准备几块硬盘或者分区来模拟PV

[root@test-centos7-node1 ~]# lsblk
NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda   8:0  0  50G 0 disk 
├─sda1  8:1  0  2G 0 part /boot
├─sda2  8:2  0  2G 0 part [SWAP]
└─sda3  8:3  0  46G 0 part /
sdb   8:16  0  50G 0 disk 
sr0   11:0  1 792M 0 rom 
[root@test-centos7-node1 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

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
Building a new DOS disklabel with disk identifier 0x6180123f.

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6180123f

  Device Boot   Start     End   Blocks  Id System

Command (m for help): n
Partition type:
  p  primary (0 primary, 0 extended, 4 free)
  e  extended
Select (default p): p
Partition number (1-4, default 1): 
First sector (2048-104857599, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): +10G
Partition 1 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6180123f

  Device Boot   Start     End   Blocks  Id System
/dev/sdb1      2048  20973567  10485760  83 Linux

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): n
Partition type:
  p  primary (1 primary, 0 extended, 3 free)
  e  extended
Select (default p): p
Partition number (2-4, default 2): 
First sector (20973568-104857599, default 20973568): 
Using default value 20973568
Last sector, +sectors or +size{K,M,G} (20973568-104857599, default 104857599): +10G
Partition 2 of type Linux and of size 10 GiB is set

Command (m for help): t
Partition number (1,2, default 2): 
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): n
Partition type:
  p  primary (2 primary, 0 extended, 2 free)
  e  extended
Select (default p): p
Partition number (3,4, default 3): 
First sector (41945088-104857599, default 41945088): 
Using default value 41945088
Last sector, +sectors or +size{K,M,G} (41945088-104857599, default 104857599): +10G
Partition 3 of type Linux and of size 10 GiB is set

Command (m for help): t
Partition number (1-3, default 3): 
Hex code (type L to list all codes): 8e 
Changed type of partition 'Linux' to 'Linux LVM'

Command (m for help): p

Disk /dev/sdb: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x6180123f

  Device Boot   Start     End   Blocks  Id System
/dev/sdb1      2048  20973567  10485760  8e Linux LVM
/dev/sdb2    20973568  41945087  10485760  8e Linux LVM
/dev/sdb3    41945088  62916607  10485760  8e Linux LVM

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@test-centos7-node1 ~]# lsblk
NAME  MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda   8:0  0  50G 0 disk 
├─sda1  8:1  0  2G 0 part /boot
├─sda2  8:2  0  2G 0 part [SWAP]
└─sda3  8:3  0  46G 0 part /
sdb   8:16  0  50G 0 disk 
├─sdb1  8:17  0  10G 0 part 
├─sdb2  8:18  0  10G 0 part 
└─sdb3  8:19  0  10G 0 part 
sr0   11:0  1 792M 0 rom 
[root@test-centos7-node1 ~]#

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


名称栏目:Linux磁盘管理之LVM的使用-创新互联
URL地址:http://cdweb.net/article/dcocsj.html