在 Centos 8 中使用 Stratis 管理本地存儲(chǔ)
Stratis是RHEL8/Centos8中提供的一個(gè)新的本地存儲(chǔ)管理工具,它將有助于在塊設(shè)備上創(chuàng)建分層存儲(chǔ)。在RHEL8/Centos8中,可以通過安裝兩個(gè)軟件包獲得Stratis。在RHEL7,我們有了BTRFS文件系統(tǒng),Red Hat在RHEL 8中刪除了BTRFS支持,并提供了Stratis本地存儲(chǔ)管理系統(tǒng)。
為了開始使用Stratis,我們需要添加一些磁盤設(shè)備,并創(chuàng)建一個(gè)單獨(dú)的池,在一個(gè)Stratis池中,可以創(chuàng)建多個(gè)文件系統(tǒng)。
安裝Stratis
通過下面命令使用yum安裝stratis:
- [root@localhost ~]# yum -y install stratis*
安裝完成之后,設(shè)置開機(jī)啟用并立即啟動(dòng):
- [root@localhost ~]# systemctl enable stratisd --now
查看以下是否啟動(dòng):
列出可用磁盤
在這添加了5個(gè)2GB磁盤,使用下面命令列出磁盤:
- [root@localhost ~]# lsblk
列出現(xiàn)有的池和文件系統(tǒng):
使用下面幾條命令列出塊設(shè)備、stratis池、文件系統(tǒng):
- [root@localhost ~]# stratis blockdev list
- [root@localhost ~]# stratis pool list
- [root@localhost ~]# stratis filesystem list
創(chuàng)建池和文件系統(tǒng)
首先,我們創(chuàng)建“data01_pool”的池。將/dev/sda,/dev/sdb,/dev/sdc,/dev/sdd添加到該池中:
- [root@localhost ~]# stratis pool create data01_pool /dev/sd{a..d}
- [root@localhost ~]# stratis pool list
- [root@localhost ~]# stratis blockdev list
上面命令創(chuàng)建"data01_pool"池、查看池、查看塊設(shè)備。
下面從“data01_pool”池中創(chuàng)建兩個(gè)文件系統(tǒng):
- [root@localhost ~]# stratis filesystem create data01_pool user_data01
- [root@localhost ~]# stratis filesystem create data01_pool user_data02
下面命令列出創(chuàng)建的文件系統(tǒng):
- [root@localhost ~]# stratis filesystem list
- 或者
- [root@localhost ~]# stratis fs list
上圖中列出的文件系統(tǒng)中,字段Device是stratis設(shè)備的位置。
掛載創(chuàng)建好的文件系統(tǒng)
一旦從池中創(chuàng)建了文件系統(tǒng),請(qǐng)創(chuàng)建一個(gè)掛載點(diǎn)并掛載文件系統(tǒng)。默認(rèn)情況下在創(chuàng)建文件系統(tǒng)時(shí),它將使用XFS文件系統(tǒng)對(duì)其進(jìn)行格式化。
- # 創(chuàng)建掛載點(diǎn)
- [root@localhost ~]# mkdir /user_data01
- [root@localhost ~]# mkdir /user_data02
- # 掛載文件系統(tǒng)
- [root@localhost ~]# mount /stratis/data01_pool/user_data01 /user_data01/
- [root@localhost ~]# mount /stratis/data01_pool/user_data02 /user_data02/
使用df -h查看掛載的情況:
- [root@localhost ~]# df -h /user_data*
- Filesystem Size Used Avail Use% Mounted on
- /dev/mapper/stratis-1-359fd7072d8349d390741a1a71f885fb-thin-fs-0657c26979ed443aa4d3a70c15606e1c 1.0T 7.2G 1017G 1% /user_data01
- /dev/mapper/stratis-1-359fd7072d8349d390741a1a71f885fb-thin-fs-b91b970f23d94eb6b2ed56f347f770d2 1.0T 7.2G 1017G 1% /user_data02
希望你已經(jīng)觀察到我們沒有格式化文件系統(tǒng)。Stratis程序?yàn)槲覀兘鉀Q了這一問題,并創(chuàng)建了XFS類型的文件系統(tǒng)。
同樣,由于自動(dòng)精簡配置,默認(rèn)情況下,它將顯示文件系統(tǒng)大小為1 TB,并且該大小僅是虛擬的,而不是實(shí)際的。要檢查實(shí)際大小,您將必須使用Stratis命令
使用df -hT /user*匹配出user_data01和user_data02掛載點(diǎn)的文件系統(tǒng),可以看到他們的類型都是XFS格式。
在/etc/fstab中添加開機(jī)掛載的條目
首先需要獲取文件系統(tǒng)的UUID,有兩種方式:
第一種方式,是通過使用stratis fs list就可以獲取到文件系統(tǒng)的UUID。
- [root@localhost ~]# stratis fs list
第二種方式,使用blkid獲取塊存儲(chǔ)的uuid,過濾出stratis文件系統(tǒng):
- [root@localhost ~]# blkid|grep stratis
下面就是將掛載信息寫入到/etc/fstab中:
- [root@localhost ~]# echo "UUID=0657c26979ed443aa4d3a70c15606e1c /user_data01 xfs defaults,x-systemd.requires=stratis.service 0 0" >> /etc/fstab
- [root@localhost ~]# echo "UUID=b91b970f23d94eb6b2ed56f347f770d2 /user_data02 xfs defaults,x-systemd.requires=stratis.service 0 0" >> /etc/fstab
檢查Stratis守護(hù)程序版本
如果需要檢查Stratis運(yùn)行的守護(hù)進(jìn)程版本,使用如下命令:
- [root@localhost ~]# stratis daemon version
- 2.1.0
向Stratis池中添加其他磁盤
在Stratis管理下,將新的塊設(shè)備添加到現(xiàn)有池非常容易。在上一篇文章《在Centos 中創(chuàng)建Stratis本地存儲(chǔ)(一)》設(shè)置中,“ data01_pool”中有4個(gè)磁盤,現(xiàn)在我們需要通過添加新磁盤來擴(kuò)展池中的空間。使用選項(xiàng)add-data來添加新磁盤,下面向"data01_pool"池中添加"/dev/sde"磁盤。
- [root@localhost ~]# stratis pool list
- Name Total Physical Properties
- data01_pool 8 GiB / 1.11 GiB / 6.89 GiB ~Ca,~Cr
- [root@localhost ~]# stratis pool add-data data01_pool /dev/sde
- [root@localhost ~]# stratis pool list
- Name Total Physical Properties
- data01_pool 10 GiB / 1.12 GiB / 8.88 GiB ~Ca,~Cr
可以看到上圖中擴(kuò)展前是8G,擴(kuò)展之后變成了10G。再查看一下stratis的塊設(shè)備:
- [root@localhost ~]# stratis pool list
- Name Total Physical Properties
- data01_pool 8 GiB / 1.11 GiB / 6.89 GiB ~Ca,~Cr
- [root@localhost ~]# stratis pool add-data data01_pool /dev/sde
- [root@localhost ~]# stratis pool list
- Name Total Physical Properties
- data01_pool 10 GiB / 1.12 GiB / 8.88 GiB ~Ca,~Cr
重命名池和文件系統(tǒng)
Stratis具有在運(yùn)行中重命名池或文件系統(tǒng)的功能,而不會(huì)影響任何正在運(yùn)行的設(shè)置。下面讓我們將當(dāng)前池名稱“data01_pool”重命名為“data01_pool_old”。
- [root@localhost ~]# stratis pool rename data01_pool date01_pool_old
下面我們來重命名文件系統(tǒng),重命名文件系統(tǒng)類似于重命名池:
- [root@localhost ~]# stratis fs rename date01_pool_old user_data01 sys_data01
在Stratis中創(chuàng)建快照
Stratis可以對(duì)任何文件系統(tǒng)進(jìn)行快照。讓我們對(duì)服務(wù)器中現(xiàn)有文件系統(tǒng)進(jìn)行快照。下面先再user_data01中寫入一些數(shù)據(jù):
- [root@localhost ~]# touch /user_data01/file{1..100}.txt
下面來打快照:
- [root@localhost ~]# stratis fs snapshot date01_pool_old sys_data01 sys_data01_snap
可以看到快照已生成。下面掛載/stratis/data01_pool_old/sys_data01_snap這個(gè)快照到/mnt目錄,然后查看文件是否存在。
- [root@localhost ~]# mount /stratis/date01_pool_old/sys_data01_snap /mnt/
刪除Stratis文件系統(tǒng)
刪除Stratis文件系統(tǒng)之前,需要在/etc/fstab中刪除stratis相關(guān)的那兩個(gè)文件系統(tǒng)條目。下面我只注釋掉,沒有刪除條目。
卸載文件系統(tǒng):
- [root@localhost ~]# umount /user_data01
- [root@localhost ~]# umount /user_data02
下面就開始刪除文件系統(tǒng)啦:
- [root@localhost ~]# stratis fs destroy date01_pool_old sys_data01
- [root@localhost ~]# stratis fs destroy date01_pool_old user_data02
- [root@localhost ~]# stratis fs destroy date01_pool_old sys_data01_snap
- [root@localhost ~]# stratis fs destroy date01_pool_old user_data02_snap
刪除Stratis池
要?jiǎng)h除Stratis池,我們應(yīng)該刪除在其下創(chuàng)建的所有文件系統(tǒng)。否則會(huì)提示:
- [root@localhost ~]# stratis pool destroy data01_pool_old
- Execution failure caused by:
- BUSY: filesystems remaining on pool
下面來刪除池:
- [root@localhost ~]# stratis pool destroy date01_pool_old
- [root@localhost ~]# stratis pool
- Name Total Physical Properties
總結(jié)
Stratis是RHEL8/Centos8中提供的一個(gè)新的本地存儲(chǔ)管理工具,它將有助于在塊設(shè)備上創(chuàng)建分層存儲(chǔ)。在RHEL8/Centos8中,可以通過安裝兩個(gè)軟件包獲得Stratis。我們已經(jīng)看到了如何通過添加磁盤并重命名來管理Stratis分層存儲(chǔ)。
本文轉(zhuǎn)載自微信公眾號(hào)「Linux就該這么學(xué)」,可以通過以下二維碼關(guān)注。轉(zhuǎn)載本文請(qǐng)聯(lián)系Linux就該這么學(xué)公眾號(hào)。