Rsync – Créer un miroir Ubuntu local

Suite à l’arrêt du support de l’outil ‘apt-mirror‘, j’ai dû trouver un solution alternative afin de maintenir à jour mon miroir local.

Avec l’arrivée d’Ubuntu 20.04 LTS, ‘apt-mirror‘ ne récupère pas correctement l’ensemble de l’arborescence du miroir et des paquets (.deb)

Donc solution alternative utiliser Rsync –> beaucoup plus gourmande en espace de stockage.

Coté Serveur

Pré-requis :

  • Serveur Ubuntu avec Apache2 (connu de votre DNS local)
  • Un accès SSH (avec privilèges sudo ou root)
  • Une (très bonne) connexion internet (pour la 1ère synchronisation)
  • Quelques connaissances des outils Linux Apache MySQL PHP (LAMP)
  • Savoir naviguer dans un système de fichier Linux en ligne de commande et connaitre les outils édition de texte (exemple : vim, nano etc..)
  • Savoir utiliser Advanced Packaging Tool (Apt)

Par habitude, j’héberge mes services dans /srv

Etape 1 – Création de l’arborescence :

Création de l’arborescence

root@serv1:/# mkdir /srv/mirror/ /srv/scripts/

Etape 2 – Création du « virtualhost » apache2 :

Création du « virtualhost » apache2 (à adapter selon votre environnement).

Pour exemple l’URL du miroir : http://mirror.home.lan/

root@serv1:/# vim /etc/apache2/sites-available/mirror.conf
<VirtualHost *:80>    
        ServerName mirror.home.lan
        DocumentRoot /srv/mirror/

        ErrorLog ${APACHE_LOG_DIR}/mirror-error.log
	CustomLog ${APACHE_LOG_DIR}/mirror-access.log combined
</VirtualHost>
root@serv1:/# a2ensite mirror.conf && service apache2 restart

Etape 3 – Récupération du script depuis GitHub :

Récupération du script depuis GitHub (à adapter selon votre environnement)

Attention : Prévoir un espace de stockage d’environ 1To –> on copiera une grande partie du miroir officiel)

Mon objectif : récupérer uniquement les paquets (.deb) les deux dernières versions LTS d’Ubuntu à savoir :

  • Focal (20.04)
  • Bionic (18.04)

Dans le script j’ai donc filtré et exclus certains dossiers, versions, sources à savoir :

  • indices
  • Project
  • dists/devel*
  • dists/eoan*
  • dists/precise*
  • dists/trusty*
  • dists/xenial*
  • *.diff.gz
  • *.tar.gz
  • *.tar.xz
  • *.dsc
root@serv1:/# cd /srv/scripts/
root@serv1:/# wget https://raw.githubusercontent.com/picardflo/fpicard.tech/master/Rsync_mirror/rsync_mirror.sh && wget https://raw.githubusercontent.com/picardflo/fpicard.tech/master/Rsync_mirror/exclusion-file && chmod +x rsync_mirror.sh

Exécutez le script (pour effectuer votre première synchronisation)

Attention : Selon votre connexion internet, le téléchargement va mettre plus ou moins d’heures voir de jours (limité à 30 Mbps -> en réponse à la demande des administrateurs du miroir FR)

Plus d’informations : http://fr.archive.ubuntu.com/

NB : L’option ‘–dry-run’ de Rsync est active dans le script, vous permettant de tester vos modifications, pensez à supprimer la ligne lorsque vous êtes prêt.

(..)

-n, –dry-run : perform a trial run with no changes made

(..)

https://linux.die.net/man/1/rsync
root@serv1:/# ./rsync_mirror.sh

Etape 4 – Crontab :

Croner votre script afin qu’il s’exécute régulièrement et maintienne à jour votre miroir (dans l’exemple toutes les 6:00)

Pour vous aider à créer vos taches Cron : https://crontab.guru/

root@serv1:/# crontab -e

Ajoutez :

0 */6 * * * /srv/scripts/rsync_mirror.sh

Coté Client

Éditez le fichier « sources.list »

root@ubuntu:/# vim /etc/apt/sources.list

Ajouter les chemins (URL) vers votre miroir

Exemple : client Ubuntu Desktop 20.04 LTS – Focal Fossa

#------------------------------------------------------------------------------#
#                            LOCAL UBUNTU REPOS                                #
#------------------------------------------------------------------------------#
#
###### Ubuntu Main Repos
deb http://mirror.home.lan/ focal main restricted universe multiverse 

###### Ubuntu Update Repos
deb http://mirror.home.lan/ focal-security main restricted universe multiverse 
deb http://mirror.home.lan/ focal-updates main restricted universe multiverse

Puis mettez à jour…

root@ubuntu:/# apt update