说到文件系统,相必都知道,在计算机系统里是个非常关键的东西,为什么关键呢.因为计算机里的文件的组织和管理全靠它了.常用的文件系统有WIN:FAT,FAT32,NTFS;solaris:ufs; AIX:JFS,JFS2和GPFS并行文件系统以及网络文件系统NFS,等等,好多啦.
至于ZFS,是SUN公司的最新开发的文件系统,ZFS的优点太多太强大了,就不必多说了,用的人都能体会到ZFS和UFS是完全两个概念的东西。唯一不确定的只有稳定性和可靠性需要在实践中来检验。
ZFS主要使用两条命令及其子命令:
zfs
zpool
zpool 命令菜单:
# zpool
missing command
usage: zpool command args ...
where 'command' is one of the following:
create [-fn] [-R root] [-m mountpoint]
...
destroy [-f]
add [-fn] ...
remove
list [-H] [-o field[,field]*] [pool] ...
iostat [-v] [pool] ... [interval [count]]
status [-vx] [pool] ...
online ...
offline [-t] ...
clear [device]
attach [-f]
detach
replace [-f] [new_device]
scrub [-s] ...
import [-d dir] [-D]
import [-d dir] [-D] [-f] [-o opts] [-R root] -a
import [-d dir] [-D] [-f] [-o opts] [-R root ] [newpool]
export [-f] ...
upgrade
upgrade -v
upgrade <-a | pool>
history []
1.1 创建zpool
ZFS文件系统是建立在存储池pool的基础上,所以要建立文件系统必须先建立底层的pool。
1.1.1 创建单边zpool
zpool create yz c3t0d0 c3t0d1
# zpool create First c3t2d0 c3t4d0
invalid vdev specification
use '-f' to override the following errors:
/dev/dsk/c3t2d0s2 contains a ufs filesystem.
/dev/dsk/c3t2d0s7 contains a ufs filesystem.
加入pool的硬盘可以是整块盘,也可以是某个分区,条件允许的时候建议使用整块盘,这样便于pool对硬盘的管理。由于加入pool的磁盘之前曾经使用过ufs,所以在创建过程中需要使用-f选项来忽视ufs文件格式将硬盘强制加入pool中。
Note:加入pool的硬盘的原来数据会被破坏。
# zpool create –f first c3t2d0 c3t3d0 创建两块盘组成的pool
# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
first 136G 90K 136G 0% ONLINE -
# zpool status
pool: first
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
first ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
errors: No known data errors
1.1.2 创建mirror pool
# zpool create –f yz mirror c3t0d0 c3t1d0
# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
first 136G 90K 136G 0% ONLINE -
yz 68G 6.08G 61.9G 8% ONLINE -
# zpool status
pool: yz
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
yz ONLINE 0 0 0
mirror ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
errors: No known data errors
创建镜像盘组成的pool,如果加入的硬盘为多个的话,则默认的raid类型为raid1+0,下例中,镜像为3份,单盘为68G,而pool总量为136G。
RCGSM-root-/yztest/2> zpool create xxx mirror c3t0d0 c3t1d0 c3t2d0 mirror c3t3d0 c3t4d0 c3t5d0
RCGSM-root-/yztest/2> zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
xxx 136G 90K 136G 0% ONLINE -
RCGSM-root-/yztest/2> zpool status
pool: xxx
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
xxx ONLINE 0 0 0
mirror ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
mirror ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
c3t5d0 ONLINE 0 0 0
errors: No known data errors
# zpool status -x
all pools are healthy
# df -h
Filesystem size used avail capacity Mounted on
first 134G 24K 134G 1% /first
1.1.3 创建raidz zpool
zpool支持的raidz有raidz1和raidz2两种,类似于传统的raid5,raidz至少需要3个devices来实现对数据的校验。raidz的有点在于基本不会造成资源浪费,raidz的容量基本和其包含的devices的硬盘空间容量的和一致。
zpool create poolname raidz2 c3t2d0 c3t3d0 c3t4d0
# zpool create poolname raidz2 c3t2d0 c3t3d0 c3t4d0
# zpool list
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
poolname 204G 267K 204G 0% ONLINE -
# zpool status
pool: poolname
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz2 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
1.2 删除zpool
zpool destroy poolname
如果zpool正在使用会提示设备正忙,强制删除pool使用-f参数。
RCGSM-root-/yztest/2> zpool destroy yz
cannot unmount '/yztest/2': Device busy
could not destroy 'yz': could not unmount datasets
RCGSM-root-/yztest/2> zpool destroy -f yz
1.3 对zpool进行管理
1.3.1 镜像和拆镜像
如果创建zpool时,物理盘为单,可以对其进行镜像,命令格式为
zpool attach xxx c3t0d0/old c3t5d0//new
例子:
# zpool status
pool: xxx
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
xxx ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
errors: No known data errors
# zpool attach xxx c3t5d0
missing
specification
usage:
attach [-f]
# zpool attach xxx c3t0d0 c3t5d0
# zpool status xxx
pool: xxx
state: ONLINE
scrub: resilver completed with 0 errors on Tue Oct 7 17:11:18 2008
config:
NAME STATE READ WRITE CKSUM
xxx ONLINE 0 0 0
mirror ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t5d0 ONLINE 0 0 0
errors: No known data errors
使用zpool detach的子命令可以对镜像进行拆除
例子:
# zpool detach xxx c3t5d0
# zpool status
pool: xxx
state: ONLINE
scrub: resilver completed with 0 errors on Tue Oct 7 17:11:18 2008
config:
NAME STATE READ WRITE CKSUM
xxx ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
errors: No known data errors
1.3.2 添加zpool空间
使用zpool add子命令对pool进行扩容,使用-n参数可以模拟出扩容后的效果。
例子:
# zpool status
pool: xxx
state: ONLINE
scrub: resilver completed with 0 errors on Tue Oct 7 17:11:18 2008
config:
NAME STATE READ WRITE CKSUM
xxx ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
errors: No known data errors
# zpool add xxx c3t5d0
# zpool status xxx
pool: xxx
state: ONLINE
scrub: resilver completed with 0 errors on Wed Oct 8 08:53:02 2008
config:
NAME STATE READ WRITE CKSUM
xxx ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t5d0 ONLINE 0 0 0
errors: No known data errors
# zpool list xxx
NAME SIZE USED AVAIL CAP HEALTH ALTROOT
xxx 136G 91K 136G 0% ONLINE -
#/mnt> zpool status
pool: poolname
state: ONLINE
scrub: resilver completed with 0 errors on Wed Oct 8 13:16:35 2008
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
#/mnt> zpool add -n poolname c3t1d0
invalid vdev specification
use '-f' to override the following errors:
mismatched replication level: pool uses raidz and new vdev is disk
#/mnt> zpool add -n -f poolname c3t1d0
would update 'poolname' to the following configuration:
poolname
raidz1
c3t0d0
c3t3d0
c3t4d0
c3t1d0
1.3.3 spare盘的添加和删除
对于raidz和mirror而言,zpool支持spare盘的设置,而且spare盘可以支持多个pool,比如在一个mirror和另一个raidz使用同一块硬盘来做spare。
# zpool add poolname spare c3t5d0
# zpool add xxx spare c3t5d0
# zpool status
pool: poolname
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
spares
c3t5d0 AVAIL
errors: No known data errors
pool: xxx
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
xxx ONLINE 0 0 0
mirror ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
spares
c3t5d0 AVAIL
errors: No known data errors
删除spare盘使用zpool remove子命令
# zpool remove xxx c3t5d0
# zpool remove poolname c3t5d0
# zpool status -x
all pools are healthy
# zpool status -v
pool: poolname
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
pool: xxx
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
xxx ONLINE 0 0 0
mirror ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
errors: No known data error
1.4 zpool的维护/故障盘的更换
当zpool内的硬盘出现问题需要更换的时候,就要使用zpool replace 子命令进行更换了。
#/mnt> zpool replace
missing pool name argument
usage:
replace [-f] [new_device]
#/mnt> zpool replace poolname c3t2d0 c3t0d0
#/mnt> zpool status
pool: poolname
state: ONLINE
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scrub: resilver in progress, 6.71% done, 0h3m to go
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
replacing ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
#/mnt> zpool status
pool: poolname
state: ONLINE
scrub: resilver completed with 0 errors on Wed Oct 8 13:16:35 2008
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
添加磁盘空间的时候可以对添加的硬盘进行数据保护,如mirror和raidz
#/mnt> zpool add -n -f poolname raidz2 c3t1d0 c3t2d0 c3t5d0
would update 'poolname' to the following configuration:
poolname
raidz1
c3t0d0
c3t3d0
c3t4d0
raidz2
c3t1d0
c3t2d0
c3t5d0
例子:raidz出现坏盘的解决
在本例中,我把poolname中的c3t0d0号盘offline之后将其拆卸出3310。
#/mnt> zpool offline poolname c3t0d0
Bringing device c3t0d0 offline
#/mnt> zpool status
pool: poolname
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'.
scrub: resilver completed with 0 errors on Wed Oct 8 13:16:35 2008
config:
NAME STATE READ WRITE CKSUM
poolname DEGRADED 0 0 0
raidz1 DEGRADED 0 0 0
c3t0d0 OFFLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
这样在执行zpool offline后,拆除该硬盘,并执行online操作,这时会发现pool中的硬盘状态为FAULTED。这时候由于raidz的校验功能,可以通过replace对硬盘进行更换并恢复数据到新盘上。
#/mnt> zpool status
pool: poolname
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:
scrub: resilver completed with 0 errors on Wed Oct 8 14:03:47 2008
config:
NAME STATE READ WRITE CKSUM
poolname DEGRADED 0 0 0
raidz1 DEGRADED 0 0 0
c3t0d0 FAULTED 0 0 0 corrupted data
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
#/mnt> zpool replace poolname c3t0d0 c3t2d0
#/mnt> zpool status
pool: poolname
state: DEGRADED
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scrub: resilver in progress, 2.97% done, 0h3m to go
config:
NAME STATE READ WRITE CKSUM
poolname DEGRADED 0 0 0
raidz1 DEGRADED 0 0 0
replacing DEGRADED 0 0 0
c3t0d0 FAULTED 0 0 0 corrupted data
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
# zpool status
pool: poolname
state: ONLINE
scrub: resilver completed with 0 errors on Wed Oct 8 14:10:02 2008
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
如果是在原来的槽位上更换过硬盘以后再同步,直接输入:
zpool replace poolname c3t0d0
# zpool replace poolname c3t2d0
# zpool status
pool: poolname
state: DEGRADED
status: One or more devices is currently being resilvered. The pool will
continue to function, possibly in a degraded state.
action: Wait for the resilver to complete.
scrub: resilver in progress, 3.75% done, 0h2m to go
config:
NAME STATE READ WRITE CKSUM
poolname DEGRADED 0 0 0
raidz1 DEGRADED 0 0 0
replacing DEGRADED 0 0 0
c3t2d0s0/o UNAVAIL 0 0 0 cannot open
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
errors: No known data errors
1.5 zpool的迁移
迁移zpool的时候需要确认zpool中所有的文件系统没有被使用,如果需要不顾一切的去迁移,可以加上-f参数。
# zpool export poolname
# zpool status
no pools available
#
# zpool import
pool: poolname
id: 10727618928512001646
state: ONLINE
action: The pool can be imported using its name or numeric identifier.
config:
poolname ONLINE
raidz1 ONLINE
c3t2d0 ONLINE
c3t3d0 ONLINE
c3t4d0 ONLINE
# zpool status
no pools available
# zpool import 10727618928512001646 使用pool的id和name都可以
# zpool status
pool: poolname
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
poolname ONLINE 0 0 0
raidz1 ONLINE 0 0 0
c3t2d0 ONLINE 0 0 0
c3t3d0 ONLINE 0 0 0
c3t4d0 ONLINE 0 0 0
1.6 恢复销毁的zpool
zpool 被destroy后,可以通过zpool import –D命令来查看上一个被销毁的zpool是否可以被恢复。
#/zzz> cp -r /opt /zzz
^C
#/zzz> ls
opt
#/zzz> du -sh .
3.6G .
#/zzz> cd
# zpool destroy zzz
# zpool import -D
pool: zzz
id: 7148440739272373876
state: ONLINE (DESTROYED)
action: The pool can be imported using its name or numeric identifier.
config:
zzz ONLINE
c3t0d0 ONLINE
c3t1d0 ONLINE
# zpool import -Df zzz
# zpool status
pool: zzz
state: ONLINE
scrub: none requested
config:
NAME STATE READ WRITE CKSUM
zzz ONLINE 0 0 0
c3t0d0 ONLINE 0 0 0
c3t1d0 ONLINE 0 0 0
errors: No known data errors
# cd /zzz
#/zzz> ls
opt
#/zzz> du –sh .
3.6G .
如果通过import –D看到的pool的状态不是online的话,那么这个pool就不可恢复了。
#/zzz> cd
# zpool destroy zzz
# zpool create zzz c3t0d0
# zpool import -D
pool: zzz
id: 7148440739272373876
state: FAULTED (DESTROYED)
status: One or more devices are missing from the system.
action: The pool cannot be imported. Attach the missing
devices and try again.
see:
config:
zzz UNAVAIL missing device
c3t1d0 ONLINE
Additional devices are known to be part of this pool, though their
exact configuration cannot be determined.
# zpool destroy zzz
# zpool import -D
pool: zzz
id: 7148440739272373876
state: FAULTED (DESTROYED)
status: One or more devices are missing from the system.
action: The pool cannot be imported. Attach the missing
devices and try again.
see:
config:
zzz UNAVAIL missing device
c3t1d0 ONLINE
Additional devices are known to be part of this pool, though their
exact configuration cannot be determined.
pool: zzz
id: 6600816109531139366
state: ONLINE (DESTROYED)
action: The pool can be imported using its name or numeric identifier.
config:
zzz ONLINE
c3t0d0 ONLINE
# zpool import -Df 7148440739272373876
cannot import 'zzz': one or more devices is currently unavailable
1.7 zpool的版本升级
如果将低版本操作系统下建立的zpool迁移到了高版本,则需要对zpool进行升级
使用zpool upgrade –v子命令来查看ZFS版本,使用zpool upgrade –a子命令来升级之前版本创建的zpool。
# zpool upgrade -a
This system is currently running ZFS version 4.
All pools are formatted using this version.
# zpool upgrade -v
This system is currently running ZFS version 4.
The following versions are supported:
VER DESCRIPTION
--- --------------------------------------------------------
1 Initial ZFS version
2 Ditto blocks (replicated metadata)
3 Hot spares and double parity RAID-Z
4 zpool history
For more information on a particular version, including supported releases, see:
Where 'N' is the version number.
Note:如果将池升级到最新版本,则在运行较早ZFS 版本的系统中将无法访问这些池。
迁移ZFS 存储池
阅读(2532) | 评论(0) | 转发(0) |