2009年12月7日星期一

sun ZFS學習筆記

Sun 提供了一個ZFS的免費教程,感覺不錯,講部分內容和自己的實驗記錄下來,備查!

參考:
https://learning.sun.com/solc/files/solc/tblo_selfcontained/1179270410/module1/default.htm

What is ZFS?

ZFS is a revolutionary new file system that fundamentally changes the way file systems are administered, with features and benefits not found in any other file system available today. ZFS has been designed to be robust, scalable, and simple to administer.

Instead of using a storage volume model and its associated limitations, ZFS aggregates storage devices into 'pools.' The storage pool describes the physical characteristics of the system's storage (device layout, data redundancy, and so on) and acts as an general data store from which file systems can be created.

The Benefits of ZFS

ZFS's pooling model has a lot of useful benefits. For example, using pools means that you no longer need to predetermine the size of a file system, as file systems grow automatically within the space allocated to the storage pool.

More Benefits of ZFS

ZFS is also designed to scale easily and can handle extremely large quantities of data. It does this by using 128-bit data addressing and dynamically scaling its metadata.

In addition, ZFS ensures that its data is always consistent on disk. Because ZFS uses checksums with each block of data, it can detect data corruption caused by any element of the storage subsystem, not just disk errors. That means you can use inexpensive disks to provide similar reliability to high-priced storage systems.

Even More Benefits of ZFS

Finally, ZFS provides a greatly simplified administration model. ZFS makes it easy to create and manage file systems without needing multiple commands or editing configuration files.

For example, with ZFS you can easily:

  • Set quotas or reservations
  • Turn compression on or off
  • Manage mount points for numerous file systems with a single command, and
  • Examine or repair devices without having to understand a separate set of volume manager commands

Now you understand why ZFS is such a popular file system!

the two basic elements of a ZFS file system are:

. Pools and datasets

which kind of storage model does ZFS use?

Pooled storage

summary

In summary , ZFS is an amazing new file system technology that is fast, scalable, and filled with useful features.

Understanding ZFS Basics

Now that you have a general understanding ZFS , let's dive into the details. In this topic we'll cover the basic components of the ZFS file systems, such as pools and datasets. Like always, if you think that you already have a good understanding of these basic concepts, you're welcome to jump to Lesson 2.

If you're ready to proceed, click the Next button.

Pools and Datasets

Conceptually, ZFS is pretty simple. There are two basic elements: Pools and datasets.

Pools consist of storage devices that provide space for datasets. Each pool is comprised of one or more virtual devices. A virtual device is an internal representation of the storage pool that describes the layout of physical storage and its fault characteristics. In a system with multiple devices, often these storage devices are grouped in pairs.

Datasets are groups of information that reside in storage space allocated from the pools.

Think of it this way:

  • A pool is like a convention center where a tradeshow is taking place.

  • The storage devices are like convention center rooms that can be opened up to fit the number of people in attendance.

  • The datasets are attendees from different professional backgrounds. For example, one dataset is made up of the marketing people, another of engineers, etc. These attendees (or datasets) can sit whereever they want in the room until it is full. Then another room can be opened up to accommodate more attendees. When the tradeshow is over, the attendees leave the convention center leaving room for others to use the space.

Pools and Datasets (cont)

Now let's take a closer look at datasets. A “dataset” is a generic name for the following ZFS entities: file systems, volumes, snapshots, or clones.

  • A file system dataset is just a directory hierarchy for organizing and storing files.

  • A volume is a dataset that is used to emulate a physical device. For example, ZFS swap and dump volumes are created automatically when the OpenSolaris release is installed.

  • A snapshot is a read-only image of a file system or volume at a given point in time.

  • A clone is a file system whose initial contents are identical to the contents of a snapshot.

Examining Pools and Datasets

In ZFS, you can examine pools and datasets with the corresponding administration commands:

  • “zpool” for pools, and
  • “zfs” for datasets

Using the ZPOOL Command

First, use the “zpool status tank” command to see the available pools.

This system has just one pool called “tank.”

Take a moment to review the “config” section. This section displays the devices that make up the pool. This is a simple pool that contains a single storage device called “c1t0d0.”

---------- sample---

root@opensolaris:~# zpool status
  pool: mypool
state: ONLINE
scrub: none requested
config:
        NAME        STATE     READ WRITE CKSUM
        mypool      ONLINE       0     0     0
          c9d0      ONLINE       0     0     0
errors: No known data errors
  pool: rpool
state: ONLINE
scrub: none requested
config:
        NAME        STATE     READ WRITE CKSUM
        rpool       ONLINE       0     0     0
          c7d0s0    ONLINE       0     0     0
errors: No known data errors
root@opensolaris:~#
root@opensolaris:~# format
Searching for disks...done
AVAILABLE DISK SELECTIONS:
       0. c7d0 <DEFAULT cyl 30390 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@1f,2/ide@0/cmdk@0,0
1. c8d1 <drive type unknown>
          /pci@0,0/pci-ide@1f,2/ide@1/cmdk@1,0
       2. c9d0 <WDC WD80-  WD-WMAM9SH8120-0001-74.50GB>
          /pci@0,0/pci-ide@1f,5/ide@0/cmdk@0,0
3. c10d0 <drive type unknown>
          /pci@0,0/pci-ide@1f,5/ide@1/cmdk@0,0
Specify disk (enter its number): ^D

创建tank pool
root@opensolaris:~# zpool create tank c8d1
root@opensolaris:~#
root@opensolaris:~# zpool list tank
NAME   SIZE   USED  AVAIL    CAP  HEALTH  ALTROOT
tank   696G   106K   696G     0%  ONLINE  -
root@opensolaris:~#

-----------------

Using the ZFS Command

Now let's use the 'zfs list -r tank' command to review the datasets on the root pool, or “rpool.”

First, let's look at the column names in the output display.

The “NAME” column lists the name of the file system.

The “USED” and ”AVAIL” columns display the amount of space has been used used and the amount of space that is still available respectivey.

The REFER column displays the amount of data accessible within the specific file system, and the amount of data that is accessible by this dataset, which may or may not be shared with other datasets in the pool. When a snapshot or clone is created, it initially references the same amount of space as the file system or snapshot it was created from, since its contents are identical.

The “MOUNTPOINT” column identifies the directory where the file system resides.

The zfs  command is used to examine:

.datasets

Summary

ZFS is a new file system technology. It uses pools and datasets. Pools include virtual devices and storage devices. Datasets include file systems, volumes, snapshots, and clones. These components can be explored with the zpool and zfs commands.

Ready to move on? Click the exit button to return to the lesson menu and continue to the next lesson.

https://learning.sun.com/solc/files/solc/tblo_selfcontained/1179270410/module2/default.htm

Introduction

Now that you understand the basics of ZFS, let's discuss how to create a ZFS pool. In this lesson, you'll learn how to create a ZFS pool and why its important to use mirrored pools.

Creating a ZFS Pool

ZFS administration has been designed with simplicity in mind. Among the goals of the ZFS design is to reduce the number of commands needed to create a usable file system. When you create a new pool, a new ZFS file system is created and mounted automatically. Let me show you how its done.

Let's start by creating a simple single-device pool named "tank."

Use the "zpool create" command to create the pool by first identifying the pool name “tank” and then the device, c1t0d0 as follows:

Now use the "zpool status tank" command to see the results.

You now have a single-disk storage pool named tank, with a single storage device called c1t0d0.

Although it is possible to create a single-disk pool, a mirrored pool provides data redundancy and better protection again disk failures. We'll cover how to create a mirrored pool in the next section.

To learn more about mirrors, see Lesson 3: Mirrors.

zfs create
zfs destroy
zfs rollback
zfs rename
zfs list
zfs mount
zfs clone
zfs promote

--- sample -----
zpool create tank cit0d0
zpool status tank
root@opensolaris:~# zpool status tank
  pool: tank
state: ONLINE
scrub: none requested
config:
        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          c8d1      ONLINE       0     0     0
errors: No known data errors
root@opensolaris:~#
---

Converting a Single-Device Storage Pool to a Mirrored Storage Pool

Mirrored storage pools are recommended over single-disk pools because mirrored pools can more effectively protect your data. After creating a single-disk pool, its is easy to convert it into a mirrored pool. Let's see how its done.

First, we'll use the “zpool status tank” command to see how the pool is configured.

The output shows us that currently there is only one device in the pool.

To convert this single device pool to a mirror, use the “zpool attach” command followed by the pool name, the existing device name, and the new device name.

Now, rerun the “zpool status tank” command to see if you were successful.

In the output, notice that the status listing includes the “scrub” status. When a new device is attached to a mirror, ZFS automatically duplicates all of the existing pool data onto the mirror device. This is called a “resilver.”

----
zpool attach tank c1t0d0 c1t1d0   做一个mirror
zpool status tank
Although its possible to create a single-disk pool, using mirrored pools is : true!
to convert a single-disk pool to a mirrored pool, you add a storage with which of the following commands?
attach

Summary

Creating ZFS pools is fast and simple. Just use the zpool create command and the device name and ZFS does the rest. However, make sure to follow up to convert the single-disk pool to a mirrored pool. More on this topic, see Lesson 3: Mirrors .

Summary

Creating ZFS pools is fast and simple. Just use the zpool create command and the device name and ZFS does the rest. However, make sure to follow up to convert the single-disk pool to a mirrored pool. More on this topic, see Lesson 3: Mirrors .

In a previous lesson, we created a single-device pool called 'tank.' Let's take another look at this pool. Use the “zpool status tank” command to review the pool configuration.

If you need to add more storage to this pool, start with the “zpool attach” command followed by the pool name, an existing device in the pool, and the new device that you want to attach.

Now use the zpool status tank command to see the results.

Review the OpenSolaris output on this page. Notice that both devices are now listed in the pool configuration. Also notice that both devices are now part of a “mirror” as identified in the “config” section. A mirror is a virtual device that stores identical copies of data on two or more disks. See Lesson 3: Mirrors for more information.

--

zpool status tank

zpool attach tank c1t0d0 c1t1d0

root@opensolaris:~# format
Searching for disks...done
AVAILABLE DISK SELECTIONS:
       0. c7d0 <DEFAULT cyl 30390 alt 2 hd 255 sec 63>
          /pci@0,0/pci-ide@1f,2/ide@0/cmdk@0,0
       1. c8d1 <ST375033-         9QK1MYJ-0001-698.63GB>
          /pci@0,0/pci-ide@1f,2/ide@1/cmdk@1,0
       2. c9d0 <WDC WD80-  WD-WMAM9SH8120-0001-74.50GB>
          /pci@0,0/pci-ide@1f,5/ide@0/cmdk@0,0
       3. c10d0 <drive type unknown>
          /pci@0,0/pci-ide@1f,5/ide@1/cmdk@0,0
Specify disk (enter its number): ^D
root@opensolaris:~# zpool status tank
  pool: tank
state: ONLINE
scrub: none requested
config:
        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          c8d1      ONLINE       0     0     0
errors: No known data errors
root@opensolaris:~# zpool attach tank c8d1 c10d0
root@opensolaris:~# zpool status tank
  pool: tank
state: ONLINE
scrub: resilver completed after 0h0m with 0 errors on Mon Dec  7 16:09:21 2009
config:
        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          mirror    ONLINE       0     0     0
            c8d1    ONLINE       0     0     0
            c10d0   ONLINE       0     0     0  73K resilvered
errors: No known data errors
root@opensolaris:~#

---

to add a device to the storage pool, you use the following ZFS command:

attach

Summary

Adding storage to a ZFS pool is easy. Simply use the “zpool attach” command combined with the pool and device names and ZFS does the rest. Simple, isn't it? Let's move on to the next topic.

Introduction

When administering a system, its often necessary to adjust and reconfigure your setup. Often this includes destroying storage pools.

Destroying a ZFS Pool

Sometimes you make a mistake or need to reconfigure your system. To destroy a pool that is no longer needed, simply use the “zpool destroy” command. Let me show you how its done.

First, use the “zpool status tank” command to review the pools on your system.

Review the image of the OpenSolaris output on this page. It looks like we have one pool named “tank” with two devices. Next, use the “zpool destroy” command plus the name of the pool you want to destroy.

Finally, use the “zpool status tank” command to see the results.

Review the image of the OpenSolaris output once again. Notice that the pool called 'tank' has been removed from the system.

---zpool status tank
zpool destroy tank
zpool status tank
----sample---


root@opensolaris:~# zpool destroy tank
root@opensolaris:~# zpool status tank
cannot open 'tank': no such pool
root@opensolaris:~#
---------------------

ZFS provides a safety feature that allows you to recover a destroyed pool if the devices haven't been reused.

For example, suppose we accidentally destroyed the tank pool. We would simply use the “zpool import -D command” followed by the pool name to reimport the pool.

Then you would use the “zpool list” command to see the results.

Notice that the tank pool has been successfully restored.

---------
zpool import -D tank
zpool status tank
-------------sample ----------------
root@opensolaris:~# zpool import -D tank
root@opensolaris:~# zpool status tank
  pool: tank
state: ONLINE
scrub: none requested
config:
        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          mirror    ONLINE       0     0     0
            c8d1    ONLINE       0     0     0
            c10d0   ONLINE       0     0     0
errors: No known data errors
root@opensolaris:~#
-------------------------------------
the correct ZFS command to eliminate a pool is:
destroy

Summary

Now you know how to a create a ZFS pool, add storage, and destroy a pool if necessary. You even know how to get it back if you delete it on accident.

https://learning.sun.com/solc/files/solc/tblo_selfcontained/1179270410/module3/default.htm

Traditionally, storage management products use a convention called a “mirror.” A mirror is a virtual device that stores identical copies of data on two or more disks. If any disk in a mirror fails, any other disk in that mirror can provide the same data .

The topics in this lesson will teach you all about using a mirrored ZFS configuration to protect your data. However, you should already know the basic definition of a pool and how to create one. If you've skipped those lessons or are still unsure about them, go back and review.

If you're ready, click Next to continue.

What Is A Mirror?

A “mirror” is a kind of storage pool that keeps identical copies of data on two or more disks.

This redundancy provides basic storage protection because if one device fails, the data is still available from the other device (or devices) in the pool.

What are the Benefits of a Mirrored ZFS Configuration?

The benefit of using a mirrored ZFS configuration is that ZFS can attempt to recover the data in the event of a disk failure.

A ZFS storage pool is really just a tree of blocks. ZFS helps to identify data errors by storing the checksum of each block in its parent block pointer, not in the block itself. Every block in the tree contains the checksums for all its children, so the entire pool is self-validating.

When an error occurs, ZFS is able to automatically checks the other device in the mirror, and if it finds good data, it uses the good copy to repair the bad block.

a mirror is : a system that keeps a copy of the data on each one of the mirrorred devices
ZFS checksum feature allows it to:
check for failed blocks of data

Summary

In this topic you have learned that a mirrored ZFS configuration is a storage pool with built in redundancy. You also learned that a mirrored ZFS configuration is recommended because it can recover data in the event of a disk failure.

Introduction

ZFS uses a process called 'mirroring' to improve data security by creating redundancy in the system. This is done by grouping storage devices in pairs and making sure to that the data on each device is mirrored by the other. This arrangment is called a 'mirrored pool.'

In this lesson you'll learn how to set up a mirrored pool.

Creating a Mirrored ZFS Pool

Suppose want to create a mirrored ZFS storage pool. Here's how you do it.

Simply use the “zpool create” command followed by the pool name and device names. We'll create a pool called “tank” with two attached devices called “c1t0d0” and “c1t1do.”

Now use the “zpool status tank” command to see the results.

Notice that you now have a mirrrored pool named tank with two devices.

--------

zpool create tank mirror c1t0d0 c1t1d0

zpool status tank

Converting a Single-Device Pool to a Mirror

Mirrored storage pools are recommended rather than single-disk pools because mirrored pools can more effectively protect your data. After creating a single-disk pool, its is easy to convert it into a mirrored pool. Let's see how its done.

First, we'll use the “zpool status tank” command to see how the pool is configured.

The output shows us that currently there is only one device in the pool.

To convert this single device pool to a mirror, use the “zpool attach” command plus the pool name, the existing device name, and the name of the device you want to attach.

Now, rerun the “zpool status tank” command to see if you were successful.

In the output, notice that the status listing includes the “scrub” status. When a new device is attached to a mirror, ZFS automatically duplicates all of the existing pool data onto the mirror device. This is called a “resilver.”

---

zpool status tank

zpool attach tank c1t0d0 c1t1d0

zpool status tank

-----sample----

root@opensolaris:~# zpool create tank mirror c8d1 c10d0
root@opensolaris:~# zpool status tank
  pool: tank
state: ONLINE
scrub: none requested
config:
        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          mirror    ONLINE       0     0     0
            c8d1    ONLINE       0     0     0
            c10d0   ONLINE       0     0     0
errors: No known data errors
root@opensolaris:~#
--------------------

--

to convert a single-device pool to multiple-device pool you use which of the following:

Summary

Creating ZFS pools is fast and simple. Just use the zpool attach command and the device name to convert your single-device pool to a mirrored-pool.

Introduction

While managing your ZFS mirror, you might want to modify the configuration. This could mean replacing one device with another or taking a device offline.

This topic will teach you how to manage these tasks.

Taking a Device Offline

ZFS allows individual devices to be taken offline or brought online. When hardware is unreliable or not functioning properly, ZFS continues to read or write data to the device, assuming the condition is only temporary. If the condition is not temporary, it is possible to instruct ZFS to ignore the device by bringing it offline. This is done with the “zpool offline” command.

Again, let's run the “zpool status tank” command to review our mirror configuration.

Suppose you wanted to take the device c1t1d0 offline for maintenance. You would type the following “zpool offline “ command followed by the pool name and then the device name.

Now let's run the “zpool status tank” command again to see what happened.

Notice that in the “Config” section the device is listed as “offline.” Also notice that the mirror's state is listed as “degraded.” This means that the mirror is operating with less than full capacity.

In addition, the “Status” line reports that one of the devices has been taken offline, and the “Action” line provides guidance about how to return the mirror to the normal online state.

zpool status tank

zpool offline tank c1t1d0

------------sample ---------------

root@opensolaris:~# zpool status tank
  pool: tank
state: ONLINE
scrub: none requested
config:
        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          mirror    ONLINE       0     0     0
            c8d1    ONLINE       0     0     0
            c10d0   ONLINE       0     0     0
errors: No known data errors
root@opensolaris:~# zpool offline tank c10d0
root@opensolaris:~# zpool status tank
  pool: tank
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: none requested
config:
        NAME        STATE     READ WRITE CKSUM
        tank        DEGRADED     0     0     0
          mirror    DEGRADED     0     0     0
            c8d1    ONLINE       0     0     0
            c10d0   OFFLINE      0     0     0
errors: No known data errors
root@opensolaris:~#

-----------------------------------

Bringing a Device Online

Once you have finished your maintenance tasks, you can easily bring the device back online. Simply use the 'zpool online” command accompanied by the pool name and the device name.

Then we'll use the “zpool status tank” command to check the results:

As you can see, the device c1t1d0 is back online and part of the mirrored pool.

zpool online tank c1t1d0

---------------sample-----------

root@opensolaris:~#  zpool online tank c10d0
root@opensolaris:~# zpool status tank
  pool: tank
state: ONLINE
scrub: resilver completed after 0h0m with 0 errors on Mon Dec  7 16:20:44 2009
config:
        NAME        STATE     READ WRITE CKSUM
        tank        ONLINE       0     0     0
          mirror    ONLINE       0     0     0
            c8d1    ONLINE       0     0     0
            c10d0   ONLINE       0     0     0  1.50K resilvered
errors: No known data errors
root@opensolaris:~#

---------------------------------

Replacing One Device With Another

Sometimes you might want to replace one device with another. ZFS allows you to do this with a single operation. Just use the “zpool replace” command.

For example, let's look at our mirror called “tank.” We type in the “zpool status tank” command and review the output.

You'll notice that there are two devices in the pool: c1t0d0 and c1t1d0. Now we'll use the “zpool replace” to replace the device c1t10d0 with a new device named c1t2d0.

During this operation ZFS displays the following output showing that the device is being replaced.

Running the “zpool status tank” command again shows the new configuration.

Notice that the new device has replaced the old device in the mirror.

---
zpool status tank
zpool replace tank c1t1d0 c1t2d0
zpool status tank
It takes two commans in ZFS to replace one drive with another drive.
false

Summary

As you can see, managing ZFS pools is very simple. Just master a few simple commands and you can complete a variety of important tasks.

If you have any questions, please click the Back button and review. Otherwise, click the Exit button to return to the Main Menu and proceed to the next lesson.

没有评论:

发表评论