iT邦幫忙

DAY 29
3

回應鐵人賽的文章變鐵人系列 第 29

[Reply] ZFS 簡單入門教學(二)

接續 上一篇 ZFS 的實作。

單一磁碟Pool
最單純的pool是存在於單一裝置。
pools是用 zpool create 的指令產生:

# zpool create herring /home/ocean/disk1
# zpool list
NAME                    SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
herring                 123M   51.5K    123M     0%  ONLINE     -

不需磁卷管理、設定、newf或掛載的動作。
這樣就把一正運作的pool掛在ZFS檔案系統的 /herring 的下面
(在Mac OS X 則是在 /Volumes/herring,
也可看到是被掛在Mac的桌面)。
怎麼調整掛載點,則在之後談到。

在新檔案系統裡產生個檔案:

# mkfile 32m /herring/foo
# ls -lh /herring/foo
-rw------T   1 root     root         32M Mar  7 19:56 /herring/foo

# zpool list
NAME                    SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
herring                 123M   32.1M   90.9M    26%  ONLINE     -

新檔案佔約pool的1/4的容量(從CAP的值)。
如果在ZFS完成寫入磁碟前執行list指令,
會看到USED及CAP的值是比較低,
過一會兒後再試一下看看。

現在用 zpool destroy 來砍掉pool

# zpool destroy herring
# zpool list
no pools available

在 Mac OS X 的環境下,要砍掉之前,
需要強制卸載檔案系統(用 umount -f /Volumes/herring)
因為會被 fseventsd 所使用。

如果pool在使用中而做砍掉的動作,
會出現警告資訊。
之後會討論如何復原意外被砍掉的pool。
鏡射Pool
單一磁碟組成的pool並不提供任何的備援。
其中一種提供備援的方法是,
鏡射兩個磁碟成為一個pool:

# zpool create trout mirror /home/ocean/disk1 /home/ocean/disk2

# zpool list
NAME                    SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
trout                   123M   51.5K    123M     0%  ONLINE     -

用 zpool status 來看詳細資料:

# zpool status trout
  pool: trout
 state: ONLINE
 scrub: none requested
config:
        NAME                          STATE     READ WRITE CKSUM
        trout                         ONLINE       0     0     0
          mirror                      ONLINE       0     0     0
            /home/ocean/disk1         ONLINE       0     0     0
            /home/ocean/disk2         ONLINE       0     0     0

errors: No known data errors

可看到pool包含一組有兩個磁碟的鏡射。
現在來產生一個檔案,看看USED怎麼變化:

# mkfile 32m /trout/foo

# zpool list
NAME                    SIZE    USED   AVAIL    CAP  HEALTH     ALTROOT
trout                   123M   32.1M   90.9M    26%  ONLINE     -

之前磁碟被用了1/4,
但現資料是備援地存在兩個磁碟,
現在隨便覆寫任意資料在第一個磁碟。
(如果是用實體磁碟的話,
可停用或移開一個磁碟)

# dd if=/dev/random of=/home/ocean/disk1 bs=512 count=1

ZFS 在讀寫檔案時,
會自動檢查錯誤。
但我們用 zfs scrub 來強制查錯誤。

# zpool scrub trout

# zpool status
  pool: trout
 state: DEGRADED
status: One or more devices could not be used because the label is missing or
        invalid.  Sufficient replicas exist for the pool to continue
        functioning in a degraded state.
action: Replace the device using 'zpool replace'.
   see: http://www.sun.com/msg/ZFS-8000-4J
 scrub: scrub completed with 0 errors on Wed Mar  7 20:42:07 2007
config:
        NAME                          STATE     READ WRITE CKSUM
        trout                         DEGRADED     0     0     0
          mirror                      DEGRADED     0     0     0
            /home/ocean/disk1         UNAVAIL      0     0     0 corrupted data
            /home/ocean/disk2         ONLINE       0     0     0

errors: No known data errors

之前我們用 dd 處理的磁碟,
狀態是 UNAVAIL 及 corrupted data 的描述,
但整個pool卻沒有錯誤訊息,
也能正常地讀寫pool:

# mkfile 32m /trout/bar
# ls -l /trout/
total 131112
-rw------T   1 root     root     33554432 Mar  7 20:43 bar
-rw------T   1 root     root     33554432 Mar  7 20:35 foo

為了維持備援,
用其他磁碟來取代那壞掉的磁碟;
如果是以實體的磁碟取代,
可用 zpool replace 的指令。
而在這以檔案為基礎的例子,
我們從鏡射裡移除磁碟,
及重建一個:
用 zpool detach 來卸載裝置:

# zpool detach trout /home/ocean/disk1

# zpool status trout
  pool: trout
 state: ONLINE
 scrub: scrub completed with 0 errors on Wed Mar  7 20:42:07 2007
config:
        NAME                        STATE     READ WRITE CKSUM
        trout                       ONLINE       0     0     0
          /home/ocean/disk2         ONLINE       0     0     0

errors: No known data errors

# rm /home/ocean/disk1
# mkfile 128m /home/ocean/disk1

再用 zpool attach 把另個裝置掛載到已有裝置的鏡射裡:

# zpool attach trout /home/ocean/disk2 /home/ocean/disk1

系列文章


上一篇
[Reply] ZFS 簡單入門教學(一)
下一篇
[Reply] ZFS 簡單入門教學(三)
系列文
回應鐵人賽的文章變鐵人30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言