Benutzer-Werkzeuge

Webseiten-Werkzeuge


zfs

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
zfs [2020-05-19 06:58:44] – [ZFS] manfredzfs [2025-12-10 17:26:41] (aktuell) – [ZFS-Snapshot erstellen] manfred
Zeile 1: Zeile 1:
 +====== ZFS ======
 +
 +  - [[::freebsd:ZFS]] in FreeBSD
 +  - [[https://www.pro-linux.de/news/1/27955/openzfs-mit-besserer-freebsd-unterst%C3%BCtzung.html|OpenZFS mit besserer FreeBSD-Unterstützung]]
 +    * Die OpenZFS-Entwickler haben Anpassungen für FreeBSD in ihr Repositorum übernommen. FreeBSD plant bereits seit geraumer Zeit, auf die freie Variante des ZFS-Dateisystems aufzusetzen und trieb die Integration voran.
 +    * ... Doch auch andere Betriebssysteme setzen nicht auf das Original-ZFS, sondern auf verschiedene Implementierungen. So nutzt beispielsweise FreeBSD die von dem [[https://www.pro-linux.de/news/1/16000/illumos-projekt-startet.html|Illumos-Projekt]] vorangetriebene Implementierung des Dateisystems, die allerdings OpenZFS hinterherhinkt. Die FreeBSD-Entwickler haben deshalb letztes Jahr [[https://lists.freebsd.org/pipermail/freebsd-current/2018-December/072422.html|beschlossen]], dass die ZFS-Unterstützung von FreeBSD auf OpenZFS - und damit auch >>ZFS On Linux<< - migriert werden soll. Dieser Schritt soll letztendlich auch eine bessere Unterstützung und Funktionalität erzielen und das Open-Source-ZFS-Ökosystem vereinheitlichen. Allan Jude präsentierte auf der EuroBSDCon 2019 die [[https://2019.eurobsdcon.org/slides/The%20Future%20of%20OpenZFS%20and%20FreeBSD%20-%20Allan%20Jude.pdf|Kombination aus OpenZFS + FreeBSD]] und stellte eine Aufnahme der Änderungen in OpenZFS in Aussicht. Die Resultate der Arbeit sind nun letzte Woche in das offizielle Repositorium von OpenZFS eingeflossen und sollen nun als eine gemeinsame Codebasis zwischen Illumos, FreeBSD und Linux dienen. Weitere Systeme wie MacOS und Windows können zu einem späteren Zeitpunkt folgen.
 +  * [[https://community.oracle.com/docs/DOC-914874|Part 10 - Monitoring and Tuning ZFS Performance]]
 +
 +
 +===== Installation =====
 +
 +Linux:
 +  > apt install zfsutils-linux zfsnap
 +
 +FreeBSD //(Die ZFS-Tools sind bereits im FreeBSD-Basis-System enthalten)//:
 +  > pkg install sysutils/zfsnap
 +
 +
 +===== Allgemeines =====
 +
 +  > zfs list -s used
 +  > zfs list -S used
 +
 +
 +==== ZFS-Cache ====
 +
 +  * [[http://dtrace.org/blogs/brendan/2012/01/09/activity-of-the-zfs-arc/|Brendan's blog: Activity of the ZFS ARC]]
 +  * [[https://books.google.de/books?id=CDY9DwAAQBAJ&pg=PT730&lpg=PT730&dq=top+arc+mfu+mru|Absolute FreeBSD, 3rd Edition: The Complete Guide to FreeBSD]]
 +  * [[https://books.google.de/books?id=uhgNDgAAQBAJ&pg=PA363&lpg=PA363&dq=top+arc+mfu+mru|UNIX: The Textbook, Third Edition]]
 +
 +  * ARC: ZFS's "Advanced Replacement Cache" (Self-Tuning)
 +  * MFU: Most Frequently Used
 +  * MRU: Most Recently Used
 +
 +
 +==== ZFS-Snapshot ====
 +
 +[[:FreeBSD:ZFS-Snapshot]]
 +
 +
 +==== ZFS mit Verschlüsselung ====
 +
 +ZFS-Pool anlegen (ohne Mount-Point):
 +  > zpool create -m none HDD1000 /dev/sda
 +  > zpool list HDD1000
 +  > zpool status HDD1000
 +  > zfs get mountpoint,compression,encryption HDD1000
 +  NAME     PROPERTY     VALUE           SOURCE
 +  HDD1000  mountpoint   none            local
 +  HDD1000  compression  off             default
 +  HDD1000  encryption   off             default
 +
 +ZFS-Volumen mit Verschlüsselung anlegen (mit Mount-Point):
 +  > zfs get 2>&1 | grep -Fi encryption
 +          encryption       NO      YES   on | off | aes-128-ccm | aes-192-ccm | aes-256-ccm | aes-128-gcm | aes-192-gcm | aes-256-gcm
 +  
 +  > zfs create -o encryption=aes-256-gcm -o keylocation=prompt -o keyformat=passphrase -o mountpoint=/HDD1000/test HDD1000/test
 +
 +Infos über das ZFS-Volumen anzeigen:
 +  > zfs list HDD1000/test
 +  NAME           USED  AVAIL     REFER  MOUNTPOINT
 +  HDD1000/test   98K   899G       98K  /HDD1000/test
 +  
 +  > zfs get mountpoint,compression,encryption HDD1000/test
 +  NAME           PROPERTY     VALUE           SOURCE
 +  HDD1000/test   mountpoint   /HDD1000/test   local
 +  HDD1000/test   compression  off             default
 +  HDD1000/test   encryption   aes-256-gcm     -
 +  
 +  > zfs list
 +  NAME           USED  AVAIL     REFER  MOUNTPOINT
 +  HDD1000        274K   899G       24K  none
 +  HDD1000/test    98K   899G       98K  /HDD1000/test
 +
 +ZFS-Volumen wieder löschen:
 +  > zfs destroy HDD1000/test
 +
 +ZFS-Pool wieder löschen:
 +  > zpool destroy HDD1000
 +
 +
 +==== ZFS-Snapshot erstellen ====
 +
 +<file bash /root/bin/zfs-snapshot.sh>
 +#!/bin/bash
 +
 +#------------------------------------------------------------------------------#
 +# Dieses Skript macht von dem ZFS-Pool "mysql_datadir" einen SnapShot.
 +#
 +# Es kann maximal EINER pro Stunde angelegt werden,
 +# sollte für diesen Zeitraum bereits einer existieren,
 +# dann wird er vorher gelöscht.
 +#------------------------------------------------------------------------------#
 +# zfs snapshot mysql_datadir@4-16
 +# zfs list -t snapshot mysql_datadir
 +# mount -t zfs mysql_datadir@7-16 /mnt
 +# zfs destroy mysql_datadir@4-16
 +#------------------------------------------------------------------------------#
 +# Bedeutung von "mysql_datadir@4-16"
 +# mysql_datadir - ZFS-Pool (Tank)
 +# 4             - 4. Wochentag -> am Donnerstag aufgenommen
 +# 16            - zwischen 16:00 und 16:59 Uhr aufgenommen
 +#------------------------------------------------------------------------------#
 +
 +SNAP_ZEIT="$(date +'%u-%H')"
 +zfs list -Hp | awk '/mysql_datadir/{print $1}' | while read SNAP
 +do
 + echo "################################################################################"
 + echo "snapshot ${SNAP}@${SNAP_ZEIT} erneuern"
 + zfs destroy ${SNAP}@${SNAP_ZEIT}
 + zfs snapshot ${SNAP}@${SNAP_ZEIT}
 +done
 +echo
 + 
 +# alle SnapShots anzeigen
 +zfs list -t snapshot
 +</file>
 +
 +
 +==== ZFS-Snapshot mounten ====
 +
 +<code bash>
 +root@mysqlhost01:~# zfs list -t snapshot
 +NAME                 USED  AVAIL  REFER  MOUNTPOINT
 +mysql_datadir@3-17     0B      -  10.1M  -
 +
 +root@mysqlhost01:~# mount -t zfs mysql_datadir@3-17 /mnt/
 +
 +root@mysqlhost01:~# df -h /mnt/
 +Filesystem          Size  Used Avail Use% Mounted on
 +mysql_datadir@3-17  145G   11M  145G   1% /mnt
 +
 +root@mysqlhost01:~# ls -lha /mnt/
 +total 13K
 +drwxr-xr-x  3 mysql mysql    3 Dec  9 17:19 .
 +drwxr-xr-x 23 root  root  4.0K Dec  9 15:39 ..
 +drwxr-xr-x  7 mysql mysql   53 Dec 10 16:21 data
 +
 +root@mysqlhost01:~# umount /mnt/
 +
 +root@mysqlhost01:~# df -h /mnt/
 +Filesystem      Size  Used Avail Use% Mounted on
 +/dev/sda2        48G   13G   33G  28% /
 +
 +root@mysqlhost01:~# ls -lha /mnt/
 +total 8.0K
 +drwxr-xr-x  2 root root 4.0K Aug  5 16:54 .
 +drwxr-xr-x 23 root root 4.0K Dec  9 15:39 ..
 +</code>
 +
 +
 +==== ZFS-Snapshot löschen ====
 +
 +<code bash>
 +root@mysqlhost01:~# zfs list -t snapshot
 +NAME                 USED  AVAIL  REFER  MOUNTPOINT
 +mysql_datadir@3-17     0B      -  10.1M  -
 +
 +root@mysqlhost01:~# zfs destroy mysql_datadir@3-17
 +
 +root@mysqlhost01:~# zfs list -t snapshot
 +no datasets available
 +</code>
 +
 +
 +==== ZFS-Pool resize ====
 +
 +[[https://docs.freebsd.org/en/books/handbook/disks/]]
 +
 +the resize is triggered by running the online subcommand with ''-e'':
 +<code bash resize>
 +root@mysqlhost01:~# zpool list
 +
 +root@mysqlhost01:~# zpool online -e mysql_datadir /dev/sdb
 +
 +root@mysqlhost01:~# zpool list
 +</code>
 +
 +
 +==== Stand 2010 ====
 +
 +Leider gibt es unter Linux (und NetBSD) kein natives (und freies) ZFS (-Kernelmodul), es muss per FUSE eingebunden werden.
 +  * [[http://www.pro-linux.de/news/1/16091/native-zfs-unterstuetzung-fuer-den-linux-kernel.html]]
 +Weiterhin gibt es mit ZFS im Zusammenhang mit großen Datenmengen und weniger als 4GB RAM Probleme. Unter FUSE (egal ob Linux oder NetBSD) gibt es noch eine deutliche Verschärfung dieser Probleme.
 +
 +So ist bei mir in einem Test auf einem Rechner mit 2GB RAM der FUSE-Daemon immer ausgestiegen, wenn ich 300GB oder mehr auf die ZFS-Platte kopieren wollte (egal ob lokal oder übers Netz). ZFS ist immer bei ca. 300GB ausgestiegen, diese Tests habe ich mit verschiedenen Linuxdistributionen mehrfach durchgeführt.
 +
 +Aus diesem Grund würde ich ZFS unter Linux nur für USB-Sticks verwenden, auf großen Speichermedien
 +nur mit Solaris oder FreeBSD.
 +Unter FreeBSD und Solaris ist es dagegen mein absolutes Lieblingsdateisystem!
 +Soein genial einfach zu bedienendes und zuverlässiges Dateisystem ist momentan absolut konkurenzlos!
 +
 +
 +==== Stand Ende 2013 ====
 +
 +
 +=== Linux ===
 +
 +  * [[http://zfsonlinux.org/]]
 +    * [[http://wiki.ubuntuusers.de/Baustelle/ZFS_on_Linux]]
 +
 +Das Projekt [[https://launchpad.net/~zfs-native|Native ZFS for Linux]] hat jetzt einen gut funktionierenden nativen ZFS-Treiber für Linux fertig.\\
 +Ich nutze ihn seit ein paar Wochen und bin damit zufrieden.
 +
 +  > echo "deb http://ppa.launchpad.net/zfs-native/daily/ubuntu $(lsb_release -c | awk '{print $NF}') main" >> /etc/apt/sources.list
 +
 +  > apt-key adv --recv-keys --keyserver keyserver.ubuntu.com E871F18B51E0147C77796AC81196BA81F6B0FC61
 +  Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.moPJoH1QUo --trustdb-name /etc/apt//trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --recv-keys --keyserver keyserver.ubuntu.com E871F18B51E0147C77796AC81196BA81F6B0FC61
 +  gpg: requesting key F6B0FC61 from hkp server keyserver.ubuntu.com
 +  gpg: key F6B0FC61: public key "Launchpad PPA for Native ZFS for Linux" imported
 +  gpg: Total number processed: 1
 +  gpg:               imported: 1  (RSA: 1)
 +
 +  > apt-key export F6B0FC61
 +  -----BEGIN PGP PUBLIC KEY BLOCK-----
 +  Version: GnuPG v1.4.12 (GNU/Linux)
 +  
 +  mI0ETjjRQwEEAN1t7LdXiXEDucAXemaXZphLeDSmUE2gHxj/b+Gqt1wRaCMAE1NU
 +  rLOqTDNq8XPi4ZSp8Rr8R8jVupmKlt446ESGOadUO0AAjFyYe+YwZ65uYa69536k
 +  T+PhcFepWm8YgJL1skn0u+qpHzMJLvLB6iyAP8fP5C19wjiY8TtpSEtLABEBAAG0
 +  JkxhdW5jaHBhZCBQUEEgZm9yIE5hdGl2ZSBaRlMgZm9yIExpbnV4iLgEEwECACIF
 +  Ak440UMCGwMGCwkIBwMCBhUIAgkKCwQWAgMBAh4BAheAAAoJEBGWuoH2sPxh32cD
 +  /2uniH9nyAKYI3/6X29pmRXcsuf1J+ZYqEnUIWT41ZBvNJHkbMiSgNC0lUvW4miq
 +  LgHZrft2X3D1fUP6djnueTnFG/Rs/uVRCMU32YjmxW92nZc6StfNt35LT7CUd9xV
 +  /6e3h5klln/xUsimOm9BcHglUXF7n8U39qw9JGV2sheo
 +  =qkiU
 +  -----END PGP PUBLIC KEY BLOCK-----
 +
 +  > aptitude update
 +  Get: 3 http://ppa.launchpad.net raring Release.gpg [316 B]                                                                                     
 +  Get: 6 http://ppa.launchpad.net raring Release [9.757 B]                                                                              
 +  Get: 10 http://ppa.launchpad.net raring/main amd64 Packages [4.573 B]                                                    
 +  Get: 11 http://ppa.launchpad.net raring/main i386 Packages [4.548 B]                                                                                       
 +  Ign http://ppa.launchpad.net raring/main Translation-en_US
 +  Ign http://ppa.launchpad.net raring/main Translation-en
 +  Ign http://ppa.launchpad.net raring/main Translation-de
 +
 +  > aptitude search ubuntu-zfs
 +  p   ubuntu-zfs                                                                   - Native ZFS filesystem metapackage for Ubuntu.
 +  p   ubuntu-zfs:i386                                                              - Native ZFS filesystem metapackage for Ubuntu.
 +
 +  > aptitude install ubuntu-zfs
 +  The following NEW packages will be installed:
 +    build-essential dpkg-dev{a} g++{a} g++-4.7{a} libalgorithm-diff-perl{a} libalgorithm-diff-xs-perl{a} libalgorithm-merge-perl{a} libnvpair1{a} libstdc++6-4.7-dev{a} 
 +    libuutil1{a} libzfs1{a} libzpool1{a} spl spl-dkms{a} ubuntu-zfs zfs-dkms zfsutils 
 +  The following packages will be upgraded:
 +    mountall 
 +  1 packages upgraded, 17 newly installed, 0 to remove and 1 not upgraded.
 +  Need to get 14,3 MB of archives. After unpacking 45,9 MB will be used.
 +  Do you want to continue? [Y/n/?]
 +  
 +  ...
 +  
 +  depmod....
 +  
 +  DKMS: install completed.
 +  Setting up libstdc++6-4.7-dev:amd64 (4.7.3-1ubuntu1) ...
 +  Setting up g++-4.7 (4.7.3-1ubuntu1) ...
 +  Setting up g++ (4:4.7.3-1ubuntu10) ...
 +  update-alternatives: using /usr/bin/g++ to provide /usr/bin/c++ (c++) in auto mode
 +  Setting up dpkg-dev (1.16.10ubuntu1) ...
 +  Setting up build-essential (11.6ubuntu4) ...
 +  Setting up libalgorithm-diff-perl (1.19.02-3) ...
 +  Setting up libalgorithm-diff-xs-perl (0.04-2build3) ...
 +  Setting up libalgorithm-merge-perl (0.08-2) ...
 +  Setting up spl (0.6.2-1~raring) ...
 +  Setting up libuutil1 (0.6.2-1~raring) ...
 +  Setting up libnvpair1 (0.6.2-1~raring) ...
 +  Setting up libzpool1 (0.6.2-1~raring) ...
 +  Setting up libzfs1 (0.6.2-1~raring) ...
 +  Setting up zfsutils (0.6.2-1~raring) ...
 +  Processing triggers for initramfs-tools ...
 +  update-initramfs: Generating /boot/initrd.img-3.8.0-31-generic
 +  Warning: No support for locale: en_US.utf8
 +  
 +  Processing triggers for ureadahead ...
 +  Setting up ubuntu-zfs (7~raring) ...
 +  Processing triggers for libc-bin ...
 +  ldconfig deferred processing now taking place
 +                                           
 +  Current status: 1 update [-1].
 +
 +
 +===== Beispiel =====
 +
 +[[https://docs.freebsd.org/de/books/handbook/zfs/]]
 +
 +den Daten-Pool "speicher" anlegen:
 +  > zpool create speicher mirror /dev/ad7 /dev/ad8
 +
 +  > zpool list speicher
 +  > zpool iostat speicher
 +  > zpool status speicher
 +
 +alle Daten auf dem Pool überprüfen und ggf. reparieren:
 +  > zpool scrub speicher
 +
 +auf dem Daten-Pool "speicher" werden 4 ZFS-Volumen eingerichtet:
 +  > zfs create speicher/var
 +  > zfs create speicher/home
 +  > zfs create speicher/tmp
 +  > zfs create speicher/daten
 +
 +die 4 ZFS-Volumen bekommen jeweils einen Mount-Point zugewiesen:
 +  > zfs set mountpoint=/var   speicher/var
 +  > zfs set mountpoint=/home  speicher/home
 +  > zfs set mountpoint=/tmp   speicher/tmp
 +  > zfs set mountpoint=/daten speicher/daten
 +
 +so kannst du eine doppelte Redundanz einstellen, das bringt deutlich mehr Datensicherheit
 +  > zfs set copies=2 speicher/home
 +
 +so kannst du Kompression einstellen:
 +  > zfs set compression=gzip speicher/home
 +
 +einen SnapShot von ''home'' erstellen:
 +  > zfs snapshot speicher/home@$(date +'%F_%H-%M-%S')
 +
 +alle SnapShots von ''home'' anzeigen:
 +  > zfs list -rt snapshot speicher/home
 +  NAME                                USED  AVAIL  REFER  MOUNTPOINT
 +  speicher/home@2024-04-04_22-59-45     0B      -  24.0M  -
 +
 +den SnapShots mounten:
 +  > mount -t zfs speicher/home@2024-04-04_22-59-45 /mnt
 +  > ls -lha /mnt
 +  > umount /mnt
 +
 +den SnapShots löschen:
 +  > zfs destroy speicher/home@2024-04-04_22-59-45
 +  
 +  > zfs list -rt snapshot speicher/home
 +  no datasets available
 +
 +nur das eine ZFS-Volumen "daten" (''-r'' => samt seiner SnapShots) auf dem Daten-Pool "speicher" löschen:
 +  > zfs destroy -r speicher/daten
 +
 +alle ZFS-Volumen (''-r'' => samt ihrer SnapShots) auf dem Daten-Pool "speicher" löschen:
 +  > zfs destroy -r speicher
 +
 +den ganzen Daten-Pool "speicher" (samt seiner ZFS-Volumen) löschen:
 +  > zpool destroy speicher
 +