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

成都創(chuàng)新互聯(lián)服務(wù)項(xiàng)目包括河?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)驗(yàn)、深度合作伙伴關(guān)系等,向廣大中小型企業(yè)、政府機(jī)構(gòu)等提供互聯(lián)網(wǎng)行業(yè)的解決方案,河?xùn)|網(wǎng)站推廣取得了明顯的社會(huì)效益與經(jīng)濟(jì)效益。目前,我們服務(wù)的客戶以成都為中心已經(jīng)輻射到河?xùn)|省份的部分城市,未來相信會(huì)繼續(xù)擴(kuò)大服務(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)建好一個(gè)新的卷組了,名字為vg_thin。然后在現(xiàn)有卷組的中創(chuàng)建一個(gè)精簡池:
[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)建精簡卷。在本實(shí)驗(yàn)中創(chuàng)建四個(gè)精簡卷,每個(gè)精簡卷的大小為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)建的四個(gè)精簡卷格式化為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)建掛載點(diǎn),并掛載:
[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
向這四個(gè)目錄寫入一些文件:
[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
然后運(yùn)行下面命令查看以下使用空間:
[root@localhost ~]# lvs
我們可以注意到精簡池利用率為41.41%
開啟防止精簡池空間耗盡的保護(hù)
再創(chuàng)建兩個(gè)200 MB的精簡卷??梢园l(fā)現(xiàn)創(chuàng)建這兩個(gè)精簡卷會(huì)超過所設(shè)置的精簡池的大小,雖然可以創(chuàng)建成功,但這樣做會(huì)有更大的風(fēng)險(xiǎn),并提示一些超額的警告。
[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配置文件中開啟超額保護(hù),并重新創(chuàng)建這兩個(gè)精簡卷:
[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配置文件,將下兩個(gè)參數(shù)的值修改一下:
# 當(dāng)精簡池的使用率超過此百分比時(shí),將自動(dòng)擴(kuò)展該池,將其更改為100將禁用自動(dòng)擴(kuò)展??山邮艿淖钚≈凳?0。
thin_pool_autoextend_threshold = 80
# 通過自動(dòng)擴(kuò)展精簡池,會(huì)增加這個(gè)百分比的額外空間。添加到精簡池的額外空間量是其當(dāng)前大小的百分比。
thin_pool_autoextend_percent = 20
下面創(chuàng)建tp_lv_user5和tp_lv_user6兩個(gè)精簡卷:
[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%,我們可以看到精簡池的容量擴(kuò)容了。
[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,這就說明當(dāng)精簡池的使用率超過80%時(shí),提升20%的容量。
如何擴(kuò)展精簡池
擴(kuò)展精簡池時(shí),我們需要遵循兩個(gè)步驟:
-
\1. 擴(kuò)展精簡池的元數(shù)據(jù)
-
\2. 然后再擴(kuò)展精簡池。
要擴(kuò)展精簡池,我們不應(yīng)該立即繼續(xù)擴(kuò)展精簡池。首先,通過運(yùn)行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
擴(kuò)展精簡池metadata的大小
元數(shù)據(jù)的當(dāng)前大小僅為4 MB。讓我們?cè)诋?dāng)前大小的基礎(chǔ)上添加4MB。
[root@localhost ~]# lvextend --poolmetadatasize +4M vg_thin/thin_pool
可以看到[thin_pool_tmeta]已經(jīng)變成8M了。
擴(kuò)展精簡池的大小
完成擴(kuò)展元數(shù)據(jù)后,開始將精簡池?cái)U(kuò)展到所需的大小。將精簡池?cái)U(kuò)容量再添加1G容量。
[root@localhost ~]# lvextend -L +1G /dev/vg_thin/thin_pool
現(xiàn)在大小已變成2.2G了。
擴(kuò)展精簡卷
擴(kuò)展精簡卷和擴(kuò)展精簡池類似:
[root@localhost ~]# lvextend -L +200M /dev/vg_thin/tp_lv_user1
刪除精簡卷、精簡池
要?jiǎng)h除精簡池,首先需要卸載所有文件系統(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)建大于可用磁盤的邏輯卷。使用精簡卷,你可以管理可用空間的存儲(chǔ)池(稱為精簡池),可以在應(yīng)用程序需要時(shí)將其分配給任意數(shù)量的設(shè)備。精簡池可以在需要時(shí)進(jìn)行動(dòng)態(tài)擴(kuò)展,以節(jié)省成本。
網(wǎng)站名稱:Centos8部署LVM精簡邏輯卷
文章URL:http://www.dlmjj.cn/article/dhojicd.html


咨詢
建站咨詢
