新聞中心
LVM是Linux環(huán)境中對磁盤分區(qū)進行管理的一種機制,是建立在硬盤和分區(qū)之上、文件系統(tǒng)之下的一個邏輯層,可提高磁盤分區(qū)管理的靈活性。RHEL5默認安裝的分區(qū)格式就是LVM邏輯卷的格式

成都創(chuàng)新互聯(lián)服務(wù)項目包括河?xùn)|網(wǎng)站建設(shè)、河?xùn)|網(wǎng)站制作、河?xùn)|網(wǎng)頁制作以及河?xùn)|網(wǎng)絡(luò)營銷策劃等。多年來,我們專注于互聯(lián)網(wǎng)行業(yè),利用自身積累的技術(shù)優(yōu)勢、行業(yè)經(jīng)驗、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,河?xùn)|網(wǎng)站推廣取得了明顯的社會效益與經(jīng)濟效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到河?xùn)|省份的部分城市,未來相信會繼續(xù)擴大服務(wù)區(qū)域并繼續(xù)獲得客戶的支持與信任!
系統(tǒng)環(huán)境
Centos8
創(chuàng)建精簡池
下面我們添加一塊硬盤。創(chuàng)建物理卷,然后創(chuàng)建卷組:
[root@localhost ~]# pvcreate /dev/sda
Physical volume "/dev/sda" successfully created.
[root@localhost ~]# vgcreate vg_thin /dev/sda
Volume group "vg_thin" successfully created
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
cl 1 2 0 wz--n-
上面已經(jīng)創(chuàng)建好一個新的卷組了,名字為vg_thin。然后在現(xiàn)有卷組的中創(chuàng)建一個精簡池:
[root@localhost ~]# lvcreate -L 1G -T vg_thin/thin_pool
Thin pool volume with chunk size 64.00 KiB can address at most 15.81 TiB of data.
Logical volume "thin_pool" created.
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root cl -wi-ao---- 15.00g
swap cl -wi-ao---- 2.00g
thin_pool vg_thin twi-a-tz-- 1.00g 0.00 10.94
創(chuàng)建精簡卷
創(chuàng)建精簡池之后,我們就可以從精簡池中創(chuàng)建精簡卷。在本實驗中創(chuàng)建四個精簡卷,每個精簡卷的大小為200 MB。
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user1
Logical volume "tp_lv_user1" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user2
Logical volume "tp_lv_user2" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user3
Logical volume "tp_lv_user3" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user4
Logical volume "tp_lv_user4" created.
Centos8中創(chuàng)建LVM精簡邏輯卷Centos8中創(chuàng)建LVM精簡邏輯卷
格式化并掛載精簡卷
將上面創(chuàng)建的四個精簡卷格式化為xfs格式:
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user1
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user2
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user3
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user4
創(chuàng)建掛載點,并掛載:
[root@localhost ~]# mkdir -p /mnt/user{1..4}
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user1 /mnt/user1
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user2 /mnt/user2
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user3 /mnt/user3
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user4 /mnt/user4
向這四個目錄寫入一些文件:
[root@localhost ~]# dd if=/dev/zero of=/mnt/user1/test.img bs=1M count=100
[root@localhost ~]# dd if=/dev/zero of=/mnt/user2/test.img bs=1M count=100
[root@localhost ~]# dd if=/dev/zero of=/mnt/user3/test.img bs=1M count=100
[root@localhost ~]# dd if=/dev/zero of=/mnt/user4/test.img bs=1M count=100
然后運行下面命令查看以下使用空間:
[root@localhost ~]# lvs
我們可以注意到精簡池利用率為41.41%
開啟防止精簡池空間耗盡的保護
再創(chuàng)建兩個200 MB的精簡卷??梢园l(fā)現(xiàn)創(chuàng)建這兩個精簡卷會超過所設(shè)置的精簡池的大小,雖然可以創(chuàng)建成功,但這樣做會有更大的風(fēng)險,并提示一些超額的警告。
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user5
Logical volume "tp_lv_user5" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user6
WARNING: Sum of all thin volume sizes (1.17 GiB) exceeds the size of thin pool vg_thin/thin_pool (1.00 GiB).
WARNING: You have not turned on protection against thin pools running out of space.
WARNING: Set activation/thin_pool_autoextend_threshold below 100 to trigger automatic extension of thin pools before they get full.
Logical volume "tp_lv_user6" created.
下面我們刪掉剛才創(chuàng)建的tp_lv_user5和tp_lv_user6,在lvm.conf配置文件中開啟超額保護,并重新創(chuàng)建這兩個精簡卷:
[root@localhost ~]# lvremove -f /dev/vg_thin/tp_lv_user5
Logical volume "tp_lv_user5" successfully removed
[root@localhost ~]# lvremove -f /dev/vg_thin/tp_lv_user6
Logical volume "tp_lv_user6" successfully removed
編輯/etc/lvm/lvm.conf配置文件,將下兩個參數(shù)的值修改一下:
# 當精簡池的使用率超過此百分比時,將自動擴展該池,將其更改為100將禁用自動擴展??山邮艿淖钚≈凳?0。
thin_pool_autoextend_threshold = 80
# 通過自動擴展精簡池,會增加這個百分比的額外空間。添加到精簡池的額外空間量是其當前大小的百分比。
thin_pool_autoextend_percent = 20
下面創(chuàng)建tp_lv_user5和tp_lv_user6兩個精簡卷:
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user5
Logical volume "tp_lv_user5" created.
[root@localhost ~]# lvcreate -V 200M -T vg_thin/thin_pool -n tp_lv_user6
Logical volume "tp_lv_user6" created.
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user5
[root@localhost ~]# mkfs.xfs /dev/vg_thin/tp_lv_user6
[root@localhost ~]# mkdir -p /mnt/user{5..6}
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user5 /mnt/user5
[root@localhost ~]# mount /dev/vg_thin/tp_lv_user6 /mnt/user6
看一下使用的情況: 下面我們向/mnt/user5和/mnt/user6填充內(nèi)容,直到thin_pool精簡池的使用率超過80%,我們可以看到精簡池的容量擴容了。
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root cl -wi-ao---- 15.00g
swap cl -wi-ao---- 2.00g
thin_pool vg_thin twi-aotz-- 1.20g 75.94 22.66
tp_lv_user1 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user2 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user3 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user4 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user5 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user6 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
可以看到上面,thin_pool精簡池的容量提升了200M,這就說明當精簡池的使用率超過80%時,提升20%的容量。
如何擴展精簡池
擴展精簡池時,我們需要遵循兩個步驟:
-
\1. 擴展精簡池的元數(shù)據(jù)
-
\2. 然后再擴展精簡池。
要擴展精簡池,我們不應(yīng)該立即繼續(xù)擴展精簡池。首先,通過運行lvs -a查看現(xiàn)有元數(shù)據(jù)使用的大小情況。
[root@localhost ~]# lvs -a
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root cl -wi-ao---- 15.00g
swap cl -wi-ao---- 2.00g
[lvol0_pmspare] vg_thin ewi------- 4.00m
thin_pool vg_thin twi-aotz-- 1.20g 75.94 22.66
[thin_pool_tdata] vg_thin Twi-ao---- 1.20g
[thin_pool_tmeta] vg_thin ewi-ao---- 4.00m
tp_lv_user1 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user2 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user3 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user4 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user5 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
tp_lv_user6 vg_thin Vwi-aotz-- 200.00m thin_pool 77.97
擴展精簡池metadata的大小
元數(shù)據(jù)的當前大小僅為4 MB。讓我們在當前大小的基礎(chǔ)上添加4MB。
[root@localhost ~]# lvextend --poolmetadatasize +4M vg_thin/thin_pool
可以看到[thin_pool_tmeta]已經(jīng)變成8M了。
擴展精簡池的大小
完成擴展元數(shù)據(jù)后,開始將精簡池擴展到所需的大小。將精簡池擴容量再添加1G容量。
[root@localhost ~]# lvextend -L +1G /dev/vg_thin/thin_pool
現(xiàn)在大小已變成2.2G了。
擴展精簡卷
擴展精簡卷和擴展精簡池類似:
[root@localhost ~]# lvextend -L +200M /dev/vg_thin/tp_lv_user1
刪除精簡卷、精簡池
要刪除精簡池,首先需要卸載所有文件系統(tǒng),然后刪除所有精簡卷,最后刪除精簡池。
# 卸載分區(qū)
[root@localhost ~]# umount /mnt/user{1..6}
# 刪除精簡卷
[root@localhost ~]# lvremove -y /dev/vg_thin/tp_lv_user[1-6]
Logical volume "tp_lv_user1" successfully removed
Logical volume "tp_lv_user2" successfully removed
Logical volume "tp_lv_user3" successfully removed
Logical volume "tp_lv_user4" successfully removed
Logical volume "tp_lv_user5" successfully removed
Logical volume "tp_lv_user6" successfully removed
# 刪除精簡池
[root@localhost ~]# lvremove -y /dev/vg_thin/thin_pool
Logical volume "thin_pool" successfully removed
使用lvs 命令查看以下,是否已經(jīng)刪除干凈:
[root@localhost ~]# lvs -a
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root cl -wi-ao---- 15.00g
swap cl -wi-ao---- 2.00g
總結(jié)
精簡卷是可以創(chuàng)建大于可用磁盤的邏輯卷。使用精簡卷,你可以管理可用空間的存儲池(稱為精簡池),可以在應(yīng)用程序需要時將其分配給任意數(shù)量的設(shè)備。精簡池可以在需要時進行動態(tài)擴展,以節(jié)省成本。
當前名稱:Centos8部署LVM精簡邏輯卷
文章路徑:http://m.fisionsoft.com.cn/article/dhojicd.html


咨詢
建站咨詢
