ZFS-学习笔记.docx
ZFS学习笔记第一章zpool的管理21.1 创建ZPoOI31.1.1 创建单边ZpOol31.1.2 创建mirrorpool41.1.3 创建raidzzpool61.2 删除ZPoOI71.3 对ZpOol进行管理81.3.1 镜像和拆镜像81.3.2 添加ZPoOl空间91.3.3 spare盘的添加和删除101.4 zpool的维护/故障盘的更换121.5 ZPOol的迁移151.6 恢复销毁的ZPoOI161.7 ZPOol的Do统计181.8 迁移ZFS存储池191.9 ZPOol的版本升级20第二章ZFS文件系统的建立和设置222.1 ZFS文件系统的创建和删除222.1.1 ZFS文件系统的创建222.1.2 ZFS文件系统重命名232.1.3 删除ZFS文件系统232.2 ZFS属性介绍242.3 查询ZFS文件系统信息252.4 管理ZFS属性252.4.1 设置Set262.4.2 继承inherit272.4.3 查询get272.4.4 ZFS文件系统的mount和UmoUnl342.4.5 ZFS文件系统的share和unshare362.4.6 ZFS文件系统的配额和预留空间37第三章使用ZFS进行快照或者克隆403.1 快照snapshot403.1.1 创建和销毁快照403.1.2 快照的显示和重命名413.1.3 使用快照同滚413.2 克隆433.2.1 创建CIOne433.2.2 删除clone443.2.3 使用clone来代替文件系统443.3 快照的保存和恢复453.3.1 快照的保存453.3.2 使用快照文件恢复文件系统46附录:ZFS卷48ZFS主要使用两条命令及其子命令:zfszpool第一章zpool的管理zpool命令菜单:#zpoolmissingcommandusage:zpoolcommandargs.where'command*isoneofthefollowing:create-fn-Rroot-mmountpoint<pool><vdev>.destroy-f<pool>add-fn<pool><vdev>.remove<pool><device>list-H-ofield,field*pool.iostat-vpool.intervalcountstatus-vxpool.online<pool><device>.offline-t<pool><device>.clear<pool>deviceattach-f1<pool><device><new_device>detach<pool><device>replace-f<pool><device>new_devicescrub-s<pool>.import-ddir-Dimport-ddir-D-f-oopts-Rroot-aimport-ddir-D-f-oopts-Rroot<poolid>newpoolexport-f<pool>.upgradeupgrade-vupgrade<-apool>history<pool>1.1 创建zpoolZFS文件系统是建立在存储池pool的基础上,所以要建立文件系统必须先建立底层的plo1.1.1 创建单边zpoolzpoolcreateyzc3tdc3td1#zpoolcreateFirstc3t2dc3t4dinvalidvdevspecificationuse'-ftooverridethefollowingerrors:devdskc3t2ds2containsaufsfilesystem.devdskc3t2ds7containsaufsfilesystem.加入pool的硬盘可以是整块盘,也可以是某个分区,条件允许的时候建议使用整块盘,这样便于pool对硬盘的管理。由于加入pool的磁盘之前曾经使用过ufs,所以在创建过程中需要使用-f选项来忽视ufs文件格式将硬盘强制加入pool中。Notes加入pool的硬盘的原来数据会被破坏。# zpoolcreate-ffirstc3t2dc3t3d# zpoollistNAMEALTROOT创建两块盘组成的plSIZEUSEDAVAILCAPHEALTHfirst136G90K136G0%ONLINE-#zpoolstatuspool:firststate:ONLINEscrub:nonerequestedconfig:NAMESTATEfirstONLINEc3t2dONLINEc3t3dONLINEREADWRITECKSUMOOO000000errors:Noknowndataerrors1.1.2 创建mirrorpool#zpoolcreate-fyzmirrorc3tdc3tld#zpoollistNAMESIZEUSEDAVAILALTROOTfirst136G90K136G0%ONLINEyz68G6.08G61.9G8%ONLINE#zpoolstatuspool:yzstate:ONLINEscrub:nonerequestedconfig:CAPHEALTHNAMESTATEREADWRITECKSUMyzONLINEOOOmirrorONLINEOOOc3tdONLINEOOOc3tldONLINEOOOerrors:Noknowndataerrors创建镜像盘组成的pool,如果加入的硬盘为多个的话,则默认的raid类型为raidl+O,下例中,镜像为3份,单盘为68G,而PoOl总量为136G。RCGSM-root-yztest2>zpoolcreatexxxmirrorc3tdc3tldc3t2dmirrorc3t3dc3t4dc3t5dRCGSM-root-yztest2>zpoollistSIZE USED AVAIL CAP HEALTH90K136G0% ONLINENAMEALTROOTxxx136GRCGSM-root-yztest2>zpoolstatuspool:xxxstate:ONLINEscrub:nonerequestedconfig:NAMESTATEREADWRITECKSUMXXXONLINEOOOmirrorONLINEOOOc3tdONLINEOOOc3tldONLINEOOOc3t2dONLINEOOOmirrorONLINEOOOc3t3dONLINEOOOc3t4dONLINEOOOc3t5dONLINEOOOerrors:Noknowndataerrors#zpoolstatus-xallpoolsarehealthy#df-hFilesystemsizeusedavailcapacityMountedonfirstI34G24K134G1%/first1.1.3 创建raidzzpoolzpool支持的raidz有raidz1和raidz2两种,类似于传统的raid5,raidz至少需要3个devices来实现对数据的校验。raidz也就是raidzl会消耗一块盘的空间,raidz2消耗凉快盘的空间。# zpoolcreateyzraidz1c3tdc3tldc3t2dc3t3d# zpoolstatuspool:yzstate:ONLINEscrub:nonerequestedconfig:NAMESTATEREADWRITECKSUMyzONLINE000raidz1ONLINE000c3tdONLINE000c3tldONLINE000c3t2dONLINE000c3t3dONLINE000errors:Noknowndataerrors#zpoollistNAMESIZEUSEDAVAILCAPHEALTHALTROOTyz272G147K272G0%ONLINE.#df-hFilesystemsizeusedavailcapacityMountedonyz200G36K200G1%yz# zpoolcreateyzraidz2c3tdc3tldc3t2dc3t3d# zpoollistNAMESIZEUSEDAVAILCAPHEALTHALTROOTyz272G226K272G0%ONLINE.#df-hFilesystemyz#zpoollistNAMEsizeused133GavailcapacityMountedon36K133G1%yzSIZEUSEDAVAILCAPHEALTHALTROOTyz272G226K272G0%ONLINE#zpoolstatuspool:yzstate:ONLINEscrub:nonerequestedconfig:NAMESTATEREADWRITECKSUMyzONLINE000raidz2ONLINE000c3tdONLINE000c3tldONLINE000c3t2dONLINE000c3t3dONLINE000errors:NoknowndataerrorsNote:同样是四块盘的raidz,raidz2消耗掉两块盘的空间,raidzl消耗一块盘的空间。raidz2的数据校验性应当是更强的。1.2 删除zpoolzpooldestroypoolname如果zpool正在使用会提示设备正忙,强制删除pool使用-f参数。RCGSM-root-yztest2>zpooldestroyyzcannotunmount'yztest2':Devicebusycouldnotdestroy,yz,:couldnotunmountdatasetsRCGSM-root-yztest2>zpooldestroy-fyz1.3 对zpool进行管理1.3.1 镜像和拆镜像如果创建硬。|时,物理盘为单,可以对其进行镜像,命令格式为zpoolattachxxxc3tOdOoldc3t5dnew例子:# zpoolstatuspool:XXXstate:ONLINEscrub:nonerequestedconfig:READ WRITE CKSUMOOO000NAMEXXXc3tdSTATEONLINEONLINEerrors:Noknowndataerrors# zpoolattachxxxc3t5dmissing<new_device>specificationusage:attach-f<pool><device><new_device># zpoolattachxxxc3tdc3t5d# zpoolstatusxxxpool:xxxstate:ONLINEscrub:resilvercompletedwith0errorsonTueOct717:11:182008config:NAMESTATEREADWRITECKSUMXXXONLINE000mirrorONLINE000c3tdONLINE000c3t5dONLINE000errors:Noknowndataerrors使用zpooldetach的子命令可以对镜像进行拆除例子:# zpooldetachxxxc3t5d# zpoolstatuspool:XXXstate:ONLINEscrub:resilvercompletedwith0errorsonTueOct717:11:182008config:NAMESTATEREADWRITECKSUMXXXONLINE000c3tdONLINE000errors:Noknowndataerrors1.3.2 添加zpool空间使用zpooladd子命令对pool进行扩容,使用.n参数可以模拟出扩容后的效果。例子:# zpoolstatuspool:XXXstate:ONLINEscrub:resilvercompletedwith0errorsonTueOct717:11:182008config:NAMESTATEREADWRITECKSUMXXXONLINE000c3tdONLINE000errors:Noknowndataerrors# zpooladdxxxc3t5d# zpoolstatusxxxpool:xxxstate:ONLINEscrub:resilvercompletedwith0errorsonWedOct808:53:022008config:NAMESTATEREADWRITECKSUMXXXONLINE000c3tdONLINE000c3t5dONLINE000errors:Noknowndataerrors#zpoollistxxxNAMESIZEUSEDAVAILCAPHEALTHAEROOTXXX136G91K136G0%ONLINE.RCGSM-root-mnt>zpoolstatuspool:poolnamestate:ONLINEscrub:resilvercompletedwith0errorsonWedOct813:16:352008config:NAMESTATEREADWRITECKSUMpoolnameONLINE000raidz1ONLINE000c3tdONLINE000c3t3dONLINE000c3t4dONLINE000errors:NoknowndataerrorsRCGSM-root-mnt>zpooladd-npoolnamec3tldinvalidvdevspecificationuse'-ftooverridethefollowingerrors:mismatchedreplicationlevel:poolusesraidzandnewvdevisdiskRCGSM-root-mnt>zpooladd-n-fpoolnamec3tldwouldupdate'poolname'tothefollowingconfiguration:poolnameraidzIc3tdc3t3dc3t4dc3tld1.3.3 spare盘的添加和删除对于raidz和mirror而言,zpool支持spare盘的设置,而且spare盘可以支持多个pool,比如在一个mirror和另一个raidz使用同一块硬盘来做spare。# zpooiaddpoolnamesparec3t5d# zpooiaddxxxsparec3t5d# zpoolstatuspool:poolnamestate:ONLINEscrub:nonerequestedconfig:NAMESTATEREADWRITECKSUMpoolnameONLINE000raidz1ONLINE000c3t2dONLINE000c3t3dONLINEc3t4dONLINEsparesc3t5dAVAILerrors:Noknowndataerrorspool:xxxstate:ONLINEscrub:nonerequestedconfig:NAMESTATEREADWRITECKSUMXXXONLINE000mirrorONLINE000c3tdONLINE000c3tldONLINE000sparesc3t5dAVAILerrors:Noknowndataerrors删除spare盘使用zpoolremove子命令# zpoolremovexxxc3t5d# zpoolremovepoolnatnec3t5d# zpoolstatus-xallpoolsarehealthy# zpoolstatus-vpool:poolnamestate:ONLINEscrub:nonerequestedconfig:NAMESTATEREADWRITECKSUMpoolnameONLINE000raidzlONLINE000c3t2dONLINE000c3t3dONLINE000c3t4dONLINE000errors:Noknowndataerrorspool:xxxstate:ONLINEscrub:nonerequestedconfig:NAMESTATEREADWRITECKSUMXXXONLINEOOOmirrorONLINEOOOc3tdONLINEOOOc3tldONLINEOOOerrors:Noknowndataerror1.4 zpool的维护/故障盘的更换当ZPOoI内的硬盘出现问题需要更换的时候,就要使用ZPOOIr叩IaCe子命令进行更换了。RCGSM-root-mnl>zpoolreplacemissingpoolnameargumentusage:replace-f<pool><device>new_deviceRCGSM-root-mnt>zpoolreplacepoolnamec3t2dc3tdRCGSM-root-mnt>zpoolstatuspool:poolnamestate:ONLINEstatus:Oneormoredevicesiscurrentlybeingresilvered.Thepoolwillcontinuetofunction,possiblyinadegradedstate.action:Waitfortheresilvertocomplete.scrub:resilverinprogress,6.71%done,0h3mtogoconfig:NAMESTATEREADWRITECKSUMpoolnameONLINEOOOraidz1ONLINEOOOreplacingONLINEOOOc3t2dONLINEOOOc3tdONLINEOOOc3t3dONLINEOOOc3t4dONLINEOOOerrors:NoknowndataerrorsRCGSM-root-mnt>zpoolstatuspool:poolnamestate:ONLINEscrub:resilvercompletedwithOerrorsonWedOct813:16:352008config:NAMESTATEREADWRITECKSUMpoolnameONLINE000raidz1ONLINE000c3tdONLINE000c3t3dONLINE000c3t4dONLINE000errors:Noknowndataerrors添加磁盘空间的时候可以对添加的硬盘进行数据保护,如mirror和raidzRCGSM-root-mnt>zpooladd-n-fpoolnameraidz2c3tldc3t2dc3t5dwouldupdate'poolname'tothefollowingconfiguration:poolnameraidz1c3tdc3t3dc3t4draidz2c3tldc3t2dc3t5d例子:raidz出现坏盘的解决在木例中,我把poolname中的c3ld号盘OffIine之后将其拆卸出3310。RCGSM-root-mnt>zpoolofflinepoolnamec3tdBringingdevicec3tdofflineRCGSM-root-mnt>zpoolstatuspool:poolnamestate:DEGRADEDstatus:Oneormoredeviceshasbeentakenofflinebytheadministrator.Sufficientreplicasexistforthepooltocontinuefunctioninginadegradedstate.action:Onlinethedeviceusing,zpoolonline'orreplacethedevicewith,zpoolreplace'.scrub:resilvercompletedwith0errorsonWedOct813:16:352008config:NAMESTATEREADWRITECKSUMpoolnameDEGRADED000raidz1DEGRADED000c3tdOFFLINE000c3t3dONLINE000c3t4dONLINE000errors:Noknowndataerrors这样在执行ZPOoloffIine后,拆除该硬盘,并执行OnIine操作,这时会发现POOl中的硬盘状态为FAUurED。这时候由于raidz的校验功能,可以通过replace对硬盘进行更换并恢复数据到新盘上。RCGSM-root-mnt>zpoolstatuspool:poolnamestate:DEGRADEDstatus:Oneormoredevicescouldnotbeusedbecausethelabelismissingorinvalid.Sufficientreplicasexistforthepooltocontinuefunctioninginadegradedstate.action:Replacethedeviceusing'zpoolreplace'.see:scrub:resilvercompletedwith0errorsonWedOct814:03:472008config:NAMESTATEREADWRITECKSUMpoolnameDEGRADED000raidzIDEGRADED000c3tdFAULTED000corrupteddatac3t3dONLINE000c3t4dONLINE000errors:NoknowndataerrorsRCGSM-root-mnt>zpoolreplacepoolnamec3tdc3t2dRCGSM-root-mnt>zpoolstatuspool:poolnamestate:DEGRADEDstatus:Oneormoredevicesiscurrentlybeingresilvered.Thepoolwillcontinuetofunction,possiblyinadegradedstate.action:Waitfortheresilvertocomplete.scrub:resilverinprogress,2.97%done,0h3mtogoconfig:NAMESTATEREADWRITECKSUMpoolnameDEGRADED000raidzIDEGRADED000replacingDEGRADED000c3tdFAULTED000corrupteddatac3t2dONLINE000c3t3dONLINE000c3t4dONLINE000errors:Noknowndataerrors# zpoolstatuspool:poolnamestate:ONLINEscrub:resilvercompletedwith0errorsonWedOct814:10:022008config:NAMESTATEREADWRITECKSUMpoolnameONLINE000raidz1ONLINE000c3t2dONLINE000c3t3dONLINE000c3t4dONLINE000如果是在原来的槽位上更换过硬盘以后再同步,直接输入:zpoolreplacepoolnamec3td# zpoolreplacepoolnamec3t2d# zpoolstatuspool:poolnamestate:DEGRADEDstatus:Oneormoredevicesiscurrentlybeingresilvered.Thepoolwillcontinuetofunction,possiblyinadegradedstate.action:Waitfortheresilvertocomplete.scrub:resilverinprogress,3.75%done,0h2mtogoconfig:NAMESTATEREADWRITECKSUMpoolnameDEGRADED000raidz1DEGRADED000replacingDEGRADED000c3t2dOsOoUNAVAIL000cannotopenc3t2dONLINE000c3t3dONLINE000c3t4dONLINE000errors:Noknowndataerrors1.5 zpool的迁移迁移zpool的时候需要确认zpool中所有的文件系统没有被使用,如果需要不顾一切的去迁移,可以加上f参数。# zpoolexportpoolname# zpoolstatusnopoolsavailable# zpoolimportpool:poolnameid:10727618928512001646state:ONLINEaction:Thepoolcanbeimportedusingitsnameornumericidentifier,config:poolnameONLINEraidzlONLINEc3t2dONLINEc3t3dONLINEc3t4dONLINE# zpoolstatusnopoolsavailable# zpoolimport10727618928512001646使用pool的id和name都可以# zpoolstatuspool:poolnamestate:ONLINEscrub:nonerequestedconfig:NAMESTATEpoolnameONLINEraidzlONLINEc3t2dONLINEc3t3clONLINEc3t4dONLINEREADWRITECKSUM0000000000000001.6 恢复销毁的zpoolzpool被destroy后,可以通过zpoolimport-D命令来查看上一个被销毁的zpool是否可以被恢复。RCGSM-root-zzz>cp-r/optzzzCRCGSM-root-zzz>IsoptRCGSM-root-zzz>du-sh.3.6GRCGSM-root-zzz>Cd# zpooldestroyZZZ# zpoolimport-Dpool:zzzid:7148440739272373876state:ONLINE(DESTROYED)action:Thepoolcanbeimportedusingitsnameornumericidentifier,config:ZZZONLINEc3tdONLINEc3tldONLINE# zpoolimport-Dfzzz#zpoolstatuspool:zzzstate:ONLINEscrub:nonerequestedconfig:NAMESTATEREADWRITECKSUMZZZONLINE000c3tdONLINE000c3tldONLINE000errors:Noknowndataerrors# cdzzzRCGSM-root-zzz>IsoptRCGSM-root-zzz>dush.3.6G.如果通过import-D看到的pool的状态不是online的话,那么这个pool就不可恢复了。RCGSM-root-zzz>Cd# zpooldestroyzzz# zpoolcreatezzzc3ld# zpoolimport-Dpool:zzzid:7148440739272373876state:FAULTED(DESTROYED)status:Oneormoredevicesaremissingfromthesystem.action:Thepoolcannotbeimported.Attachthemissingdevicesandtryagain.see:zzzUNAVAILmissingdevicec3tldONLINEAdditionaldevicesareknowntobepartofthispool,thoughtheirexactconfigurationcannotbedetermined.# zpooldestroyzzz# zpoolimport-Dpool:zzzid:7148440739272373876state:FAULTED(DESTROYED)status:Oneormoredevicesaremissingfromthesystem.action:Thepoolcannotbeimported.Attachthemissingdevicesandtryagain.see:config:zzzUNAVAILmissingdevicec3tldONLINEAdditionaldevicesareknowntobepartofthispool,thoughtheirexactconfigurationcannotbedetermined.pool:zzzid:6600816109531139366state:ONLINE(DESTROYED)action:Thepoolcanbeimportedusingitsnameornumericidentifier,config:zzzONLINEc3tdONLINE# zpoolimport-Df7148440739272373876cannotimport'zzz,:oneormoredevicesiscurrentlyunavailable1.7 zpool的I/O统计使用zpooliostat命令来查询zpool的I/O运行状况#zpooliostatcapacityoperationsbandwidthpoolusedavailreadwritereadwritepoolname64.7G139G0134