Usare apt-cacher per creare una cache dei pacchetti usabile in una LAN: differenze tra le versioni

Vai alla navigazione Vai alla ricerca
Nessun oggetto della modifica
mNessun oggetto della modifica
Riga 1: Riga 1:
==Introduzione==
=Introduzione=
Apt-cacher è un programma che ha lo scopo di creare una cache di pacchetti deb su un server, per poi renderli disponibili a tutte le macchine presenti sulla LAN. In questo modo è possibile limitare la banda utlizzata in uscita e velocizzare i tempi di installazione. <br>
Il pacchetto bootsplash per Debian, presente nei repository:
A differenza di apt-proxy (http://apt-proxy.sourceforge.net/), apt-cacher ha una struttura completamente piatta, per cui i pacchetti dela cache sono conservati in una unica directory anche se provengono da repository diversi; questa soluzione ne rende l'utilizzo più semplice e immediato.
                             
==Installazione==
Per installare apt-cache è sufficiente digitare sul server che dovrà contenere la cache
<pre>
<pre>
# apt-get install apt-cacher
deb http://debian.bootsplash.de unstable main
deb-src http://debian.bootsplash.de unstable main
</pre>
</pre>
molto comodo per la gestione dei temi, ma ha un ''difetto'': utilizza debconf per la gestione dei temi. Questo porta ad un effetto collaterale: i temi installati manualmente non saranno riconosciuti e per poterli usare si dovranno eseguire operazioni scomode (rispetto ad un semplice ''dpkg-reconfigure bootsplash'' :-) ).


==Configurazione==
Vedremo, ora, come creare un pacchetto Debian contenente un tema, e come gestire il template di debconf per aggiornare la lista dei temi.
Per configurare apt-cacher è necessario <br>  
 
1) modificare il file
{{Box|Nota Bene:|gli script qui descritti non sono opera mia, ma di [mailto:oliver_at_dediziert_dot_org Oliver Sorge], che mantiene i temi presenti nel repository sopra riportato}}
 
=Requisiti=
Per poter creare un pacchetto Debian dobbiamo installare i seguenti pacchetti:
* build-essential
* dpkg-dev
* dh-make
* debhelper
 
=Creazione del pacchetto=
Estraiamo il pacchetto contenente il tema, e rinominiamo la directory contenente il tema in un formato del tipo ''bootsplash-theme-<nometema>-<versione>''.
 
La directory deve contenere le directory images, ...
 
Una volta completato, lanciamo il comando
<pre>
<pre>
/etc/default/apt-cacher
$ dh_make --copyright GPL
</pre>
</pre>
ponendo ad 1 il valore di AUTOSTART. In questo modo apt-cacher si avvierà automaticamente ad ogni sessione. Nel caso vogliate avviare/fermare apt-cacher manualmente basterà usare il comando
ovviamente dopo aver verificato la licenza del tema...
 
Alla domanda
<pre>
<pre>
# /etc/init.d/apt-cacher {start|stop|restart|force-reload}
Type of package: single binary, multiple binary, library, or kernel module?
[s/m/l/k]</pre> rispondiamo con una ''s''.
 
Controlliamo i dati riportati (per il nome e l'email possiamo usare le variabili d'ambiente $DEBEMAIL e $DEBFULLNAME); se tutto � corretto � possibile andare avanti.
 
Verr� cos� creata la directory debian/, contenente tutto il necessario per il nostro pacchetto.
 
==La directory debian/*==
===Rimozione dei file non necessari===
La directory debian/ contiene molti file non necessari, che possiamo tranquillamente rimuovere:
<pre>
$ cd debian
$ rm conffiles.ex cron.d.ex emacsen* init.d.ex manpage* matrix* menu.ex watch*
</pre>
</pre>
2) modificare il file
 
===.templates===
Dobbiamo creare il template utilizzato da debconf. Creiamo, quindi, un file del tipo ''bootsplash-theme-<nometema>.template'' con il seguente contenuto:
<pre>
<pre>
/etc/apt-cacher/apt-cacher.conf
Template: shared/bootsplash-theme
Type: select
Choices: ${choices}
Description: Please select theme bootsplash should use.
Please select the theme bootsplash should use.  If you wish to
change it at a later date, just run dpkg-reconfigure bootsplash.
 
Template: bootsplash-theme-<nometema>/resolutions
Type: multiselect
Choices: 1024x768
Default: 1024x768
Description: Select the resoultion you would like to enable bootsplash for.
You need to select which resolutions bootsplash should be enabled for, also
remember to include the proper (vga=???) line in your lilo.conf.
</pre>
</pre>
che contiene tutte le opzioni configurabili.
Ricordandoci di sostituire a ''<nometema>'' il nome del nostro tema ed eventualmente sistemare i valori delle risoluzioni.
Riportiamo il file di configurazione originale per completezza
 
===rules===
Il file ''debian/rules'' necessit� di molte modifiche... Conviene, quindi, sostituire il contenuto con questo:
<pre>
<pre>
#################################################################
#!/usr/bin/make -f
# This is the config file for apt-cacher. On most Debian systems
# -*- makefile -*-
# you can safely leave the defaults alone.
# Sample debian/rules that uses debhelper.
#################################################################
# GNU copyright 1997 to 1999 by Joey Hess.


# cache_dir is used to set the location of the local cache. This can
# Uncomment this to turn on verbose mode.
# become quite large, so make sure it is somewhere with plenty of space.
# export DH_VERBOSE=1
cache_dir=/var/cache/apt-cacher


# The email address of the administrator is displayed in the info page
# Edit these lines!!!
# and traffic reports.
THEME_DIRS = images config animations bootloader
admin_email=root@localhost
THEME_SUFFIX = <nometema>


# For the daemon startup settings please edit the file /etc/default/apt-cacher.
configure: configure-stamp
configure-stamp:
        dh_testdir
        touch configure-stamp


# Daemon port setting, only useful in stand-alone mode. You need to run the
build: build-stamp
# daemon as root to use privileged ports (<1024).
daemon_port=3142


# optional settings, user and group to run the daemon as. Make sure they have
build-stamp: configure-stamp
# sufficient permissions on the cache and log directories. Comment the settings
        dh_testdir
# to run apt-cacher as the native user.
        touch build-stamp
group=www-data
user=www-data


# optional setting, binds the listening daemon to one specified IP. Use IP
clean:
# ranges for more advanced configuration, see below.
        dh_testdir
# daemon_addr=localhost
        dh_testroot
        rm -f build-stamp configure-stamp
        dh_clean


# If your apt-cacher machine is directly exposed to the Internet and you are
install: build
# worried about unauthorised machines fetching packages through it, you can
        dh_testdir
# specify a list of IPv4 addresses which are allowed to use it and another
        dh_testroot
# list of IPv4 addresses which aren't.
        dh_clean -k
# Localhost (127.0.0.1) is always allowed. Other addresses must be matched
        dh_installdirs
# by allowed_hosts and not by denied_hosts to be permitted to use the cache.
        -cp -a $(THEME_DIRS) \
# Setting allowed_hosts to "*" means "allow all".
"$(CURDIR)/debian/bootsplash-theme-$(THEME_SUFFIX)/etc/bootsplash/themes/$(THEME_SUFFIX)/"
# Otherwise the format is a comma-separated list containing addresses,
# optionally with masks (like 10.0.0.0/22), or ranges of addresses (two
# addresses separated by a hyphen, no masks, like '192.168.0.3-192.168.0.56').
allowed_hosts=*
denied_hosts=


# And similiarly for IPv6 with allowed_hosts_6 and denied_hosts_6.
binary-indep: build install
# Note that IPv4-mapped IPv6 addresses (::ffff:w.x.y.z) are truncated to
        # We have nothing to do by default.
# w.x.y.z and are handled as IPv4.
allowed_hosts_6=fec0::/16
denied_hosts_6=


# This thing can be done by Apache but is much simplier here - limit access to
# Build architecture-dependent files here.
# Debian mirrors based on server names in the URLs
binary-arch: build install
#allowed_locations=ftp.uni-kl.de,ftp.nerim.net,debian.tu-bs.de
        dh_testdir
        dh_testroot
        dh_installchangelogs
        dh_installdocs
        dh_installdebconf
        dh_link
        dh_strip
        dh_compress
        dh_fixperms
        dh_installdeb
        dh_shlibdeps
        dh_gencontrol
        dh_md5sums
        dh_builddeb


# Apt-cacher can generate usage reports every 24 hours if you set this
binary: binary-indep binary-arch
# directive to 1. You can view the reports in a web browser by pointing
.PHONY: build clean binary-indep binary-arch binary install configure
# to your cache machine with '/apt-cacher/report' on the end, like this:
</pre>
#      http://yourcache.example.com/apt-cacher/report
# Generating reports is very fast even with many thousands of logfile
# lines, so you can safely turn this on without creating much
# additional system load.
generate_reports=1


# Apt-cacher can clean up its cache directory every 24 hours if you set
ricordando le seguente cose:
# this directive to 1. Cleaning the cache can take some time to run
* fare attenzione ad usare la tabulazioni (tasto <tab>) al posto degli spazi per le indentazioni (obbligatorie)!
# (generally in the order of a few minutes) and removes all package
* modificare la variabile THEME_DIRS riportando solo le directory presenti all'interno della directory ''<nometema>-<versione>'' ad eccezione di ''debian''.
# files that are not mentioned in any existing 'Packages' lists. This
* modificare la variabile THEME_SUFFIX con il nome del tema.
# has the effect of deleting packages that have been superseded by an
# updated 'Packages' list.
clean_cache=1


# The directory to use for apt-cacher access and error logs.
===control===
# The access log records every request in the format:
Il file ''debian/control'' necessita di alcune modifiche:
# date-time|client ip address|HIT/MISS/EXPIRED|object size|object name
* ''Section'' dovrebbe essere modificata in ''graphics''
# The error log is slightly more free-form, and is also used for debug
* ''Architecture'' pu� essere modificato in ''all'', visto che il pacchetto non sar� dipendente dall'architettura
# messages if debug mode is turned on.
* ''Depends'' pu� essere modificato in ''bootsplash (>= 3.0.0), debconf (>= 0.5) | debconf-2.0''
# Note that the old 'logfile' and 'errorfile' directives are
* deve essere aggiunta la riga ''Provides: bootsplash-theme''
# deprecated: if you set them explicitly they will be honoured, but it's
* la descrizione deve essere modificata nel seguente modo (in linea coi pacchetti di http://www.bootsplash.de ):
# better to just get rid of them from old config files.
<pre>Description: The bootsplash theme <nometema>
logdir=/var/log/apt-cacher
This is another bootsplash theme packaged for the Debian GNU/Linux
Operating System.
.
Resolutions: 1280x1024</pre>


# apt-cacher can use different methods to decide whether package lists need to
===dirs===
# be updated,
Dovr� contenere
# A) looking at the age of the cached files
<pre>
# B) getting HTTP header from server and comparing that with cached data. This
etc/bootsplash/themes/<nometema>
# method is more reliable and avoids desynchronisation of data and index files
</pre>
# but needs to transfer few bytes from the server every time somebody requests
# the files ("apt-get update")
# Set the following value to the maximum age (in hours) for method A or to 0
# for method B
expire_hours=0


# Apt-cacher can pass all its requests to an external http proxy like
===docs===
# Squid, which could be very useful if you are using an ISP that blocks
Dovr� contenere
# port 80 and requires all web traffic to go through its proxy. The
<pre>
# format is 'hostname:port', eg: 'proxy.example.com:8080'.
docs/*
http_proxy=proxy.example.com:8080
</pre>
se la directory � presente nei sorgenti del tema (altrimenti si pu� omettere questo file).


# Use of an external proxy can be turned on or off with this flag.
===postinst===
# Value should be either 0 (off) or 1 (on).
Usiamo direttamente quelli creati per i pacchetti dei temi presenti su http://www.bootsplash.org :
use_proxy=0
<pre>
#! /bin/sh
# postinst script for test
#
# see: dh_installdeb(1)


# External http proxy sometimes need authentication to get full access. The
set -e
# format is 'username:password'.
. /usr/share/debconf/confmodule
http_proxy_auth=proxyuser:proxypass


# Use of external proxy authentication can be turned on or off with this flag.
THEME_SUFFIX=<nometema>
# Value should be either 0 (off) or 1 (on).
use_proxy_auth=0


# Rate limiting sets the maximum bandwidth in bytes per second to use
# summary of how this script can be called:
# for fetching packages. Syntax is fully defined in 'man wget'.
#       * <postinst> `configure' <most-recently-configured-version>
# Use 'k' or 'm' to use kilobits or megabits / second: eg, 'limit=25k'.
#        * <old-postinst> `abort-upgrade' <new version>
# Use 0 or a negative value for no rate limiting.
#       * <conflictor's-postinst> `abort-remove' `in-favour' <package>
limit=0
#          <new-version>
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#         <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
#


# Debug mode makes apt-cacher spew a lot of extra debug junk to the
case "$1" in
# error log (whose location is defined with the 'logdir' directive).
    configure)
# Leave this off unless you need it, or your error log will get very
        db_register shared/bootsplash-theme bootsplash-theme-$THEME_SUFFIX
# big. Acceptable values are 0 or 1.
    ;;
debug=0


# Adapt the line in the usage info web page to match your server configuration
    abort-upgrade|abort-remove|abort-deconfigure)
# example_sources_line=deb&nbsp;http://<b>my.cacher.server:3142/</b>ftp.au.debian.org/debian&nbsp;unstable&nbsp;main&nbsp;contrib&nbsp;non-free
    ;;


# Print a 410 (Gone) HTTP message with the specified text when accessed via
    *)
# CGI. Useful to tell users to adapt their sources.list files when the
        gettext -s "postinst called with unknown argument \`$1'" >&2
# apt-cacher server is beeing relocated (via apt-get's error messages while
        exit 1
# running "update")
    ;;
#cgi_advise_to_use = Please use http://cacheserver:3142/ as apt-cacher access URL
esac
#cgi_advise_to_use = Server relocated. To change sources.list, run perl -pe "s,/apt-cacher\??,:3142," -i /etc/apt/sources.list


# Server mapping - this allows to hide real server names behind virtual paths
# dh_installdeb will replace this with shell code automatically
# that appear in the access URL. This method is known from apt-proxy. This is
# generated by other debhelper scripts.
# also the only method to use FTP access to the target hosts. The syntax is simple, the part of the beginning to replace, followed by a list
 
#of mirror urls, all space separated. Multiple profile are separated by semicolons
#DEBHELPER#
# path_map = debian ftp.uni-kl.de/pub/linux/debian ftp2.de.debian.org/debian ; ubuntu archive.ubuntu.com/ubuntu ;
#security security.debian.org/debian-security ftp2.de.debian.org/debian-security
# Note that you need to specify all target servers in the allowed_locations
# options if you make use of it. Also note that the paths should not overlap
# each other. FTP access method not supported yet, maybe in the future.
</pre>
Le opzioni più importanti sono
1) cache_dir che determina la directory in cui verrà salvata la cache <br>
2) allowed_hosts che specifica uno o più indirizzi a cui limitare l'accesso alla cache <br>
3) daemon_port che specifica la porta sulla quale ascolta apt-cacher <br>


==Client==
exit 0
Non è necessario installare apt-cacher sui client. Per accedere alla cache dovrete solo modificare il file
<pre>
/etc/apt/sources.list
</pre>
</pre>
inserendo una riga da del tipo
===postrm===
<pre>
<pre>
deb http://server_con_cache:porta/repository_da_utilizzare/debian [flavour] [sezioni]
#! /bin/sh
# postrm script for bootsplash-theme-newtux
#
# see: dh_installdeb(1)
 
set -e
 
# summary of how this script can be called:
#        * <postrm> `remove'
#        * <postrm> `purge'
#        * <old-postrm> `upgrade' <new-version>
#        * <new-postrm> `failed-upgrade' <old-version>
#        * <new-postrm> `abort-install'
#        * <new-postrm> `abort-install' <old-version>
#        * <new-postrm> `abort-upgrade' <old-version>
#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
 
# Theme variables
THEME_SUFFIX=<nometema>
 
 
case "$1" in
      remove)
 
        # This only applies to the remove process.
        # By default the directory of the theme under
        # /etc/bootsplash/themes will not be removed.
        # However, this postrm script will do this if
        # a directory exists.
        if [ -d /etc/bootsplash/themes/$THEME_SUFFIX ]
        then
                gettext -s "Deleting orphaned files under /etc/bootsplash/themes/$THEME_SUFFIX ... "
                rm -rf /etc/bootsplash/themes/$THEME_SUFFIX || gettext -s "ERROR: Couldn't delete directory /etc/bootsplash/themes/$THEME_SUFFIX."
        fi
        ;;
 
      purge|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
 
 
        ;;
 
    *)
        gettext -s "postrm called with unknown argument \`$1'" >&2
        exit 1
 
esac
# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.
 
# Automatically added by dh_installdebconf
if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then
        . /usr/share/debconf/confmodule
        db_purge
fi
# End automatically added section
 
 
exit 0
</pre>
</pre>
Chiariamo il concetto con un esempio. <br>
 
Supponiamo che il server abbia hostname computer e apt-cacher ascolti sulla porta 3142 (quella di default). Supponiamo poi che il repository utilizzato sia
===prerm===
<pre>
<pre>
deb http://ftp.it.debian.org/debian unstable main contrib non-free
#! /bin/sh
</pre>  
# prerm script for bootsplash-theme-debblue
La nuova riga da inserire per utilizzare la cache sarà
#
<pre>
# see: dh_installdeb(1)
deb http://computer:3142/ftp.it.debian.org/debian unstable main contriib non-free
 
set -e
. /usr/share/debconf/confmodule
 
# summary of how this script can be called:
#        * <prerm> `remove'
#        * <old-prerm> `upgrade' <new-version>
#        * <new-prerm> `failed-upgrade' <old-version>
#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
#        * <deconfigured's-prerm> `deconfigure' `in-favour'
#          <package-being-installed> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package
 
case "$1" in
    remove|upgrade|deconfigure)
        # I no longer claim this question.
        db_unregister shared/bootsplash-theme
        # See if the shared question still exists.
        if db_get shared/bootsplash-theme; then
                db_metaget shared/bootsplash-theme owners
                db_subst shared/bootsplash-theme choices $RET
                db_metaget shared/bootsplash-theme value
                if [ "<package>" = "$RET" ] ; then
                        db_fset shared/bootsplash-theme seen false
                        db_input high shared/bootsplash-theme || true
                        db_go || true
                fi
        fi
        ;;
 
    failed-upgrade)
        ;;
    *)
        gettext -s "prerm called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac
 
exit 0
</pre>
</pre>
Basterà poi salvare e lanciare un
 
=Compilazione=
La compilazione di un pacchetto � semplicissima: nella directory contenente i sorgenti diamo il seguente comando:
<pre>
<pre>
# apt-get update
$ dpkg-buildpackage
</pre>
</pre>
per cominciare ad utilizzare la cache. <br>
se tutto va a buon fine, verr� creato un pacchetto debian nella directory superiore.
Importante notare che tutte le righe dovranno presentare la dicitura deb http e non deb ftp.


==Importare Pacchetti==
=Test del pacchetto=
A questo punto siamo pronti per usare apt-cacher. Se però si hanno già a disposizione tanti pacchetti installati sul server e presenti nella directory
L'unico modo per testare il pacchetto � installarlo (dpkg -i pacchetto.deb) e riconfigurare il pacchetto bootsplash (dpkg-reconfigure bootsplash)... se tutto � stato fatto correttamente, nella lista apparir� il nuovo tema...
<pre>
 
/var/cache/apt/archives
=Conclusioni=
</pre>
La guida qui riportata � frutto dell'analisi dei pacchetti ''bootsplash-theme-*'' presenti nel repository di http://www.bootsplash.de ;)
potreste volerli importare nella cache. Niente di più semplice :)
 
Copiate tutti i pacchetti nella directory
[[Categoria:Apt]]
<pre>
[[Categoria:Apt-Dev]]
/var/cache/apt-cacher/import
</pre>
e poi lanciate il comando
<pre>
# /usr/share/apt-cacher/apt-cacher-import.pl
</pre>
che mette a disposizione tutti i pacchetti importati nella cache. <br>
Non resta che augurare happy caching! <br>
<br>
----
Autore: giorsat <br>
Esteso da: [[Utente:Sal|Sal]]