ZFS文件系統基本使用

ZFS文件系統

 

          ZFS是一款128bit文件系統,總容量是現有64bit文件系統的1.84x1019倍,其支持的單個存儲卷容量達到16EiB(264byte, 即 16x1024x1024TB);一個zpool存儲池可以擁有264個卷,總容量最大256ZiB(278byte);整個系統又可以擁有264個存儲 池。可以說在相當長的未來時間內,ZFS幾乎不太可能出現存儲空間不足的問題。另外,它還擁有自優化,自動校驗數據完整性,存儲池/卷系統易管理等諸多優 點。 較ext3系統有較大運行速率,提高大約30%-40%。

ZFS是基於存儲池的,與典型的映射物理存儲設備的傳統文件系統不同,ZFS所有在存儲池中的文件系統都可以使用存儲池的資源。

什麼是ZFS

ZFS 文件系統是一個革命性的全新的文件系統,它從根本上改變了文件系統的管理方式,這個文件系統的特色和其帶來的好處至今沒有其他文件系統可以與之媲美,ZFS 被設計成強大的、可升級並易於管理的。

ZFS 用“存儲池”的概念來管理物理存儲空間。過去,文件系統都是構建在物理設備之上的。爲了管理這些物理設備,併爲數據提供冗餘,“卷管理”的概念提供了一個單設備的映像。但是這種設計增加了複雜性,同時根本沒法使文件系統向更高層次發展,因爲文件系統不能跨越數據的物理位置。

ZFS 完全拋棄了“卷管理”,不再創建虛擬的卷,而是把所有設備集中到一個存儲池中來進行管理!“存儲池”描述了存儲的物理特徵(設備的佈局,數據的冗餘等等),並扮演一個能夠創建文件系統的專門存儲空間。從此,文件系統不再侷限於單獨的物理設備,而且文件系統還允許物理設備把他們自帶的那些文件系統共享到 這個“池”中。你也不再需要預先規劃好文件系統的大小,因爲文件系統可以在“池”的空間內自動的增大。當增加新的存貯介質時,所有“池”中的所有文件系統能立即使用新增的空間,而不需要而外的操作。在很多情況下,存儲池扮演了一個虛擬內存。

創建一個池的例子

# zpool create tank mirror c1t0d0 c1t1d0

這是一個被鏡像了的池,名叫“tank”。如果命令中的設備包含有其他的文件系統或者以別的形式被使用,那麼命令不能執行。

要查看池是否成功創建,用 zpool list 命令,例如:

# zpool list

 

NAME SIZE USED AVAIL CAP HEALTH ALTROOT

tank 80G 137K 80G 0% ONLINE -

ZFS 文件系統的層次

不管層次如何,根總是池的名字。

1、爲每個用戶及項目創建一個文件系統是個不錯的辦法!

2、ZFS可以爲文件系統分組,屬於同一組的文件系統具有相似的性質,這有點像用戶組的概念!相似的文件系統能夠使用一個共同的名字。

3、大多數文件系統的特性都被用簡單的方式進行控制,這些特徵控制了各種行爲,包括文件系統被mount在哪裏,怎麼被共享,是否被壓縮,是否有限額

創建一個文件系統

# zfs create tank/home

下一步,就可以創建各個文件系統,把它們都歸組到 home 這個文件系統中。同時可以設置home的特性,讓組內的其他文件系統繼承的它的這些特性。當一個文件系統層次創建之後,可以爲這個文件系統設置一些特性,這些特性將被所有的用戶共享:

# zfs set mountpoint=/export/zfs tank/home

# zfs set sharenfs=on tank/home

# zfs set compression=on tank/home

# zfs get compression tank/home

 

NAME PROPERTY VALUE SOURCE

tank/home compression on local

4、創建單個的文件系統

注意:這些文件系統如果被創建好,他們的特性的改變將被限制在home級別,所有的特性能夠在文件系統的使用過程中動態的改變。

# zfs create tank/home/bonwick

# zfs create tank/home/billm

bonwick、billm文件系統從父文件系統home中繼承了特性,因此他們被自動的mount到/export/zfs/user 同時作爲被共享的NFS。管理員根本不需要再手工去編輯 /etc/vfstab 或 /etc/dfs/dfstab 文件。

每個文件系統除了繼承特性外,還可以有自己的特性,

如果用戶bonwick的磁盤空間要限制在10G。

# zfs set quota=10G tank/home/bonwick

5、用 zfs list 命令查看可獲得的文件系統的信息,類似於過去的 df -k 命令了,呵呵 .

# zfs list

 

NAME USED AVAIL REFER MOUNTPOINT

tank 92.0K 67.0G 9.5K /tank

tank/home 24.0K 67.0G 8K /export/zfs

tank/home/billm 8K 67.0G 8K /export/zfs/billm

tank/home/bonwick 8K 10.0G 8K /export/zfs/bonwick

ZFS和傳統文件系統的區別

1、傳統的文件系統被限制在單個磁盤設備之內,它們的尺寸是不能超越單個磁盤設備。

2、過去的文件系統是被影射到一個物理存儲單元,如:分區;所有的ZFS文件系統共享池內的可獲得的存儲空間。

3、ZFS 文件系統不需要通過編輯/etc/vfstab 文件來維護。

ZFS已經拋棄了卷管理,邏輯卷可以不再使用。因爲ZFS在使用和管理raw設備能夠有更好的表現。

ZFS存儲池組件
組成ZFS存儲池的元件有:磁盤、文件、虛擬設備,其中磁盤可以是整個硬盤(c1t0d0),也可以是單個slice(c0t0d0s7)。推薦使用整個硬盤,這樣可以省去分區操作(format)。

RAID-Z 跟 RAID-5的區別:

傳統的raid-5都存在着“寫漏洞”,就是說如果raid-5的stripe在正寫數據時, 如果這時候電源中斷,那麼奇偶校驗數據將跟該部分數據不同步,因此前邊的寫無效;RAID-Z用了“variable-width RAID stripes”技術,因此所有的寫都是full-stripe writes。之所以能實現這種技術,就是因爲ZFS集成了文件系統和設備管理,使得文件系統的元數據有足夠的信息來控制“variable-width RAID stripes”

理論上說,創建RAID-Z需要至少三塊磁盤,這跟raid-5差不多。例如:

raidz c1t0d0 c2t0d0 c3t0d0

還可以更加複雜一點,例如:

raidz c1t0d0 c2t0d0 c3t0d0 c4t0d0 c5t0d0 c6t0d0 c7t0d0 raidz c8t0d0 c9t0d0 c10t0d0 c11t0d0 c12t0d0 c13t0d0 c14t0d0

上邊這個例子創建了14個磁盤的RAID-Z , 這14個盤被分成了兩組,但下邊這句話有點不大明白:

RAID-Z configurations with single-digit groupings of disks should perform better.

(我的理解是:相對於大於10個硬盤組成的RAID-Z,少於10個(single-digit 即1位數)硬盤組成的RAID-Z的性能會更好)

RAID-Z具有自動修復數據的功能

當有損壞的數據塊被檢測到,ZFS不但能從備份中找到相同的正確的數據,而且還能自動的用正確數據修復損壞的數據。

創建ZFS存儲池過程

1、創建一個基本的存儲池,方法很簡單:

# zpool create tank c1t0d0 c1t1d0

這時可以在 /dev/dsk 目錄下看到一個大的slice,數據動態的stripe跨過所有磁盤!

2、創建一個鏡像的存儲池

也是很簡單,只要在上邊命令基礎上增加“mirror”關鍵字就可以了,下邊是創建一個兩路(two-way)鏡像的例子:

# zpool create tank mirror c1d0 c2d0 mirror c3d0 c4d0

3、創建RAID-Z存儲池

使用“raidz”關鍵字就可以了,例如:

# zpool create tank raidz c1t0d0 c2t0d0 c3t0d0 c4t0d0 /dev/dsk/c5t0d0

這裏/dev/dsk/c5t0d0其實跟用c5t0d0是一樣的,由此可以看出,在創建ZFS的時候,磁盤完全可以用物理設備名就可以,不需要指出全路徑。

4、檢測正在使用的設備

在格式化設備之前,ZFS首先決定磁盤是否已經在用或者是否裝有操作系統,如果磁盤在用了,那麼將會出現下邊的錯誤提示:

# zpool create tank c1t0d0 c1t1d0

 

invalid vdev specification

use ’-f’ to override the following errors

/dev/dsk/c1t0d0s0 is currentlymounted on

dev/dsk/c1t0d0s1 is currentlymounted on swap

/dev/dsk/c1t1d0s0 is part of active ZFS pool ’zeepool’

Please see zpool(1M)

有些錯誤可以用 -f 選項來強制覆蓋,但是大多錯誤是不能的。下邊給出不能用-f覆蓋的錯誤情況,這時只能手工糾正錯誤:

Mounted file system The disk or one of its slices contains a file system that is currently mounted. To correct this error, use the umount command.

 

File system in /etc/vfstab The disk contains a file system that is listed in the /etc/vfstab file,but the file system is not currently mounted. To correct this error,remove or comment out the line in the /etc/vfstab file.

 

Dedicated dump device The disk is in use as the dedicated dump device for the system. To correct this error, use the dumpadm command.

 

Part of a ZFS pool The disk or file is part of an active ZFS storage pool. To correct this error, use the zpool command to destroy the pool.

5、創建存儲池時默認的mount點

在創建存儲池時,如果mount點所在目錄不存在,系統會自動創建,如果存在,根數據集(root dataset)會自動mount到這個目錄上。

To create a pool with a different default mount point, use the -m option of the zpool create command:

 

# zpool create home c1t0d0

 

default mountpoint ’/home’ exists and is not empty

use ’-m’ option to specifya different default

 

# zpool create -m /export/zfs home c1t0d0

 

This command creates a new pool home and the home dataset with a mount point of /export/zfs.

6、刪除存儲池

Pools are destroyed by using the zpool destroy command. This command destroys the pool even if it contains mounted datasets.

 

# zpool destroy tank

用ZFS存儲池管理設備

1、增加設備到存儲池

用戶可以通過增加一個新的頂級虛擬設備的方法動態給存儲池增加空間,這個空間立即對空間中的所有數據集(dataset)有效。要增加一個虛擬設備到池中,用“zpool add”命令,例如:

# zpool add zeepool mirror c2t1d0 c2t2d0

該命令也可以用 -n選項進行預覽,例如:

# zpool add -n zeepool mirror c3t1d0 c3t2d0

 

would update ’zeepool’ to the following configuration:

 

zeepool

mirror

c1t0d0

c1t1d0

mirror

c2t1d0

c2t2d0

mirror

c3t1d0

c3t2d0

2、增加和減少一路鏡像

用“zpool attach”命令增加一路鏡像,例如:

# zpool attach zeepool c1t1d0 c2t1d0

在這個例子中,假設 zeepool 是第一點裏的那個zeepool(已經是兩路鏡像),那麼這個命令將把zeepool升級成三路鏡像。

用“zpool detach”命令來分離一路鏡像

# zpool detach zeepool c2t1d0

如果池中不存在鏡像,這個才操作將被拒絕。錯誤提示如下邊這個例子:

# zpool detach newpool c1t2d0 cannot detach c1t2d0: onlyapplicable to mirror and replacing vdevs

3、管理設備的“上線”和“下線”

ZFS允許個別的設備處於offline或者online狀態。當硬件不可靠或者還沒有完全不 能用的時候,ZFS會繼續向設備讀寫數據,但不過是臨時這麼做,因爲設備還能將就使用。一旦設備不能使用,就要指示ZFS忽略該設備,並讓這個壞掉的設備 下線。ZFS不會向offline的設備發送任何請求。

注意:如果只是爲了更換設備(被換設備並沒有出問題),不需要把他們offline。如果offline設備,然後換了一個新設備上去,再把新設備online,這麼做會出錯!

用“zpool offline”命令讓設備下線。例如:

# zpool offline tank c1t0d0

 

bringing device c1t0d0 offline

 

# zpool offline tank c1t0d0

 

cannot offline c1t0d0: no valid replicas

默認情況下,offline設備將永久保持offline狀態,直到系統重新啓動。

要臨時offline一個設備,用-t選項,例如:

# zpool offline -t tank c1t0d0

 

bringing device ’c1t0d0’ offline

用“zpool onine”命令使設備上線

# zpool online tank c1t0d0

 

bringing device c1t0d0 online

注意:如果只是爲了更換設備(被換設備並沒有出問題),不需要把他們offline。如果offline設備,然後換了一個新設備上去,再把新設備online,這麼做會出錯!在這個問題上文檔是這麼說的:

Note that you cannot use device onlining to replace a disk. If you offline a device, replace the drive, and try to bring it online, it remains in the faulted state.

4、清掃存儲池設備

如果設備因爲出現錯誤,被offline了,可以用“zpool clear”命令清掃錯誤。如果沒有特別指定,zpool clear命令清掃池裏所有設備。例如:

# zpool clear tank

如果要清掃指定設備,例如:

# zpool clear tank c1t0d0

5、替換存儲池裏的設備

用“zpool replace”命令替換池中設備,例如:

# zpool replace tank c1t1d0 c1t2d0

c1t1d0 被 c1t2d0 替換

注意:如果是mirror或者RAID-Z,替換設備的容量必須大於或等於所有設備最小容量!

查詢ZFS存儲池的狀態

1、ZFS存儲池的基本信息

用“zpool list”命令查看存儲池的基本信息,例如:

# zpool list

 

NAME SIZE USED AVAIL CAP HEALTH ALTROOT

tank 80.0G 22.3G 47.7G 28% ONLINE -

dozer 1.2T 384G 816G 32% ONLINE -

NAME The name of the pool.

SIZE The total size of the pool, equal to the sum of the size of all top-level virtual devices.

USED The amount of space allocated by all datasets and internal metadata. Note that

this amount is different from the amount of space as reported at the file system level.

AVAILABLE The amount of unallocated space in the pool.

CAPACITY (CAP) The amount of space used, expressed as a percentage of total space.

HEALTH The current health status of the pool.

ALTROOT The alternate root of the pool, if any.

可以通過指定名字來查看某一個池的狀態,例如:

# zpool list tank

 

NAME SIZE USED AVAIL CAP HEALTH ALTROOT

tank 80.0G 22.3G 47.7G 28% ONLINE -

如果要有選擇看狀態列表,可以用-o選項

# zpool list -o name,size

 

NAME SIZE

tank 80.0G

dozer 1.2T

Scripting ZFS Storage Pool Output

The default output for the zpool list command is designed for readability, and is not easy to use as art of a shell script. To aid programmatic uses of the command, the -H option can be used to uppress the column headings and separate fields by tabs, rather than by spaces. For example, to request a simple list of all pool names on the system:

上邊這段話簡單說就是爲了方便編程,用-H選項,這樣輸出列表的域之間用tab相隔,而不是空格。

# zpool list -Ho name

 

tank

dozer

Here is another example:

# zpool list -H -o name,size

 

tank 80.0G

dozer 1.2T

2、查看存儲池的I/O狀態

用“zpool iostat”命令查看存儲池的I/O狀態,例如:

# zpool iostat

 

capacity operations bandwidth

pool used avail read write read write

---------- ----- ----- ----- ----- ----- -----

tank 100G 20.0G 1.2M 102K 1.2M 3.45K

dozer 12.3G 67.7G 132K 15.2K 32.1K 1.20K

3、ZFS存儲池的健康狀態

用“zpool status”查看健康狀態

 

發佈了18 篇原創文章 · 獲贊 3 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章