Outils personnels
Vous êtes ici : Accueil GNU / Linux Ubuntu Edgy Eft Développement et serveurs Création d'un mirroir Ubuntu local à l'aide de apt-mirror
Actions sur le document
  • Send this page to somebody
  • Print this page
  • Add Bookmarklet

Création d'un mirroir Ubuntu local à l'aide de apt-mirror

Par admin - Dernière modification 23/05/2007 10:58

apt-mirror est un outil permettant de créer facilement un mirroir de dépôt de paquets deb. Cet article vous explique point par point comment créer un mirroir local des dépôts Ubuntu les plus courants dans l'optique d'une Install Party (ou pour le fournir à une personne ayant une connexion internet ridiculement lente :D.... Oui, Jérôme, c'est de toi que je parle, sale bête).

Cet article présuppose que vous disposez d'au moins 20 Go d'espace disque libre dans votre dossier personnel. Pensez à vérifier à l'aide de la commande suivante :

df --si

Il présuppose aussi que le réseau local cible possède un routeur dont l'adresse IP est 192.168.1.1 et dont la fonction DHCP est désactivée.

Installation des logiciels nécessaires

Nous commençons par installer les logiciels dont nous nous servirons pour créer les dépôts :

sudo apt-get install apache2 bind dhcp apt-mirror

En détail :

  • bind : Nous utilisons Bind pour créer un serveur DNS personnalisé pour surcharger les noms de domaines des sites dont nous créons les mirroirs.
  • dhcp : Nous mettons en place un serveur DHCP pour fournir automatiquement des adresses IP (et par la même l'adresse de notre DNS personnalisé) à l'ensemble des ordinateurs du réseau local.
  • apache2 : Nous utilisons Apache 2 pour servir les fichiers de notre mirroir aux membres de notre réseau local.
  • apt-mirror : Ce logiciel est à la base de ce manuel. Il permet de créer simplement des miroirs Ubuntu et de les tenir à jour.

Création du mirroir

En premier lieu, nous créons un dossier MIRROR dans notre dossier personnel :

mkdir ~/MIRROR

Une fois ce dossier créé, nous stockons sont emplacement dans une variable d'environnement afin de pouvoir nous en servir par la suite :

export MIRROR_ROOT=~/MIRROR

Définissons pour quelle version d'Ubuntu nous souhaitons créer le miroir. Ici, nous créons un miroir pour Ubuntu Edgy Eft :

export MIRROR_DIST=edgy

Copions le spool d'apt-mirror dans ce dossier afin que nous ayons les droits de le modifier sans utiliser sudo :

cp -r /var/spool/apt-mirror $MIRROR_ROOT

Et nous y créons le fichier de configuration d'apt-mirror :

echo "# apt-mirror configuration file
##
## The default configuration options (uncomment and change to override)
##
#
set base_path    $MIRROR_ROOT/apt-mirror
set mirror_path $MIRROR_ROOT
set skel_path    \$base_path/skel
set var_path     \$base_path/var
#
# set defaultarch  <running host architecture>
# set nthreads     20
#

deb ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/ubuntu/ $MIRROR_DIST main
#deb-src ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/ubuntu/ $MIRROR_DIST main

deb http://fr.archive.ubuntu.com/ubuntu/ $MIRROR_DIST restricted
#deb-src http://fr.archive.ubuntu.com/ubuntu/ $MIRROR_DIST restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/ubuntu/ $MIRROR_DIST-updates main
#deb-src ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/ubuntu/ $MIRROR_DIST-updates main

deb http://fr.archive.ubuntu.com/ubuntu/ $MIRROR_DIST-updates restricted
#deb-src http://fr.archive.ubuntu.com/ubuntu/ $MIRROR_DIST-updates restricted

## Uncomment the following two lines to add software from the 'universe'
## repository.
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## universe WILL NOT receive any review or updates from the Ubuntu security
## team.
deb ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/ubuntu/ $MIRROR_DIST universe multiverse
#deb-src ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/ubuntu/ $MIRROR_DIST universe multiverse

## Uncomment the following two lines to add software from the 'backports'
## repository.
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
# deb ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/ubuntu/ $MIRROR_DIST-backports main restricted universe multiverse
# deb-src ftp://ftp.free.fr/mirrors/ftp.ubuntu.com/ubuntu/ $MIRROR_DIST-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu $MIRROR_DIST-security main
#deb-src http://security.ubuntu.com/ubuntu $MIRROR_DIST-security main restricted
deb http://security.ubuntu.com/ubuntu $MIRROR_DIST-security universe multiverse
#deb-src http://security.ubuntu.com/ubuntu $MIRROR_DIST-security universe multiverse

deb http://static.audacious-media-player.org/ubuntu $MIRROR_DIST main
deb http://repository.debuntu.org/ $MIRROR_DIST multiverse
deb http://medibuntu.sos-sts.com/repo/ $MIRROR_DIST free non-free
deb http://wine.budgetdedicated.com/apt $MIRROR_DIST main

##
## Cleaner configuration example
##
#
# set cleanscript $var_path/clean.sh
#

clean http://security.ubuntu.com/
clean ftp://ftp.free.fr/
clean http://fr.archive.ubuntu.com
clean http://static.audacious-media-player.org/ubuntu $MIRROR_DIST main
clean http://repository.debuntu.org/ $MIRROR_DIST multiverse
clean http://medibuntu.sos-sts.com/repo/ $MIRROR_DIST free non-free
clean http://wine.budgetdedicated.com/apt $MIRROR_DIST main
" > $MIRROR_ROOT/mirror.list

Vous pouvez bien sûr modifier ce fichier à votre convenance.

Attention : les lignes de sources sont commentées volontairement, car cela prendrait bien plus de 20 Go d'espace disque pour créer un miroir des sources des paquets.

Remarque : je me sert du miroir Ubuntu de Free car c'est mon fournisseur d'accès et que je pense que cela permet de maximiser l'utilisation de la bande passante. Je peut avoir tort sur ce point, et vous êtes bien sur libre de créer votre miroir à partir d'un autre dépôt.

Vous pouvez maintenant lancer la création de votre miroir Ubuntu :

apt-mirror $MIRROR_ROOT/mirror.list

Lorsque cette commande sera terminée, votre miroir sera complet. Pour information, il faut environ 24 heures avec une connexion Free 10 Mega pour créer un miroir des paquets binaires. Par la suite, il suffit de relancer cette commande régulièrement pour maintenir votre miroir à jour.

Configuration du serveur.

Pendant que le miroir est téléchargé, nous pouvons nous consacrer à la configuration des autres logiciels.

DHCP

La configuration du démon DHCP se fait simplement en exécutant la commande suivante :

sudo sh -c 'echo "subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.10 192.168.1.30;
option domain-name-servers $HOSTNAME.ubuntu.local;
option domain-name "ubuntu.local";
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;
option broadcast-address 192.168.1.255;
default-lease-time 600;
max-lease-time 7200;
}
" >> /etc/dhcpd.conf'

Normalement, une fois ceci fait, il suffit de redémarrer le démon :

sudo /etc/init.d/dhcp restart

Apache 2

La configuration d'Apache 2 se fait elle-aussi relativement simplement :

archive.ubuntu.com

sudo sh -c 'echo "<VirtualHost *:80>
ServerAdmin webmaster@landure.org

ServerName archive.ubuntu.com
ServerAlias *.archive.ubuntu.com

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>

DocumentRoot $MIRROR_ROOT/ftp.free.fr/mirrors/ftp.ubuntu.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory $MIRROR_ROOT/ftp.free.fr/mirrors/ftp.ubuntu.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

</VirtualHost>
" > /etc/apache2/sites-available/archive.ubuntu.com'
sudo ln -s /etc/apache2/sites-available/archive.ubuntu.com /etc/apache2/sites-enabled

medibuntu.sos-sts.com

sudo sh -c 'echo "<VirtualHost *:80>
ServerAdmin webmaster@landure.org

ServerName medibuntu.sos-sts.com

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>

DocumentRoot $MIRROR_ROOT/medibuntu.sos-sts.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory $MIRROR_ROOT/medibuntu.sos-sts.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

</VirtualHost>

" > /etc/apache2/sites-available/medibuntu.sos-sts.com'
sudo ln -s /etc/apache2/sites-available/medibuntu.sos-sts.com /etc/apache2/sites-enabled

repository.debuntu.org

sudo sh -c 'echo "<VirtualHost *:80>
ServerAdmin webmaster@landure.org

ServerName repository.debuntu.org

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>

DocumentRoot $MIRROR_ROOT/repository.debuntu.org
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory $MIRROR_ROOT/repository.debuntu.org>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

</VirtualHost>
" > /etc/apache2/sites-available/repository.debuntu.org'
sudo ln -s /etc/apache2/sites-available/repository.debuntu.org /etc/apache2/sites-enabled

security.ubuntu.com

sudo sh -c 'echo "<VirtualHost *:80>
ServerAdmin webmaster@landure.org

ServerName security.ubuntu.com

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>

DocumentRoot $MIRROR_ROOT/security.ubuntu.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory $MIRROR_ROOT/security.ubuntu.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

</VirtualHost>
" > /etc/apache2/sites-available/security.ubuntu.com'
sudo ln -s /etc/apache2/sites-available/security.ubuntu.com /etc/apache2/sites-enabled

static.audacious-media-player.org

sudo sh -c 'echo "<VirtualHost *:80>
ServerAdmin webmaster@landure.org

ServerName static.audacious-media-player.org

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>

DocumentRoot $MIRROR_ROOT/static.audacious-media-player.org
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory $MIRROR_ROOT/static.audacious-media-player.org>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

</VirtualHost>
" > /etc/apache2/sites-available/static.audacious-media-player.org'
sudo ln -s /etc/apache2/sites-available/static.audacious-media-player.org /etc/apache2/sites-enabled

wine.budgetdedicated.com

sudo sh -c 'echo "<VirtualHost *:80>
ServerAdmin webmaster@landure.org

ServerName wine.budgetdedicated.com

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>

DocumentRoot $MIRROR_ROOT/wine.budgetdedicated.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory $MIRROR_ROOT/wine.budgetdedicated.com>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>

</VirtualHost>
" > /etc/apache2/sites-available/wine.budgetdedicated.com'
sudo ln -s /etc/apache2/sites-available/wine.budgetdedicated.com /etc/apache2/sites-enabled

Il suffit maintenant de recharger la configuration d'Apache :

/etc/init.d/apache2 reload 

Bind

La configuration de Bind est assez complexe pour un non-initié, aussi vais-je faire en sorte de vous la simplifier au maximum. Copiez-collez encore plus bêtement que d'habitude.

Fichier db.192.168.1.

sudo sh -c 'echo "1.168.192.in-addr.arpa. IN SOA $HOSTNAME.ubuntu.local. root.localhost. ( 
1; Serial
10800; refresh after 3 hours.
3600; Retry after 1 hour.
604800; expire after 1 week.
86400; Minimum TTL of 1 day.
);

;
; Name servers declaration.
;

1.168.192.in-addr.arpa. IN NS $HOSTNAME.ubuntu.local.;

;
; Hostnames declaration.
;
2.1.168.192.in-addr.arpa. IN PTR $HOSTNAME.ubuntu.local.;
" > /etc/bind/db.192.168.1'

Fichier db.ubuntu.local.

sudo sh -c 'echo "ubuntu.local. IN SOA $HOSTNAME.ubuntu.local. root.localhost. (
1; Serial
10800; refresh after 3 hours.
3600; Retry after 1 hour.
604800; expire after 1 week.
86400; Minimum TTL of 1 day.
)

;
; Name servers declaration.
;

ubuntu.local. IN NS $HOSTNAME.ubuntu.local.;

;
; Hostnames declaration.
;
$HOSTNAME.ubuntu.local. IN A 192.168.1.2;
" > /etc/bind/db.ubuntu.local'

Fichier db.ubuntu.com.

sudo sh -c 'echo "ubuntu.com. IN SOA $HOSTNAME.ubuntu.local. root.localhost. (
1; Serial
10800; refresh after 3 hours.
3600; Retry after 1 hour.
604800; expire after 1 week.
86400; Minimum TTL of 1 day.
)

;
; Name servers declaration.
;

ubuntu.com. IN NS $HOSTNAME.ubuntu.local.;

;
; Hostnames declaration.
;
$HOSTNAME.ubuntu.com. IN A 192.168.1.2;
security.ubuntu.com. IN CNAME $HOSTNAME;
archive.ubuntu.com. IN CNAME $HOSTNAME;
fr.archive.ubuntu.com. IN CNAME $HOSTNAME;
" > /etc/bind/db.ubuntu.com'

Fichier db.budgetdedicated.com.

sudo sh -c 'echo "budgetdedicated.com. IN SOA $HOSTNAME.ubuntu.local. root.localhost. (
1; Serial
10800; refresh after 3 hours.
3600; Retry after 1 hour.
604800; expire after 1 week.
86400; Minimum TTL of 1 day.
)

;
; Name servers declaration.
;

budgetdedicated.com. IN NS $HOSTNAME.ubuntu.local.;

;
; Hostnames declaration.
;
$HOSTNAME.budgetdedicated.com. IN A 192.168.1.2;
wine.budgetdedicated.com. IN CNAME $HOSTNAME;
" > /etc/bind/db.budgetdedicated.com'

Fichier db.debuntu.org.

sudo sh -c 'echo "debuntu.org. IN SOA $HOSTNAME.ubuntu.local. root.localhost. (
1; Serial
10800; refresh after 3 hours.
3600; Retry after 1 hour.
604800; expire after 1 week.
86400; Minimum TTL of 1 day.
)

;
; Name servers declaration.
;

debuntu.org. IN NS $HOSTNAME.ubuntu.local.;

;
; Hostnames declaration.
;
$HOSTNAME.debuntu.org. IN A 192.168.1.2;
repository.debuntu.org. IN CNAME $HOSTNAME;
" > /etc/bind/db.debuntu.org'

Fichier db.sos-sts.com.

sudo sh -c 'echo "sos-sts.com. IN SOA $HOSTNAME.ubuntu.local. root.localhost. (
1; Serial
10800; refresh after 3 hours.
3600; Retry after 1 hour.
604800; expire after 1 week.
86400; Minimum TTL of 1 day.
)

;
; Name servers declaration.
;

sos-sts.com. IN NS $HOSTNAME.ubuntu.local.;

;
; Hostnames declaration.
;
$HOSTNAME.sos-sts.com. IN A 192.168.1.2;
medibuntu.sos-sts.com. IN CNAME $HOSTNAME;
" > /etc/bind/db.sos-sts.com'

Fichier db.audacious-media-player.org.

sudo sh -c 'echo "audacious-media-player.org. IN SOA $HOSTNAME.ubuntu.local. root.localhost. (
1; Serial
10800; refresh after 3 hours.
3600; Retry after 1 hour.
604800; expire after 1 week.
86400; Minimum TTL of 1 day.
)

;
; Name servers declaration.
;

audacious-media-player.org. IN NS $HOSTNAME.ubuntu.local.;

;
; Hostnames declaration.
;
$HOSTNAME.audacious-media-player.org. IN A 192.168.1.2;
static.audacious-media-player.org. IN CNAME $HOSTNAME;
" > /etc/bind/db.audacious-media-player.org'

Fichier named.conf.local.

sudo sh -c 'echo "zone \"1.168.192.in-addr.arpa\" in {
type master;
file \"/etc/bind/db.192.168.1\";
};

zone \"ubuntu.local\" in {
type master;
file \"/etc/bind/db.ubuntu.local\";
};

zone \"ubuntu.com\" in {
type master;
file \"/etc/bind/db.ubuntu.com\";
};

zone \"audacious-media-player.org\" in {
type master;
file \"/etc/bind/db.audacious-media-player.org\";
};

zone \"budgetdedicated.com\" in {
type master;
file \"/etc/bind/db.budgetdedicated.com\";
};

zone \"debuntu.org\" in {
type master;
file \"/etc/bind/db.debuntu.org\";
};

zone \"sos-sts.com\" in {
type master;
file \"/etc/bind/db.sos-sts.com\";
};
" >> /etc/bind/named.conf.local'

Fichier named.conf.options.

Enfin, nous utilisons OpenDNS comme forwarder pour récupèrer les autres adresses de l'Internet :

sudo sed -i -e '/^\};$/i\
forwarders { 208.67.222.222; 208.67.220.220; };' /etc/bind/named.conf.options

Enfin, nous pouvons redémarrer Bind :

sudo /etc/init.d/bind restart

Dernière étape

Une fois toutes les configurations terminées, et le téléchargement du miroir accompli, il vous faut fixer l'adresse IP de votre interface réseau :

  • Adresse IP : 192.168.1.2
  • Masque de sous-réseau : 255.255.255.0
  • Passerelle : 192.168.1.1
  • DNS : 192.168.1.2

Si tout s'est bien passé, vous disposez à présent d'un miroir Ubuntu fonctionnel.

Remerciements

Super tuto mais...

Posté par Jérôme le 01/07/2008 11:51
Hello,

bon le tuto est un peu vieux mais je voulais savoir si y'avait moyen de faire, sur la meme machine, deux serveur de dépot. Genre un pour les dépots ubuntu et un autre pour les dépots Xandros....

A votre avis ?

Merci pour votre aide

A priori

Posté par lwolf le 01/07/2008 12:28
A priori, oui, mais en faisant attention à la config du DNS.

Bon courrage


Réalisé avec Plone

Ce site respecte les normes suivantes :

Wikio