主頁 > 知識庫 > 詳解基于Linux的LVM無縫磁盤水平擴容

詳解基于Linux的LVM無縫磁盤水平擴容

熱門標(biāo)簽:蕪湖呼叫中心外呼系統(tǒng)哪家強 咸陽穩(wěn)定外呼系統(tǒng)公司 ec外呼系統(tǒng)怎么樣 征服者快捷酒店地圖標(biāo)注 貴陽語音電銷機器人 漯河電銷外呼系統(tǒng)價格 電銷機器人怎么錄音 貴港市機器人外呼系統(tǒng)團隊 天津外呼系統(tǒng)運營商

環(huán)境

名稱 屬性
CPU x5650
內(nèi)存 4G
磁盤 20G+4TB

 

這時候,我們假設(shè)服務(wù)器已經(jīng)有如下東西:

  • 安裝好了Parted(yum install parted)
  • 分區(qū)容量已經(jīng)告捷,公司為服務(wù)器增加了一塊4T硬盤用來增加容量!
  • 除了/boot分區(qū)外,其余都為LVM 模式的擴展邏輯分區(qū)

軟件安裝與信息查看

首先查看軟件是否安裝:

[root@Candy ~]# rpm -qa | grep lvm
lvm2-libs-2.02.118-2.el6.x86_64
lvm2-2.02.118-2.el6.x86_64
[root@Candy ~]# lv
lvchange   lvextend   lvmdiskscan lvmsar    lvresize
lvconvert  lvm     lvmdump   lvreduce   lvs
lvcreate   lvmchange  lvmetad   lvremove   lvscan
lvdisplay  lvmconf   lvmsadc   lvrename
[root@Candy ~]# rpm -qa | grep parted
parted-2.1-29.el6.x86_64

軟件準(zhǔn)備好后順便查看下 VM 硬件:

[root@Candy ~]# df -h
Filesystem      Size Used Avail Use% Mounted on
/dev/mapper/vg_candy-root
           7.3G 231M 6.7G  4% /
tmpfs         1.9G   0 1.9G  0% /dev/shm
/dev/sda1       477M  30M 422M  7% /boot
/dev/mapper/vg_candy-home
           3.9G 8.0M 3.7G  1% /home
/dev/mapper/vg_candy-usr
           3.9G 382M 3.3G 11% /usr
/dev/mapper/vg_candy-var
           3.9G  63M 3.6G  2% /var
[root@Candy ~]# fdisk -l
Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 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: 0x0006e71c
  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    2611  20458496  8e Linux LVM
Disk /dev/sdb: 4398.0 GB, 4398046511104 bytes
255 heads, 63 sectors/track, 534698 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
Disk /dev/mapper/vg_candy-root: 8061 MB, 8061452288 bytes
255 heads, 63 sectors/track, 980 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
Disk /dev/mapper/vg_candy-usr: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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
Disk /dev/mapper/vg_candy-var: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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
Disk /dev/mapper/vg_candy-home: 4294 MB, 4294967296 bytes
255 heads, 63 sectors/track, 522 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
[root@Candy ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb

這時候我們看到,Centos 已經(jīng)知道有個sdb的盤了,但是沒掛載與分區(qū)。

使用Parted進行擴容前的分區(qū)

現(xiàn)在假設(shè)除了/boot 其余分區(qū)都滿了! 我們需要先進行分區(qū),將4T的硬盤用上(/dev/sdb).

[root@Candy ~]# parted /dev/sdb
GNU Parted 2.1
使用 /dev/sdb
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel
新的磁盤標(biāo)簽類型? gpt
(parted) mkpart
分區(qū)名稱? []?
文件系統(tǒng)類型? [ext2]? ext4
起始點? 0T
結(jié)束點? 4T
(parted) p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 4398GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start  End   Size  File system Name 標(biāo)志
 1   1049kB 4398GB 4398GB
(parted)set 1 lvm on
(parted)p
Model: VMware, VMware Virtual S (scsi)
Disk /dev/sdb: 4398GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number Start  End   Size  File system Name 標(biāo)志
1   1049kB 4398GB 4398GB           lvm
(parted)q
[root@Candy ~]# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1

現(xiàn)在讓我們來解釋一下操作:

  1. mklabel將磁盤轉(zhuǎn)換為gpt分區(qū),因為MBR分區(qū)無法支持TB級硬盤(具體請自行查閱,parted當(dāng)然也支持TB級以下的操作)
  2. mkpart將轉(zhuǎn)換好的gpt磁盤進行分區(qū),需要提供文件系統(tǒng)類型、開始點、結(jié)束點。
  3. 輸入p 打印出剛才才做后生成的分區(qū)。
  4. set 1 lvm on 是將num為1的分區(qū),tager設(shè)置為LVM ,這樣才能添加到vm卷組里

下一步,我們查看我們的LVM組名叫什么:

[root@Candy ~]# vgs
 VG    #PV #LV #SN Attr  VSize VFree
 vg_candy  1  4  0 wz--n- 19.51g  0
 
[root@Candy ~]# vgdisplay
 --- Volume group ---
 VG Name        vg_candy
 System ID
 Format        lvm2
 Metadata Areas    1
 Metadata Sequence No 5
 VG Access       read/write
 VG Status       resizable
 MAX LV        0
 Cur LV        4
 Open LV        4
 Max PV        0
 Cur PV        1
 Act PV        1
 VG Size        19.51 GiB
 PE Size        4.00 MiB
 Total PE       4994
 Alloc PE / Size    4994 / 19.51 GiB
 Free PE / Size    0 / 0
 VG UUID        Gcm5Ml-fc88-Xk5q-xuPC-Kj7Y-alfK-i770Gc
[root@Candy ~]# lvscan
 ACTIVE      '/dev/vg_candy/usr' [4.00 GiB] inherit
 ACTIVE      '/dev/vg_candy/var' [4.00 GiB] inherit
 ACTIVE      '/dev/vg_candy/home' [4.00 GiB] inherit
 ACTIVE      '/dev/vg_candy/root' [7.51 GiB] inherit
[root@Candy ~]#

知道lvm卷組叫 'vg_candy'了, 我們就使用vgextend來向lvm 'vg_candy' 卷組添加成員了.

[root@Candy ~]# vgextend vag_candy /dev/sdb1
Physical volume "/dev/sdb1" successfully created
Volume group "vg_candy" successfully extended

現(xiàn)在我們再用vgs命令看一下pv個數(shù):

[root@Candy ~]# vgs
VG    #PV #LV #SN Attr  VSize VFree
vg_candy  2  4  0 wz--n- 4.02t 4.00t

大家對比未添加時的vgs是否有看到PV個數(shù)從1變?yōu)?了!

現(xiàn)在讓我們用vgdisplay看看現(xiàn)在分區(qū)的容量.

[root@Candy ~]# vgdisplay
 --- Volume group ---
 VG Name        vg_candy
 System ID
 Format        lvm2
 Metadata Areas    2
 Metadata Sequence No 6
 VG Access       read/write
 VG Status       resizable
 MAX LV        0
 Cur LV        4
 Open LV        4
 Max PV        0
 Cur PV        2
 Act PV        2
 VG Size        4.02 TiB
 PE Size        4.00 MiB
 Total PE       1053569
 Alloc PE / Size    4994 / 19.51 GiB
 Free PE / Size    1048575 / 4.00 TiB
 VG UUID        Gcm5Ml-fc88-Xk5q-xuPC-Kj7Y-alfK-i770Gc

再次對比未添加的vgdiplay命令發(fā)現(xiàn),F(xiàn)reePE 的value 從 0 / 0 變?yōu)?1048575 / 4.00 TiB . 這樣說明Candy已經(jīng)成功將4TB的lvm 分區(qū)添加進入到vg_candy 邏輯卷組里了。

現(xiàn)在我們對所有邏輯分區(qū)進行擴容前,df -h 看看有哪些分區(qū)。

[root@Candy ~]# df -h
Filesystem         Size Used Avail Use% Mounted on
/dev/mapper/vg_candy-root 7.3G 231M 6.7G  4% /
 tmpfs           1.9G   0 1.9G  0% /dev/shm
/dev/sda1         477M  30M 422M  7% /boot
/dev/mapper/vg_candy-home 3.9G 8.0M 3.7G  1% /home         
/dev/mapper/vg_candy-usr  3.9G 382M 3.3G 11% /usr
/dev/mapper/vg_candy-var  3.9G  63M 3.6G  2% /var

現(xiàn)在麻煩的事已經(jīng)做完了,接下來就剩下為分區(qū)進行擴容了.

為磁盤進行擴容

假設(shè):我們需要向 這些分區(qū)都添加500G容量: / 、 /home 、 /usr 、 /var

[root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-root
 Size of logical volume vg_candy/root changed from 7.51 GiB (1922 extents) to 507.51 GiB (129922 extents).
 Logical volume root successfully resized
 
[root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-home
 Size of logical volume vg_candy/home changed from 4.00 GiB (1024 extents) to 504.00 GiB (129024 extents).
 Logical volume home successfully resized
 
[root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-usr
 Size of logical volume vg_candy/usr changed from 4.00 GiB (1024 extents) to 504.00 GiB (129024 extents).
 Logical volume usr successfully resized
 
[root@Candy ~]# lvextend -L +500G /dev/mapper/vg_candy-var
 Size of logical volume vg_candy/var changed from 4.00 GiB (1024 extents) to 504.00 GiB (129024 extents).
 Logical volume var successfully resized

大家注意,這一步操作時不可逆的! 如果輸入了錯誤的分區(qū)名字還好! 如果添加到其它分區(qū)了,就得重復(fù)N遍來縮容,比較麻煩哦! 建議大家注仔細(xì)核對上面的FileSystem. 切記切記....

提示擴容成功! 讓我們再次用上述命令查看LVM信息:

[root@Candy ~]# vgs
 VG    #PV #LV #SN Attr  VSize VFree
 vg_candy  2  4  0 wz--n- 4.02t 2.05t 
 
[root@Candy ~]# lvscan
 ACTIVE      '/dev/vg_candy/usr' [504.00 GiB] inherit
 ACTIVE      '/dev/vg_candy/var' [504.00 GiB] inherit
 ACTIVE      '/dev/vg_candy/home' [504.00 GiB] inherit
 ACTIVE      '/dev/vg_candy/root' [507.51 GiB] inherit
 
[root@Candy ~]# vgdisplay
 --- Volume group ---
 VG Name        vg_candy
 System ID
 Format        lvm2
 Metadata Areas    2
 Metadata Sequence No 10
 VG Access       read/write
 VG Status       resizable
 MAX LV        0
 Cur LV        4
 Open LV        4
 Max PV        0
 Cur PV        2
 Act PV        2
 VG Size        4.02 TiB
 PE Size        4.00 MiB
 Total PE       1053569
 Alloc PE / Size    516994 / 1.97 TiB
 Free PE / Size    536575 / 2.05 TiB
 VG UUID        Gcm5Ml-fc88-Xk5q-xuPC-Kj7Y-alfK-i770Gc
 
[root@Candy ~]# df -h
Filesystem         Size Used Avail Use% Mounted on
/dev/mapper/vg_candy-root 7.3G 231M 6.7G  4% /
 tmpfs           1.9G   0 1.9G  0% /dev/shm
/dev/sda1         477M  30M 422M  7% /boot
/dev/mapper/vg_candy-home 3.9G 8.0M 3.7G  1% /home         
/dev/mapper/vg_candy-usr  3.9G 382M 3.3G 11% /usr
/dev/mapper/vg_candy-var  3.9G  63M 3.6G  2% /var

看到這里大家可能奇怪! 為什么df -h 還沒變呢?

刷新磁盤信息與寫入

我們需要用resize2fs 重設(shè)分區(qū)大小, 這樣才能使df -h 也能生效.

而resize2fs 需要的時間與你給予的容量線性疊加. 也就是說你給的容量越多,resize2fs 的需要的時間就越多。

[root@Candy ~]# resize2fs /dev//mapper/vg_candy-root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev//mapper/vg_candy-root is mounted on /; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32
Performing an on-line resize of /dev//mapper/vg_candy-root to 133040128 (4k) blocks.
The filesystem on /dev//mapper/vg_candy-root is now 133040128 blocks long.

[root@Candy ~]# resize2fs /dev//mapper/vg_candy-usr
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev//mapper/vg_candy-usr is mounted on /usr; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32
Performing an on-line resize of /dev//mapper/vg_candy-usr to 132120576 (4k) blocks.
The filesystem on /dev//mapper/vg_candy-usr is now 132120576 blocks long.

[root@Candy ~]# resize2fs /dev//mapper/vg_candy-var
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev//mapper/vg_candy-var is mounted on /var; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32
Performing an on-line resize of /dev//mapper/vg_candy-var to 132120576 (4k) blocks.
The filesystem on /dev//mapper/vg_candy-var is now 132120576 blocks long.

[root@Candy ~]# resize2fs /dev//mapper/vg_candy-home
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev//mapper/vg_candy-home is mounted on /home; on-line resizing required old desc_blocks = 1, new_desc_blocks = 32
Performing an on-line resize of /dev//mapper/vg_candy-home to 132120576 (4k) blocks.
The filesystem on /dev//mapper/vg_candy-home is now 132120576 blocks long.

[root@Candy ~]# df -h
Filesystem          Size Used Avail Use% Mounted on
/dev/mapper/vg_candy-root   500G 245M 474G  1% /
tmpfs             1.9G   0 1.9G  0% /dev/shm
/dev/sda1           477M  30M 422M  7% /boot
/dev/mapper/vg_candy-home   496G  16M 471G  1% /home
/dev/mapper/vg_candy-usr   496G 390M 471G  1% /usr
/dev/mapper/vg_candy-var   496G  71M 471G  1% /var

結(jié)束語

順便給大家曬一張重啟后系統(tǒng)自動掛載的圖!

Linux系統(tǒng)還是比較聰明的. 其實重啟與不重啟都能使用, 只是為大家演示重啟后的效果.

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

標(biāo)簽:怒江 西寧 西藏 攀枝花 香港 濰坊 東營 淮北

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《詳解基于Linux的LVM無縫磁盤水平擴容》,本文關(guān)鍵詞  詳解,基于,Linux,的,LVM,無縫,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《詳解基于Linux的LVM無縫磁盤水平擴容》相關(guān)的同類信息!
  • 本頁收集關(guān)于詳解基于Linux的LVM無縫磁盤水平擴容的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章