免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2241 | 回复: 0
打印 上一主题 下一主题

ZFS文件系统的学习 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-03-27 16:17 |只看该作者 |倒序浏览
ZFS文件系统

  ZFS文件系统的英文名称为Zettabyte File System,也叫动态文件系统(Dynamic File System),是第一个128位文件系统。
  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设备能够有更好的表现。
  Components of a ZFS Storage Pool
  组成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.
  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的时候,磁盘完全可以用物理设备名就可以,不需要指出全路径。
  这句话不大明白:However, the disks must be preformatted to have an appropriately sized slice zero.
  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
  下边这句话没怎么看懂:
  You cannot take a pool offline to the point
where it becomes faulted. For example, you cannot take offline two
devices out of a RAID-Z configuration, nor can you take offline a
top-level virtual device.
  # 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”查看健康状态
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/21041/showart_1882073.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP