歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux LVM空間擴容演示

Linux LVM空間擴容演示

日期:2017/2/28 13:57:18   编辑:Linux教程

虛擬化逐漸成為我們日常運維工作的主要部署策略。在虛擬化帶來的各種好處中,硬件資源動態調整是傳統物理機難以企及的優勢方面。針對不同類型的應用和性能需求,我們可以為各個應用系統提供更加個性化的部署方案和資源解決方案。而且,當存儲、CPU和內存等資源不足的時候,我們是可以快速的提供資源補充給應用。

LVM是一種源自Unix環境,在Linux上廣泛應用的邏輯虛擬盤存儲方案。借助LVM,可以在保證各個Linux目錄分區穩定,又可以實現各目錄存儲資源靈活分配。

本文主要系統介紹Linux環境下,LVM實現資源擴容步驟方法。留待需要朋友待查。

1、環境介紹

筆者使用Linux 6.5進行測試,背景是一台用於測試搭建的數據庫服務器,需要轉換為正式投產,但是原有可用根節點空間只有50G左右。

[root@Testserver vg_li6]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_li6-lv_root 50G 20G 27G 43% /

tmpfs 3.9G 232K 3.9G 1% /dev/shm

/dev/sda1 485M 39M 421M 9% /boot

/dev/mapper/vg_li6-lv_home 26G 173M 24G 1% /home

目標是通過外圍虛擬化環境,增加存儲空間,並且將增加的空間轉移到/目錄下。也就是增加在vg_li6虛擬磁盤組的lv_root邏輯卷下面。

2、增加磁盤空間和分區

聯系負責虛擬化的同事,為虛擬機增加虛擬磁盤sdb。通過fdisk命令,可以比較清晰的查看到。

[root@Testserver ~]# fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes

255 heads, 63 sectors/track, 10443 cylinders

(篇幅原因,有省略……)

Disk /dev/sdb: 107.4 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

使用fdisk命令進行格式化。

[root@Testserver ~]# fdisk /dev/sdb

Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

Building a new DOS disklabel with disk identifier 0x44e9daf0.

Changes will remain in memory only, until you decide to write them.

After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to

switch off the mode (command 'c') and change display units to

sectors (command 'u').

Command (m for help): n –創建新的磁盤組

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-13054, default 1):

Using default value 1

Last cylinder, +cylinders or +size{K,M,G} (1-13054, default 13054):

Using default value 13054

Command (m for help): w –寫入磁盤分區信息

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

查看fdisk結果。

[root@Testserver ~]# fdisk -l

Disk /dev/sda: 85.9 GB, 85899345920 bytes

255 heads, 63 sectors/track, 10443 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00064fe0

Device Boot Start End Blocks Id System

/dev/sda1 * 1 64 512000 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2 64 10444 83373056 8e Linux LVM

(篇幅原因,有省略……)

Disk /dev/sdb: 107.4 GB, 107374182400 bytes

255 heads, 63 sectors/track, 13054 cylinders

Units = cylinders of 16065 * 512 = 8225280 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x44e9daf0

Device Boot Start End Blocks Id System

/dev/sdb1 1 13054 104856223+ 83 Linux

3、LVM管理設置

總的步驟應該是這樣:首先需要讓LVM認可/dev/sdb1是一個可用的PV(Physical Volume),之後將其加入到VG裡面去,補充VG資源。最後拓展lv_root磁盤空間。

當前LVM情況如下:

lvm> vgs

VG #PV #LV #SN Attr VSize VFree

vg_li6 1 3 0 wz--n- 79.51g 0

lvm> lvs

LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert

lv_home vg_li6 -wi-ao---- 25.63g

lv_root vg_li6 -wi-ao---- 50.00g

lv_swap vg_li6 -wi-ao---- 3.88g

lvm> pvs

PV VG Fmt Attr PSize PFree

/dev/sda2 vg_li6 lvm2 a-- 79.51g 0

此時的pv只有一個/dev/sda2,全部用滿。首先創建/dev/sdb1作為PV。

[root@Testserver ~]# pvcreate /dev/sdb1

dev_is_mpath: failed to get device for 8:17

Physical volume "/dev/sdb1" successfully created

[root@Testserver ~]# pvs

PV VG Fmt Attr PSize PFree

/dev/sda2 vg_li6 lvm2 a-- 79.51g 0

/dev/sdb1 lvm2 a-- 100.00g 100.00g

往VG裡面增加PV,作為空間拓容。

lvm> vgs

VG #PV #LV #SN Attr VSize VFree

vg_li6 1 3 0 wz--n- 79.51g 0

lvm> vgextend vg_li6 /dev/sdb1

Volume group "vg_li6" successfully extended

lvm> vgs

VG #PV #LV #SN Attr VSize VFree

vg_li6 2 3 0 wz--n- 179.50g 100.00g –剩余空間增加

lvm> pvs

PV VG Fmt Attr PSize PFree

/dev/sda2 vg_li6 lvm2 a-- 79.51g 0

/dev/sdb1 vg_li6 lvm2 a-- 100.00g 100.00g

拓展lv_root空間。

[root@Testserver vg_li6]# lvextend -L +70G /dev/vg_li6/lv_root

Extending logical volume lv_root to 120.00 GiB

Logical volume lv_root successfully resized

4、文件系統識別

注意:此時文件系統並沒有認可本次增加。

[root@Testserver vg_li6]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_li6-lv_root 50G 20G 27G 43% /

tmpfs 3.9G 232K 3.9G 1% /dev/shm

/dev/sda1 485M 39M 421M 9% /boot

/dev/mapper/vg_li6-lv_home 26G 173M 24G 1% /home

需要使用resize2fs命令進行刷新。

[root@Testserver vg_li6]# resize2fs /dev/vg_li6/lv_root

resize2fs 1.41.12 (17-May-2010)

Filesystem at /dev/vg_li6/lv_root is mounted on /; on-line resizing required

old desc_blocks = 4, new_desc_blocks = 8

Performing an on-line resize of /dev/vg_li6/lv_root to 31457280 (4k) blocks.

The filesystem on /dev/vg_li6/lv_root is now 31457280 blocks long.

[root@Testserver vg_li6]# df -h

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/vg_li6-lv_root 119G 20G 93G 18% /

tmpfs 3.9G 232K 3.9G 1% /dev/shm

/dev/sda1 485M 39M 421M 9% /boot

/dev/mapper/vg_li6-lv_home 26G 173M 24G 1% /home

5、結論

在之前筆者的文章中,比較詳細的介紹過LVM的相關內容。本文從操作步驟的角度,逐步介紹增加LVM空間的方法。

  • 使用LVM創建彈性磁盤存儲——第一部分 http://www.linuxidc.com/Linux/2014-10/107697.htm
  • 在Linux中擴展/縮減LVM(第二部分) http://www.linuxidc.com/Linux/2014-10/107786.htm
  • 在 LVM中 錄制邏輯卷快照並恢復(第三部分) http://www.linuxidc.com/Linux/2014-11/108867.htm
  • 在LVM中設置精簡資源調配卷(第四部分) http://www.linuxidc.com/Linux/2014-11/109757.htm
  • 使用條塊化I/O管理多個LVM磁盤(第五部分) http://www.linuxidc.com/Linux/2014-12/110532.htm
Copyright © Linux教程網 All Rights Reserved