喊佛 发表于 2010-04-27 16:19

ZFS基本命令

看论坛里好像没有ZFS的资料,其实ZFS还是很强大的。

自己从文档总结了一下,没那么啰嗦。有不对的请指教。

以下均在虚拟机中测试。共6块硬盘:
       0. c0d0 <DEFAULT cyl 2085 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0wr
       1. c0d1 <DEFAULT cyl 2085 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@7,1/ide@0/cmdk@1,0
       2. c1d1 <VMware V-0000000000000000-0001-2.00GB>
          /pci@0,0/pci-ide@7,1/ide@1/cmdk@1,0
       3. c2t0d0 <VMware,-VMware Virtual S-1.0-2.00GB>
          /pci@0,0/pci15ad,1976@10/sd@0,0
       4. c2t1d0 <VMware,-VMware Virtual S-1.0-2.00GB>
          /pci@0,0/pci15ad,1976@10/sd@1,0
       5. c2t2d0 <VMware,-VMware Virtual S-1.0-2.00GB>
          /pci@0,0/pci15ad,1976@10/sd@2,0
c0d0和c0d1大小为16G,其他盘大小为2G。

ZFS GUI

First, S10u6 has a different security setting when the server communicates to the outside world.
Run this:
# svccfg -s svc:/system/webconsole setprop options/tcp_listen=true; smcwebserver restart

root@newly # svcs -a|grep web
disabled       10:27:07 svc:/application/management/webmin:default
online         10:28:26 svc:/system/webconsole:console
root@newly # svccfg -s svc:/system/webconsole setprop options/tcp_listen=true; smcwebserver restart
Restarting Sun Java(TM) Web Console Version 3.1 ...
The console is running
root@newly #
Now log on to the console: https://<server_name>:6789
If you do not see the ZFS Administration GUI showing there, do this:
# wcadmin deploy -a zfs -x zfs /usr/share/webconsole/webapps/zfs ; smcwebserver restart
Now you should be able to see the GUI. Install this patch if you see a JVM crash. This will happen if you have at least one zpool configured in the system. Thus, it also happens to servers that use ZFS as their root file system.
For S10 - SPARC,
#141104-01: SunOS 5.10: ZFS Administration Java Web Console Patch
For S10 - x86,
#141105-01: SunOS 5.10_x86: ZFS Administration Java Web Console Patch
Run "patchadd" to install the patch. Make sure you restart the web console by running "smcwebserver restart".





ZFS CLI
查看ZFS存储池状态
root@newly # zpool list
NAME    SIZE   USEDAVAIL    CAPHEALTHALTROOT
rpool15.9G6.04G9.84G    38%ONLINE-
root@newly # zpool status
pool: rpool
state: ONLINE
scrub: none requested
config:

      NAME      STATE   READ WRITE CKSUM
      rpool       ONLINE       0   0   0
          c0d0s0    ONLINE       0   0   0

errors: No known data errors
查看ZFS文件系统状态
root@newly # zfs list
NAME                        USEDAVAILREFERMOUNTPOINT
rpool                      6.95G8.67G    34K/rpool
rpool/ROOT               4.95G8.67G    21Klegacy
rpool/ROOT/s10x_u8wos_08a4.95G8.67G4.95G/
rpool/dump               1.00G8.67G1.00G-
rpool/export               44K8.67G    23K/export
rpool/export/home            21K8.67G    21K/export/home
rpool/swap                  1G9.59G85.0M-
根池做镜像
root@newly # zpool attach rpool c0d0s0 c0d1s0
cannot attach c0d1s0 to c0d0s0: EFI labeled devices are not supported on root pools.
由于根池不支持EFI标签磁盘需要格式化磁盘并改为SMI标签磁盘
root@newly # format –e
format> l
SMI Label
EFI Label
Specify Label type: 0
Warning: This disk has an EFI label. Changing to SMI label will erase all
current partitions.
Continue? y
You must use fdisk to delete the current EFI partition and create a new
Solaris partition before you can convert the label.
format> fdisk使用fdisk删除EFI分区并重新label为SMI label
root@newly # prtvtoc /dev/rdsk/c0d0s2 | fmthard -s - /dev/rdsk/c0d1s2
fmthard:New volume table of contents now in place.
root@newly # zpool attach rpool c0d0s0 c0d1s0
Please be sure to invoke installgrub(1M) to make 'c0d1s0' bootable.
安装引导信息
SPARC:
# installboot -F zfs /usr/platform/‘uname -i‘/lib/fs/zfs/bootblk /dev/rdsk/c0t1d0s0
X86:
root@newly # installgrub /boot/grub/stage1 /boot/grub/stage2 /dev/rdsk/c0d1s0
stage1 written to partition 0 sector 0 (abs 16065)
stage2 written to partition 0, 272 sectors starting at 50 (abs 16115)

root@newly # zpool status

pool: rpool
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 for 0h3m, 17.10% done, 0h18m to go
config:

      NAME      STATE   READ WRITE CKSUM
      rpool       ONLINE       0   0   0
          mirror    ONLINE       0   0   0
            c0d0s0ONLINE       0   0   0
            c0d1s0ONLINE       0   0   01.03G resilvered

errors: No known data errors
查看状态可发现数据正在同步,1.03G为已同步的数据量
拆除镜像
root@newly # zpool detach rpool c0d1s0
root@newly # zpool status
pool: rpool
state: ONLINE
scrub: none requested
config:

      NAME      STATE   READ WRITE CKSUM
      rpool       ONLINE       0   0   0
          c0d0s0    ONLINE       0   0   0

errors: No known data errors
为存储池创建高速缓存设备
对于根池同样需要设置为SMI标签磁盘
root@newly # zpool add rpool cache c1d1s0
root@newly # zpool status
pool: rpool
state: ONLINE
scrub: resilver completed after 0h20m with 0 errors on Wed Jan 27 11:15:00 2010
config:

      NAME      STATE   READ WRITE CKSUM
      rpool       ONLINE       0   0   0
          mirror    ONLINE       0   0   0
            c0d0s0ONLINE       0   0   0
            c0d1s0ONLINE       0   0   06.04G resilvered
      cache
          c1d1s0    ONLINE       0   0   0

errors: No known data errors
可通过zpool iostat 查看池io情况
root@newly # zpool iostat -v rpool
               capacity   operations    bandwidth
pool         usedavail   readwrite   readwrite
----------------------------------------
rpool       6.06G9.81G   17      3   447K10.9K
mirror    6.06G9.81G   20      3   506K12.3K
    c0d0s0      -      -   13      0   511K9.88K
    c0d1s0      -      -      0   191.91K   514K
cache         -      -      -      -      -      -
c1d1s0    66.9M1.91G      0   112.41K1.19M
----------------------------------------
为存储池创建单独的日志设备
root@newly # zpool add tpool log c2t2d0
创建RAIDZ存储池
单奇偶校验RAID-Z 与RAID-5 类似。双奇偶校验RAID-Z 与RAID-6 类似。
如果要创建包含许多磁盘的RAID-Z 配置,则最好将包含14 个磁盘的RAID-Z 配置拆分为两个包含7 个磁盘的分组。若RAID-Z 配置包含的分组中的磁盘数目为一位数(1-9),则该配置的性能应该更好。
root@newly # zpool create testpool raidz c2t0d0 c2t1d0 c2t2d0
创建双奇偶校验
root@newly # zpool create testpool raidz2 c2t0d0 c2t1d0 c2t2d0
root@newly # zpool status testpool
pool: testpool
state: ONLINE
scrub: none requested
config:

      NAME      STATE   READ WRITE CKSUM
      testpool    ONLINE       0   0   0
          raidz1    ONLINE       0   0   0
            c2t0d0ONLINE       0   0   0
            c2t1d0ONLINE       0   0   0
            c2t2d0ONLINE       0   0   0

errors: No known data errors
更换RAIDZ或镜像中的设备
root@newly # zpool replace testpool c2t2d0 c1d1
root@newly # zpool status testpool
pool: testpool
state: ONLINE
scrub: resilver completed after 0h0m with 0 errors on Wed Jan 27 11:15:10 2010
config:

      NAME      STATE   READ WRITE CKSUM
      testpool    ONLINE       0   0   0
          raidz1    ONLINE       0   0   0
            c2t0d0ONLINE       0   0   0
            c2t1d0ONLINE       0   0   0
            c1d1    ONLINE       0   0   039K resilvered

errors: No known data errors
查看及修改ZPOOL & ZFS属性
查看存储池属性
#zpool get all rpool
#zpool set failmode=coninue rpool
查看ZFS属性
#zfs get all rpool
#zpool set compression=on rpool
ZFS快照
root@newly # zfs snapshot rpool@today
root@newly # zfs list
NAME                        USEDAVAILREFERMOUNTPOINT
rpool                      6.98G8.65G    36K/rpool
rpool@today                  0      -    36K-
rpool/ROOT               4.98G8.65G    21Klegacy
rpool/ROOT/s10x_u8wos_08a4.98G8.65G4.98G/
rpool/dump               1.00G8.65G1.00G-
rpool/export               56K8.65G    23K/export
rpool/export/home            33K8.65G    33K/export/home
rpool/swap                  1G9.56G85.0M-
tpool                        81K1.95G    21K/tpool
ZFS快照储存在目录下的.zfs文件夹中

ZFS快照回滚
root@newly # zfs rollback rpool@today
ZFS快照备份
备份到本地文件系统
#zfs send pool1@snap1 | zfs recv pool2/rs01
#zfs send pool1@snap1 | gzip > backupfile.gz
备份到远程文件系统
#zfs send pool1@snap1 | ssh host2 zfs recv pool2/rs01
发送增量备份
#zfs send –I pool1@snap1 pool1@snap2 | ssh host2 zfs recv pool2/rs02
其中snap1为较早的快照,snap2为较晚的快照
ZFS快照恢复
#zfs recv [-F] pool1 < /backupfile.gz

doging 发表于 2010-04-27 16:21

沙发

waily 发表于 2010-04-27 16:22

谢谢共享

zhmzhouming 发表于 2010-04-27 16:25

学习并收藏了

yuhuohu 发表于 2010-04-27 16:26

收藏之

喊佛 发表于 2010-04-27 16:27

果然混到精华了 我很欣慰 :lol:

yuhuohu 发表于 2010-04-27 16:32

果然混到精华了 我很欣慰
喊佛 发表于 2010-04-27 16:27 http://bbs2.chinaunix.net/images/common/back.gif


    哈 欢迎哥们继续分享更多好东西

oasvr 发表于 2010-04-28 12:56

定期得做做scrub。

夏天的绿树叶 发表于 2010-04-28 22:16

大家都对这比较感兴趣吧

喊佛 发表于 2010-04-28 22:33

回复 8# oasvr


    能同步同步数据,清清碎片?
页: [1] 2 3
查看完整版本: ZFS基本命令