Leitfaden zur Nutzung von Binärpaketen

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Binary package guide and the translation is 68% complete.

Neben der gewöhnlichen Unterstützung von ebuilds bietet Portage den Bau und die Installation von Binärpaketen. Dieser Leitfaden erklärt wie man diese erstellt, installiert und wie man einen Binärpaket-Server aufsetzt.

Einleitung

Es gibt viele Gründe, weshalb einige Systemadministratoren die Verwendung von Binärpaketen für Softwareinstallationen unter Gentoo mögen:

  1. Es erlaubt Administratoren ähnliche Systeme aktuell zu halten. Alles aus den Quellen kompilieren zu müssen, kann zeitaufwändig werden. Die Wartung einiger ähnlicher Systeme, möglicherweise einige von ihnen mit älterer Hardware, kann sehr viel einfacher sein, wenn nur ein System alles aus den Quellen kompilieren muss und die anderen Systeme die Binärpakete verwenden.
  2. Sichere Updates durchzuführen. Für missionskritische Systeme in Produktionsumgebungen ist es wichtig soweit wie möglich benutzbar zu bleiben. Dies kann durch Staging-Server erreicht werden, die alle Updates zuerst bei sich selbst durchführen. Sobald der Staging-Server (wieder) in einem guten Zustand ist, können die Updates auf das kritische System angewandt werden. Eine Variante dieses Ansatzes ist die Updates in einer chroot-Umgebung auf dem selben System durchzuführen und die hierbei erzeugten Binärdateien dann im richtigen System zu benutzen.
  3. Als ein Backup. Oft sind Binärpakete der einzige Weg ein kaputtes System wiederherzustellen (z.B. kaputter Kompiler). Vorkompilierte Binärpakete bei der Hand zu haben, entweder auf einem Binärpaket-Server oder lokal, kann im Falle einer defekten Toolchain eine große Hilfe sein.
  4. Und schließlich hilft es ebenfalls sehr alte Systeme upzudaten. Die Aufgabe sehr alte Systeme upzudaten kann durch die Verwendung von Binärpaketen stark vereinfacht werden. Es ist für gewöhnlich hilfreich Binärpakete auf alten Systemen zu installieren weil sie keine Build-Time Abhängigkeiten erfordern, die installiert/ upgedatet werden müssten. Binär-Pakete vermeiden ebenfalls Fehler in Build-Prozessen, weil sie vorkompiliert sind.

Dieser Leitfaden konzentriert sich auf die folgenden Themen:

  • Die Erstellung von Binärpaketen.
  • Die Verteilung der Pakete an die Nutzer.
  • Die Implementierung der Binärpakete.
  • Die Pflege der Binärpakete.

Nahe am Ende werden ein paar fortgeschrittenere Themen zum Umgang mit Binärpaketen behandelt.

Hinweis
Alle in diesem Leitfaden verwendeten Tools sind Teil von sys-apps/portage, soweit nicht anders angegeben.

Binärpakete erzeugen

Es gibt drei Hauptmethoden um Binärpakete zu erzeugen:

  1. Nach einer regulären Installation durch Nutzung der quickpkg Anwendung;
  2. Explizit währen einer emerge-Operation durch den Gebrauch der --buildpkg (-b/) Option;
  3. Automatisch durch die Verwendung des buildpkg Werts in Portages FEATURES Variable.

Alle drei Methoden erzeugen ein Binärpaket im Verzeichnis auf das durch die PKGDIR-Variable gezeigt wird (deren Voreinstellung /var/cache/binpkgs ist).

Benutzung von quickpkg

Die Applikation quickpkg nimmt eine oder mehrere Abhängigkeits-atome (oder Paket-Sätze) und erstellt für alle installierten Pakete die mit diesem atom übereinstimmen Binärpakete.

Um beispielsweise von allen installierten GCC-Versionen Binärpakete zu erstellen:

root #quickpkg sys-devel/gcc

Um Binärpakete von allen auf dem System installierten Paketen zu schaffen, verwenden Sie * glob:

root #quickpkg "*/*"

Bei dieser Methode gibt es einen Vorbehalt: Sie ist auf die installierten Dateien angewiesen, was im Fall von Konfigurationsdateien ein Problem sein kann. Administratoren ändern Konfigurationsdateien nach der Softwareinstallation oft. Aus diesem Grund können (vielleicht sogar vertrauliche) Daten in die Pakete entweichen. quickpkg schließt standardmäßig Konfigurationsdateien nicht ein, die mit der CONFIG_PROTECT Methode geschützt sind. Um die Erfassung von Konfigurationsdateien zu erzwingen nutzen Sie die --include-config oder --include-unmodified-config Option.

--buildpkg als emerge Option nutzen

Bei der Installation von Software mit emerge kann Portage mit der --buildpkg (-b) Option verwendet werden, um Binärpakete zu erstellen:

root #emerge --ask --buildpkg sys-devel/gcc

Es ist ebenfalls möglich Portage dazu zu bringen nur Binärpakete zu erzeugen aber die Software nicht auf dem Live-System zu installieren. Dazu kann die --buildpkgonly (-B) Option verwendet werden:

root #emerge --ask --buildpkgonly sys-devel/gcc

Die letztere Herangehensweise macht es erforderlich alle Build-Time Abhängigkeiten zuvor zu installieren.

buildpkg as a Portage Eigenschaft nutzen

Die gewöhnlichste Art um automatisch Binärpakete zu erzeugen wann immer ein Paket von Portage installiert wird, ist die Nutzung der buildpkg Eigenschaft. Sie kann auf die folgende Weise in /etc/portage/make.conf gesetzt werden:

DATEI /etc/portage/make.confAktivierung der buildpkg Eigenschaft von Portage
FEATURES="buildpkg"

Falls diese Eigenschaft aktiviert ist, wird jedes mal wenn Portage Software installiert, ebenfalls ein Binärpaket erzeugt.

Erzeugung einiger Pakete ausschließen

Es ist möglich, Portage anzuweisen für einige ausgewählte Pakete oder Kategorien keine Binärpakete zu erstellen. Dies geschieht durch Übergabe der --buildpkg-exclude Option zu emerge:

root #emerge -uDN @world --buildpkg --buildpkg-exclude "virtual/* sys-kernel/*-sources"

Dies könnte für Pakete verwendet werden, bei denen es wenig bis gar keinen Nutzen bring, ein Binärpaket zur Verfügung zu haben. Beispiele wären die Linux-Kernel-Quellpakete oder Upstream-Binärpakete (die mit "-bin" enden, wie www-client/firefox-bin).

Einrichtung eines Binärpaket-Hosts

Portage unterstützt eine Reihe von Protokollen für das Herunterladen von Binärpaketen: FTP, FTPS, HTTP, HTTPS und SSH/SFTP. Dies lässt Raum für viele mögliche Implementierungen von Binärpaket-Hosts.

Es gibt jedoch keine "out-of-the-box" Methode, die von Portage für die Verteilung von Binärpaketen angeboten wird. Je nach gewünschten Setup muss zusätzliche Software installiert werden.

Webbasierter Binärpaket-Hosts

Ein gängiger Ansatz für die Verteilung von Binärpaketen ist die Erstellung eines webbasierten Binärpaket-Hosts.

Verwenden Sie einen Webserver wie lighttpd (www-servers/lighttpd) und konfigurieren Sie in so, dass er Lesezugriff auf /etc/portage/make.confs PKGDIR Verzeichnis hat.

DATEI /etc/lighttpd/lighttpd.confLighttpd Konfigurationsbeispiel
# Dies am Ende der Standardkonfiguration anfügen
server.modules += ( "mod_alias" )
alias.url = ( "/packages" => "/var/cache/binpkgs/" )

Auf den Client-Systemen konfigurieren Sie dann die Variable PORTAGE_BINHOST entsprechend:

DATEI /etc/portage/make.confBenutzung eines webbasiertem Binärpaket-Hosts
PORTAGE_BINHOST="http://binhost.example.com/packages"

SSH-Binärpaket-Host

Um einen authentifizierten Ansatz für Binärpakete zu liefern, kann man SSH verwenden.

Bei der Verwendung von SSH ist es möglich, den SSH-Schlüssel des Root-Linux-Benutzers zu verwenden (ohne Passphrase, da die Installationen im Hintergrund erfolgen müssen), um eine Verbindung zu einem entfernten Binärpaket-Host herzustellen.

Stellen Sie dazu sicher, dass der SSH-Schlüssel des Root-Benutzers auf dem Server zugelassen ist. Dies muss für jeden Rechner geschehen, der eine Verbindung mit dem SSH-fähigen Binärpaket-Host herstellen will:

root #cat root.id_rsa.pub >> /home/binpkguser/.ssh/authorized_keys

Die PORTAGE_BINHOST Variable könnte dann wie folgt aussehen:

DATEI /etc/portage/make.confEinrichten von PORTAGE_BINHOST mit SSH-Zugang
PORTAGE_BINHOST="ssh://binpkguser@binhostserver/var/cache/binpkgs"
Hinweis
Verwenden Sie nicht die SSH-Konfigurationsdateien, die Sie in ~/.ssh/config finden, um den Port oder Benutzernamen zu setzen. Dieses Verzeichnis wird ignoriert, wenn Portage versucht, die Pakete mit rsync auf den Client zu übertragen. Setzen Sie stattdessen alle Optionen korrekt in der PORTAGE_BINHOST Variable.

NFS exportiert

Bei der Verwendung von Binärpaketen in einem internen Netzwerk kann es einfacher sein, die Pakete über NFS zu exportieren und sie auf den Clients einzuhängen.

Die /etc/exports Datei könnte wie folgt aussehen:

DATEI /etc/exportsExportieren des Paketverzeichnisses
/var/cache/binpkgs   2001:db8:81:e2::/48(ro,no_subtree_check,root_squash) 192.168.100.1/24(ro,no_subtree_check,root_squash)

Auf den Clients kann das Verzeichnis dann eingehängt werden. Ein Beispiel für einen /etc/fstab-Eintrag würde so aussehen:

DATEI /etc/fstabEintrag zum Einhängen des Paketverzeichnisses
binhost:/var/cache/binpkgs      /var/cache/binpkgs    nfs    defaults    0 0

Verwendung von Binärpaketen

Damit Binärpakete auf anderen Systemen verwendet werden können, müssen sie einige Anforderungen erfüllen:

  • Die Client- und Server-Prozessorarchitektur und CHOST müssen übereinstimmen.
  • Die CFLAGS und CXXFLAGS Variablen, die zum Bau der Pakete verwendet werden, müssen mit allen Clients kompatibel sein.
  • USE-Flags für prozessorspezifische Befehlssatzmerkmale (wie MMX, SSE usw.) müssen sorgfältig ausgewählt werden; alle Clients müssen sie unterstützen.
Wichtig
Portage kann nicht überprüfen, ob diese Anforderungen übereinstimmen. Es liegt in der Verantwortung des Systemadministrators, diese Einstellungen zu überwachen.

Next to these, Portage will check if the binary package is built using the same USE flags as expected on the client. If a package is built with a different USE flag combination, Portage will either ignore the binary package (and use source-based build) or fail, depending on the options passed to the emerge command upon invocation (see Installing binary packages).

On clients, a few configuration changes are needed in order for the binary packages to be used.

Installation von Binärpaketen

There are a few options that can be passed on to the emerge command that inform Portage about using binary packages:

Option Description
--usepkg (-k) Tries to use the binary package(s) in the locally available packages directory. Useful when using NFS or SSHFS mounted binary package hosts. If the binary packages are not found, a regular (source-based) installation will be performed.
--usepkgonly (-K) Similar to --usepkg (-k) but fail if the binary package cannot be found. This option is useful if only pre-built binary packages are to be used.
--getbinpkg (-g) Download the binary package(s) from a remote binary package host. If the binary packages are not found, a regular (source-based) installation will be performed.
--getbinpkgonly (-G) Similar to --getbinpkg (-g) but will fail if the binary package(s) cannot be downloaded. This option is useful if only pre-built binary packages are to be used.

In order to automatically use binary package installations, the appropriate option can be added to the EMERGE_DEFAULT_OPTS variable:

DATEI /etc/portage/make.confAutomatisches Abrufen von Binärpaketen und Fehlschlagen des Pakets, wenn es nicht verfügbar ist
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --getbinpkgonly"

There is a Portage feature that automatically implements the equivalent of --getbinpkg (-g) without the need for updating the EMERGE_DEFAULT_OPTS variable with the --getbinpkg value:

DATEI /etc/portage/make.confAktivieren von getbinpkg in der Variable FEATURES
FEATURES="getbinpkg"

Pakete von einem Binärpaket-Host abrufen

When using a binary package host, clients need to have the PORTAGE_BINHOST variable set. Otherwise the client will not know where the binary packages are stored which results in Portage being unable to retrieve them.

DATEI /etc/portage/make.confEinstellung von PORTAGE_BINHOST
PORTAGE_BINHOST="http://binhost.example.com/packages"

The PORTAGE_BINHOST variable uses a space-separated list of URIs. This allows administrators to use several binary package servers simultaneously. The URI must always point to the directory in which the Packages file resides.

Hinweis
The support for multiple binary package servers is somewhat incomplete. If several servers serve a binary package for the same package version, then only the first one will be considered. This can be problematic when these binary packages differ in their USE variable configuration and the USE variable configuration of a later binary package would match the systems configuration.

Neuinstallation von modifizierten Binärpaketen

Passing the --rebuilt-binaries option to emerge will reinstall every binary that has been rebuilt since the package was installed. This is useful in case rebuilding tools like revdep-rebuild are run on the binary package server.

A related option is --rebuilt-binaries-timestamp. It causes emerge not to consider binary packages for a re-install if those binary packages have been built before the given time stamp. This is useful to avoid re-installing all packages, if the binary package server had to be rebuild from scratch but --rebuilt-binaries is used otherwise.

Zusätzliche Client-Einstellungen

Next to the getbinpkg feature, Portage also listens to the binpkg-logs feature. This one controls if log files for successful binary package installations should be kept. It is only relevant if the PORT_LOGDIR variable has been set and is enabled by default.

Similar to excluding binary packages for a certain set of packages or categories, clients can be configured to exclude binary package installations for a certain set of packages or categories.

To accomplish this, use the --usepkg-exclude option:

root #emerge -uDNg @world --usepkg-exclude "sys-kernel/gentoo-sources virtual/*"

To enable such additional settings for each emerge command, add the options to the EMERGE_DEFAULT_OPTS variable in the make.conf file:

DATEI /etc/portage/make.confAktivieren der Emerge-Einstellungen bei jedem Aufruf
EMERGE_DEFAULT_OPTS="${EMERGE_DEFAULT_OPTS} --usepkg-exclude 'sys-kernel/gentoo-sources virtual/*'"

Pflege von Binärpaketen

Exporting and distributing the binary packages will lead to useless storage consumption if the binary package list is not actively maintained.

Entfernen von veralteten Binärpaketen

In the app-portage/gentoolkit package an application called eclean is provided. It allows for maintaining Portage-related variable files, such as downloaded source code files, but also binary packages.

The following command will remove all binary packages that have no corresponding ebuild in the installed ebuild repositories:

root #eclean packages

For more details please read the Eclean article.

Another tool that can be used is the qpkg tool from the app-portage/portage-utils package. However, this tool is a bit less configurable.

To clean up unused binary packages (in the sense of used by the server on which the binary packages are stored):

root #qpkg -c

Pflege der Packages-Datei

Inside the packages directory exists a manifest file called Packages. This file acts as a cache for the metadata of all binary packages in the packages directory. The file is updated whenever Portage adds a binary package to the directory. Similarly, eclean updates it when it removes binary packages.

If for some reason binary packages are simply deleted or copied into the packages directory, or the Packages file gets corrupted or deleted, then it must be recreated. This is done using emaint command:

root #emaint binhost --fix

Fortgeschrittene Themen

Creating snapshots of the packages directory

When deploying binary packages for a large number of client systems it might become worthwhile to create snapshots of the packages directory. The client systems then do not use the packages directory directly but use binary packages from the snapshot.

Snapshots can be created using the /usr/lib64/portage/python2.7/binhost-snapshot or /usr/lib64/portage/python3.3/binhost-snapshot tool. It takes four arguments:

  1. A source directory (the path to the packages directory).
  2. A target directory (that must not exist).
  3. A URI.
  4. A binary package server directory.

The files from the package directory are copied to the target directory. A Packages file is then created inside the binary package server directory (fourth argument) with the provided URI.

Client systems need to use an URI that points to the binary package server directory. From there they will be redirected to the URI that was given to binhost-snapshot. This URI has to refer to the target directory.

Verstehen des Binärpaketformats

Binary packages created by Portage have the file name ending with .tbz2. These files consist of two parts:

  1. A .tar.bz2 archive containing the files that will be installed on the system.
  2. A xpak archive containing package metadata, the ebuild, and the environment file.

See man xpak for a description of the format.

In app-portage/portage-utils some tools exists that are able to split or create tbz2 and xpak files.

The following command will split the tbz2 into a .tar.bz2 and an .xpak file:

user $qtbz2 -s <package>.tbz2

The .xpak file can be examined using the qxpak utility.

To list the contents:

user $qxpak -l <package>.xpak

The next command will extract a file called USE which contains the enabled USE flags for this package:

user $qxpak -x package-manager-0.xpak USE

Das PKGDIR-Layout

The currently used format version 2 has the following layout:

CODE Layout des Pakete-Verzeichnisses (Version 2)
PKGDIR
`+- Packages
 +- app-accessibility/
 |  +- pkg1-version.tbz2
 |  `- pkgN-version.tbz2
 +- app-admin/
 |  `- ...
 `- ...

The Packages file is the major improvement (and also the trigger for Portage to know that the binary package directory uses version 2) over the first binary package directory layout (version 1). In version 1, all binary packages were also hosted inside a single directory (called All/) and the category directories only had symbolic links to the binary packages inside the All/ directory.

Entpacken mit quickunpkg

Zoobab wrote a simple shell tool named quickunpkg to quickly unpack tbz2 files.