精簡卷是可以創建大於可用磁盤的邏輯卷。使用精簡卷,你可以管理可用空間的存儲池(稱爲精簡池),可以在應用程序需要時將其分配給任意數量的設備。精簡池可以在需要時進行動態擴展,以節省成本。 |
下面我們添加一塊硬盤。創建物理卷,然後創建卷組:
[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- <19.00g <2.00g vg_thin 1 0 0 wz--n- <20.00g <20.00g
上面已經創建好一個新的卷組了,名字爲vg_thin
。然後在現有卷組的中創建一個精簡池:
[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
創建精簡池之後,我們就可以從精簡池中創建精簡卷。在本實驗中創建四個精簡卷,每個精簡卷的大小爲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.
將上面創建的四個精簡卷格式化爲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
創建掛載點,並掛載:
[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%
再創建兩個200 MB的精簡卷。可以發現創建這兩個精簡卷會超過所設置的精簡池的大小,雖然可以創建成功,但這樣做會有更大的風險,並提示一些超額的警告。
[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.
下面我們刪掉剛纔創建的tp_lv_user5和tp_lv_user6,在lvm.conf配置文件中開啓超額保護,並重新創建這兩個精簡卷:
[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
配置文件,將下兩個參數的值修改一下:
# 當精簡池的使用率超過此百分比時,將自動擴展該池,將其更改爲100將禁用自動擴展。可接受的最小值是50。 thin_pool_autoextend_threshold = 80 # 通過自動擴展精簡池,會增加這個百分比的額外空間。添加到精簡池的額外空間量是其當前大小的百分比。 thin_pool_autoextend_percent = 20
下面創建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填充內容,直到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. 擴展精簡池的元數據
- 2. 然後再擴展精簡池。
要擴展精簡池,我們不應該立即繼續擴展精簡池。首先,通過運行lvs -a
查看現有元數據使用的大小情況。
[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
元數據的當前大小僅爲4 MB。讓我們在當前大小的基礎上添加4MB。
[root@localhost ~]# lvextend --poolmetadatasize +4M vg_thin/thin_pool
可以看到[thin_pool_tmeta]
已經變成8M了。
完成擴展元數據後,開始將精簡池擴展到所需的大小。將精簡池擴容量再添加1G容量。
[root@localhost ~]# lvextend -L +1G /dev/vg_thin/thin_pool
現在大小已變成2.2G了。
擴展精簡卷和擴展精簡池類似:
[root@localhost ~]# lvextend -L +200M /dev/vg_thin/tp_lv_user1
要刪除精簡池,首先需要卸載所有文件系統,然後刪除所有精簡卷,最後刪除精簡池。
# 卸載分區 [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 命令查看以下,是否已經刪除乾淨:
[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
精簡卷是可以創建大於可用磁盤的邏輯卷。使用精簡卷,你可以管理可用空間的存儲池(稱爲精簡池),可以在應用程序需要時將其分配給任意數量的設備。精簡池可以在需要時進行動態擴展,以節省成本。