dd if=/dev/zero of=/data01/zfs.disk1 bs=8192 count=102400
dd if=/dev/zero of=/data01/zfs.disk2 bs=8192 count=102400
dd if=/dev/zero of=/data01/zfs.disk3 bs=8192 count=102400
dd if=/dev/zero of=/data01/zfs.disk4 bs=8192 count=102400
dd if=/dev/zero of=/data01/zfs.disk5 bs=8192 count=102400
dd if=/dev/zero of=/data01/zfs.disk6 bs=8192 count=102400
创建测试pool
这里使用了ZIL(zfs intent log)
zpool create zp2 mirror /data01/zfs.disk1 /data01/zfs.disk2 mirror /data01/zfs.disk3 /data01/zfs.disk4 log mirror /data01/zfs.disk5 /data01/zfs.disk6
查看状态
zpool status -v zp2
pool: zp2
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
zp2 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/data01/zfs.disk1 ONLINE 0 0 0
/data01/zfs.disk2 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
/data01/zfs.disk3 ONLINE 0 0 0
/data01/zfs.disk4 ONLINE 0 0 0
logs
mirror-2 ONLINE 0 0 0
/data01/zfs.disk5 ONLINE 0 0 0
/data01/zfs.disk6 ONLINE 0 0 0
因为是mirror,所以可以做detach操作
zpool detach zp2 /data01/zfs.disk4
再看状态
zpool status -v zp2
pool: zp2
state: ONLINE
scan: none requested
config:
NAME STATE READ WRITE CKSUM
zp2 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/data01/zfs.disk1 ONLINE 0 0 0
/data01/zfs.disk2 ONLINE 0 0 0
/data01/zfs.disk3 ONLINE 0 0 0
logs
mirror-2 ONLINE 0 0 0
/data01/zfs.disk5 ONLINE 0 0 0
/data01/zfs.disk6 ONLINE 0 0 0
加回到mirror
zpool attach zp2 /data01/zfs.disk3 /data01/zfs.disk4
zpool status -v zp2
pool: zp2
state: ONLINE
scan: resilvered 33.5K in 0h0m with 0 errors on Wed Apr 26 14:46:06 2017
config:
NAME STATE READ WRITE CKSUM
zp2 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/data01/zfs.disk1 ONLINE 0 0 0
/data01/zfs.disk2 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
/data01/zfs.disk3 ONLINE 0 0 0
/data01/zfs.disk4 ONLINE 0 0 0
logs
mirror-2 ONLINE 0 0 0
/data01/zfs.disk5 ONLINE 0 0 0
/data01/zfs.disk6 ONLINE 0 0 0
新加一块热备盘
dd if=/dev/zero of=/data01/zfs.disk7 bs=8192 count=102400
zpool add zp2 spare /data01/zfs.disk7
zpool status -v zp2
pool: zp2
state: ONLINE
scan: resilvered 33.5K in 0h0m with 0 errors on Wed Apr 26 14:46:06 2017
config:
NAME STATE READ WRITE CKSUM
zp2 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/data01/zfs.disk1 ONLINE 0 0 0
/data01/zfs.disk2 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
/data01/zfs.disk3 ONLINE 0 0 0
/data01/zfs.disk4 ONLINE 0 0 0
logs
mirror-2 ONLINE 0 0 0
/data01/zfs.disk5 ONLINE 0 0 0
/data01/zfs.disk6 ONLINE 0 0 0
spares
/data01/zfs.disk7 AVAIL
模拟故障,脱机一块设备/data01/zfs.disk1
zpool offline zp2 /data01/zfs.disk1
zpool status -v zp2
pool: zp2
state: DEGRADED
status: One or more devices has been taken offline by the administrator.
Sufficient replicas exist for the pool to continue functioning in a
degraded state.
action: Online the device using 'zpool online' or replace the device with
'zpool replace'.
scan: resilvered 33.5K in 0h0m with 0 errors on Wed Apr 26 14:46:06 2017
config:
NAME STATE READ WRITE CKSUM
zp2 DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
/data01/zfs.disk1 OFFLINE 0 0 0
/data01/zfs.disk2 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
/data01/zfs.disk3 ONLINE 0 0 0
/data01/zfs.disk4 ONLINE 0 0 0
logs
mirror-2 ONLINE 0 0 0
/data01/zfs.disk5 ONLINE 0 0 0
/data01/zfs.disk6 ONLINE 0 0 0
spares
/data01/zfs.disk7 AVAIL
注意这里不会自动替换,需要人为干预,用热备盘替换offline的设备
zpool replace zp2 /data01/zfs.disk1 /data01/zfs.disk7
zpool status -v zp2
pool: zp2
state: DEGRADED
status: One or more devices has been taken offline by the administrator.
Sufficient replicas exist for the pool to continue functioning in a
degraded state.
action: Online the device using 'zpool online' or replace the device with
'zpool replace'.
scan: resilvered 29K in 0h0m with 0 errors on Wed Apr 26 15:10:18 2017
config:
NAME STATE READ WRITE CKSUM
zp2 DEGRADED 0 0 0
mirror-0 DEGRADED 0 0 0
spare-0 OFFLINE 0 0 0
/data01/zfs.disk1 OFFLINE 0 0 0
/data01/zfs.disk7 ONLINE 0 0 0
/data01/zfs.disk2 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
/data01/zfs.disk3 ONLINE 0 0 0
/data01/zfs.disk4 ONLINE 0 0 0
logs
mirror-2 ONLINE 0 0 0
/data01/zfs.disk5 ONLINE 0 0 0
/data01/zfs.disk6 ONLINE 0 0 0
spares
/data01/zfs.disk7 INUSE currently in use
模拟插入新磁盘
rm -f /data01/zfs.disk1
dd if=/dev/zero of=/data01/zfs.disk1 bs=8192 count=102400
用新的磁盘替换掉坏的
zpool replace zp2 /data01/zfs.disk1 /data01/zfs.disk1
查看状态
zpool status -v zp2
pool: zp2
state: ONLINE
scan: resilvered 55K in 0h0m with 0 errors on Wed Apr 26 15:22:13 2017
config:
NAME STATE READ WRITE CKSUM
zp2 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/data01/zfs.disk1 ONLINE 0 0 0
/data01/zfs.disk2 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
/data01/zfs.disk3 ONLINE 0 0 0
/data01/zfs.disk4 ONLINE 0 0 0
logs
mirror-2 ONLINE 0 0 0
/data01/zfs.disk5 ONLINE 0 0 0
/data01/zfs.disk6 ONLINE 0 0 0
spares
/data01/zfs.disk7 AVAIL
清除错误计数
zpool clear zp2
添加3块vdev,这里看到提示不建议使用不匹配的replication level,之前是mirror,现在是raidz2
dd if=/dev/zero of=/data01/zfs.disk8 bs=8192 count=102400
dd if=/dev/zero of=/data01/zfs.disk9 bs=8192 count=102400
dd if=/dev/zero of=/data01/zfs.disk10 bs=8192 count=102400
zpool add zp2 raidz2 /data01/zfs.disk8 /data01/zfs.disk9 /data01/zfs.disk10
invalid vdev specification
use '-f' to override the following errors:
mismatched replication level: pool uses mirror and new vdev is raidz
但是加上-f可以强制创建,不建议在生产中使用
zpool add -f zp2 raidz2 /data01/zfs.disk8 /data01/zfs.disk9 /data01/zfs.disk10
zpool status -v zp2
pool: zp2
state: ONLINE
scan: resilvered 55K in 0h0m with 0 errors on Wed Apr 26 15:22:13 2017
config:
NAME STATE READ WRITE CKSUM
zp2 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/data01/zfs.disk1 ONLINE 0 0 0
/data01/zfs.disk2 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
/data01/zfs.disk3 ONLINE 0 0 0
/data01/zfs.disk4 ONLINE 0 0 0
raidz2-3 ONLINE 0 0 0
/data01/zfs.disk8 ONLINE 0 0 0
/data01/zfs.disk9 ONLINE 0 0 0
/data01/zfs.disk10 ONLINE 0 0 0
logs
mirror-2 ONLINE 0 0 0
/data01/zfs.disk5 ONLINE 0 0 0
/data01/zfs.disk6 ONLINE 0 0 0
spares
/data01/zfs.disk7 AVAIL
添加高速缓存,生产环境可以使用SSD,高速缓存是内存和磁盘之间的附加层,可以提高随机读的性能
添加之后,会从内存中读取数据填充到高速缓存
dd if=/dev/zero of=/data01/zfs.disk11 bs=8192 count=102400
报错,不可以用文件,必须是磁盘或者磁盘分区
zpool add zp2 cache /data01/zfs.disk11
cannot add to 'zp2': cache device must be a disk or disk slice
使用-f参数添加成功
zpool add zp2 cache /dev/sda3
invalid vdev specification
use '-f' to override the following errors:
/dev/sda3 is part of potentially active pool 'zp1'
zpool add -f zp2 cache /dev/sda3
zpool status -v zp2
pool: zp2
state: ONLINE
scan: resilvered 55K in 0h0m with 0 errors on Wed Apr 26 15:22:13 2017
config:
NAME STATE READ WRITE CKSUM
zp2 ONLINE 0 0 0
mirror-0 ONLINE 0 0 0
/data01/zfs.disk1 ONLINE 0 0 0
/data01/zfs.disk2 ONLINE 0 0 0
mirror-1 ONLINE 0 0 0
/data01/zfs.disk3 ONLINE 0 0 0
/data01/zfs.disk4 ONLINE 0 0 0
raidz2-3 ONLINE 0 0 0
/data01/zfs.disk8 ONLINE 0 0 0
/data01/zfs.disk9 ONLINE 0 0 0
/data01/zfs.disk10 ONLINE 0 0 0
logs
mirror-2 ONLINE 0 0 0
/data01/zfs.disk5 ONLINE 0 0 0
/data01/zfs.disk6 ONLINE 0 0 0
cache
sda3 ONLINE 0 0 0
spares
/data01/zfs.disk7 AVAIL