Curs: | DissenyXarxesLinux, |
Fitxers: | No hi ha fitxers |
Repositori SVN: | http://svn.projectes.lafarga.cat/svn/iceupc/DissenyXarxaLocalLinux |
Usuari: | anonymous |
Paraula de pas: | sense paraula de pas |
Autors: | Sergi Tur Badenas |
Cal tenir instal·lar rsync:
$ sudo apt-get install rsync
Normalment només cal tenir un disc dur amb prou espai (p.ex. a data --acacha 03:40, 15 abr 2011 (UTC) és necessiten uns 500G). Cal muntar el disc i fer el muntatge permanent al fitxer /etc/fstab
$ cat /etc/fstab # /etc/fstab: static file system information. # # Use 'blkid -o value -s UUID' to print the universally unique identifier # for a device; this may be used with UUID= as a more robust way to name # devices that works even if disks are added and removed. See fstab(5). # # <file system> <mount point> <type> <options> <dump> <pass> proc /proc proc defaults 0 0 /dev/mapper/servidor--web-root / ext4 errors=remount-ro 0 1 # /boot was on /dev/sda5 during installation UUID=557b7980-1bc3-4cf5-866a-a6d77a2b7269 /boot ext2 defaults 0 2 /dev/mapper/servidor--web-swap_1 none swap sw 0 0 /dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0 #Sergi Tur Disc dur de Tera amb el mirror d'Ubuntu /dev/sdb1 /mnt/sdb1 ext4 errors=remount-ro 0 3
No cal reiniciar per muntar-lo. Feu:
$ sudo mount -a
Ara cal configurar cron:
$ cat /etc/cron.d/update_mirror 0 2 * * * root rsync -a --progress --stats --delete-after --exclude="releases/" --exclude="UbuntuMirror.log" rsync://91.189.88.40/ubuntu /mnt/sdb1 /UbuntuMirror > /mnt/sdb1/UbuntuMirror/UbuntuMirror.log
Aquest sincronitza els repositoris. Ara el que sincronitza els releases:
#MAILTO=root 30 2 * * * root rsync -a --progress --stats --delete-after --exclude="UbuntuReleases.log" rsync://rsync.releases.ubuntu.com/releases /mnt/sdb1 /UbuntuMirror/releases > /mnt/sdb1/UbuntuMirror/releases/UbuntuReleases.log
Ara la configuració d'Apache
$ cat /etc/apache2/sites-available/releases.ubuntu.com
<VirtualHost *:80> ServerAdmin [email protected] ServerName releases.ubuntu.com DocumentRoot /mnt/sdb1/UbuntuMirror/releases ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/releases_ubuntu_com_error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/releases_ubuntu_com_access.log combined ServerSignature On </VirtualHost>
$ sudo cat /etc/apache2/conf.d/ubuntu.conf Alias /ubuntu /mnt/sdb1/UbuntuMirror <Directory /mnt/sdb1/UbuntuMirror> Options +Indexes </Directory>
Activeu el site i aplique els canvis a Apache:
$ sudo a2ensite releases.ubuntu.com $ sudo /etc/init.d/apache2 reload
Finalment s'han segrestat via DNS els noms de domini.
IMPORTANT: El següent script mostra com obtenir la IP a partir del nom de domini utilitzant un servidor de DNS concret (útil si estem segrestant DNS) i altres millores
NOTA: Té un problema, no tots els servidors de la llista poden ser utilitzats públicament, us pot sortir un missatge com el següent:
Welcome to the Ubuntu Master Archive mirror rsync server. This server is located in London, United Kingdom. If you are not an Ubuntu official country mirror, please consider using a Ubuntu archive mirror closer to your physical location. This server has limited resources. A list of Ubuntu archive mirrors which support rsync can be found here: https://launchpad.net/ubuntu/+archivemirrors If you host an Ubuntu mirror, public or privat e, please register your mirror in Launchpad if you have not already done so. Registrations can be made here: https://launchpad.net/ubuntu/+newmirror If you require assistance with your public mirror, please contact the Ubuntu mirror team at the following address: [email protected] -- ubuntu Ubuntu Archive
#!/bin/bash ARCHIVE_DOMAIN_NAME="archive.ubuntu.com" #OBTAIN archive.ubuntu.com IP ARCHIVE_UBUNTU_COM_IP="null" #By default we are using Telefonica DNS servers DNS_SERVER1="80.58.61.250" DNS_SERVER2="80.58.61.254" LOCAL_MIRROR_PATH="/mnt/sdb1/UbuntuMirror" LOG_FILE_NAME="UbuntuMirror.log" LOG_FILE_PATH="$LOCAL_MIRROR_PATH/$LOG_FILE_NAME" if [ -x /usr/bin/dig ]; then #DEBUG #echo "/usr/bin/dig +nocmd @$DNS_SERVER1 $ARCHIVE_DOMAIN_NAME A +noquestion +nostats +short" ARCHIVE_UBUNTU_COM_IP=$(/usr/bin/dig +nocmd @$DNS_SERVER1 $ARCHIVE_DOMAIN_NAME A +noquestion +nostats +short | head -n 1) else /usr/bin/apt-get install -y dnsutils fi if [ "$ARCHIVE_UBUNTU_COM_IP" = "null" ]; then echo "Fatal Error!. IP of domain $ARCHIVE_DOMAIN_NAME could not be retrieved." fi if [ -x /usr/bin/rsync ]; then #DEBUG echo "Executing /usr/bin/rsync -a --progress --stats --delete-after --exclude="releases/" --exclude="$LOG_FILE_NAME" rsync://$ARCHIVE_UBUNTU_COM_IP /usr/bin/rsync -a --progress --stats --delete-after --exclude="releases/" --exclude="$LOG_FILE_NAME" rsync://$ARCHIVE_UBUNTU_COM_IP $LOCAL_MIRROR_PA else /usr/bin/apt-get install -y rsync /usr/bin/rsync -a --progress --stats --delete-after --exclude="releases/" --exclude="$LOG_FILE_NAME" rsync://$ARCHIVE_UBUNTU_COM_IP $LOCAL_MIRROR_PA fi
Us col·loqueu a la carpeta on voleu fer el mirror i executeu:
$ cd $ mkdir UbuntuMirror $ rsync -a --progress --stats rsync://archive.ubuntu.com/ubuntu . receiving file list ... 351275 files to consider ....
A data (--acacha 06:44, 26 maig 2009 (UTC)) són un total de 235G aprox.
A data (--acacha 10:28, 31 oct 2009 (UTC)) són un total de 315G aprox.
A data (--acacha 12:23, 15 març 2011 (UTC)) són un total de 425G aprox.
NOTA: El primer cop no cal afegir delete. Després sí, si njo el vostre mirror local anirà creixent sense mesura:
rsync -a --progress --stats --delete-after rsync://fr.archive.ubuntu.com/ubuntu /media/disk2/UbuntuMirror > /home/sergi/backup/UbuntuMirror.log
Extret de la pàgina wiki d'ubuntu:
https://help.ubuntu.com/community/Rsyncmirror
NOTA: L'script no és correcte, té errors de sintaxi TODO
L'script:
## Mirror Synchronization Script /usr/local/bin/ubuntu-mirror-sync.sh ## Version 1.01 Updated 13 Feb 2007 by Peter Noble ## Point our log file to somewhere and setup our admin email log=/var/log/mirrorsync.log [email protected] # Set to 0 if you do not want to receive email sendemail=1 # Subject is the subject of our email subject="Ubuntu Mirror Sync Finished" ## Setup the server to mirror remote=rsync://archive.ubuntu.com/ubuntu ## Setup the local directory / Our mirror local=/media/mirror/ubuntu ## Initialize some other variables complete="false" failures=0 status=1 pid=$$ echo "`date +%x-%R` - $pid - Started Ubuntu Mirror Sync" >> $log while "$complete" != "true" ; do if $failures -gt 0 ; then ## Sleep for 5 minutes for sanity's sake ## The most common reason for a failure at this point ## is that the rsync server is handling too many concurrent connections. sleep 5m fi if $1 == "debug" ; then echo "Working on attempt number $failures" rsync -a --delete-after --progress $remote $local status=$? else rsync -a --delete-after $remote $local >> $log status=$? fi if $status -ne "0" ; then complete="false" (( failures += 1 )) else echo "`date +%x-%R` - $pid - Finished Ubuntu Mirror Sync" >> $log # Send the email if -x /usr/bin/mail && "$sendemail" -eq "1" ; then mail -s "$subject" "$adminmail" <<OUTMAIL Summary of Ubuntu Mirror Synchronization PID: $pid Failures: $failures Finish Time: `date` Sincerely, $HOSTNAME OUTMAIL fi complete="true" fi done exit 0
Primer cal escollir una hora a la que vulgueu fer la actualització. Normalment s'escull una hora de poc trànsit.
Suposem que escollim les 3 de la matinada. Aleshores heu de crear el fitxer /etc/cron.d/update_mirror:
$ sudo joe /etc/cron.d/update_mirror 0 3 * * * sergi rsync -a --progress --stats --delete-after rsync://91.189.88.40/ubuntu /media/disk2/UbuntuMirror > /home/sergi/backup/UbuntuMirror.log
on:
A l'exemple anterior es fa com un usuari concret (sergi) i si us fixeu és fa a les 3 de la nit i és genera un fitxer de log, millor si ho feu tot com a root:
$ sudo cat /etc/cron.d/update_mirror 0 3 * * * root rsync -a --progress --stats --delete-after rsync://91.189.88.40/ubuntu /mnt/sdb1/UbuntuMirror > /mnt/sdb1 /UbuntuMirror/UbuntuMirror.log
Vegeu també cron
IMPORTANT: Si utilitzeu eines com ninjabackup o similars per a fer còpies de seguretat tingueu en compte que potser no voldreu afegir la carpeta /var/www/ubuntu a les còpies ja que ocupa molt espai i no són dades pròpies
La opció més senzilla és instal·lar apache:
$ sudo apt-get install apache2
I crear un link a la carpeta /var/www:
$ cd /var/www $ sudo ln -s /home/sergi/UbuntuMirror ubuntu
Ara el mirror ja ha de poder ser accessible des de Internet amb:
http://LA_VOSTRA_IP/ubuntu
Per a més informació sobre Apache, consulteu l'article Apache.
Primer cal crear una carpeta on col·locar el mirror. Cal tenir en compte que es necessita molt espai:
$ sudo mkdir /mnt/DISC_DUR_IOMEGA/UBUNTU/releases.ubuntu.com
Si es vol fer un mirror de tot el servidor:
$ rsync -a --bwlimit=64 --progress rsync://releases.ubuntu.com/releases /mnt/DISC_DUR_IOMEGA/UBUNTU/releases.ubuntu.com/ubuntu
El servidor rsync és:
rsync://releases.ubuntu.com/releases o rsync://rsync.releases.ubuntu.com/releases
Si només és vol fer una versió:
$ rsync -rpLtgoD --bwlimit=64 --progress rsync://releases.ubuntu.com/releases/jaunty /mnt/DISC_DUR_IOMEGA/UBUNTU/releases.ubuntu.com/ubuntu
Amb --bwlimit=64 es limita la velocitat de descàrrega a 64Kbytes/s.
NOTA: Cal tenir en compte la opció -L (-rpltgoD equival a -a). Els fitxers iso no es troben realment a la carpeta intrepid sinó que són un enllaç a la carpeta ./.pool on estan totes les ISO. Amb -L, no copiem els enllaços sión que copiem el contingut dels enllaços.
Vegeu també: Servidor_DNS#Segrestar_algunes_dominis._Repositoris_Ubuntu
Cal configurar el servidor Bind amb quelcom similar a:
$ cat /etc/bind/guifi/db.releases.ubuntu.com $TTL 1H @ IN SOA releases.ubuntu.com. hostmaster ( 2011040301 ; serial 8H ; refresh for slaves 3H ; retry 4W ; expire time at slaves 1H ; negative TTL ) IN NS ns.releases.ubuntu.com. ;;;;;;;;;;;;;;;;;;;;;; ; Server with aliases ;;;;;;;;;;;;;;;;;;;;;; ns.releases.ubuntu.com. IN A 10.36.253.6 releases.ubuntu.com. IN A 10.36.253.6
On 10.36.253.6 és la vostra IP local on teniu el mirror.
També es recomanable configurar les DNS inverses:
A Apache cal posar un Virtual Host per al domini:
releases.ubuntu.com
Creeu el fitxer:
$ sudo joe /etc/apache2/sites-available/releases.ubuntu.com <VirtualHost *:80> ServerAdmin [email protected] ServerName releases.ubuntu.com DocumentRoot /mnt/sdb1/UbuntuMirror/releases ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ <Directory "/usr/lib/cgi-bin"> AllowOverride None Options ExecCGI -MultiViews +SymLinksIfOwnerMatch Order allow,deny Allow from all </Directory> ErrorLog /var/log/apache2/releases_ubuntu_com_error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel warn CustomLog /var/log/apache2/releases_ubuntu_com_access.log combined ServerSignature On </VirtualHost>
Apliqueu les canvis:
$ sudo a2ensite releases.ubuntu.com $ sudo /etc/init.d/apache2 reload
Cal anar a la web:
Utilitzant el paràmetre --stats:
Number of files: 427057 Number of files transferred: 981 Total file size: 319841607439 bytes Total transferred file size: 397195300 bytes Literal data: 217583957 bytes Matched data: 179611343 bytes File list size: 13934868 File list generation time: 46.293 seconds File list transfer time: 0.000 seconds Total bytes sent: 843718 Total bytes received: 232094003
Cal definir bé el site web d'Apache. Per exemple:
<Directory /mnt/sdb1/UbuntuMirror/openfpnet/customreleases> Options +Indexes +ExecCGI #403 Forbidden if activated #[Thu Nov 03 16:35:59 2011] [error] [client 127.0.0.1] Directory index forbidden by Options directive: /sdb1/customreleases/ #Options FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory>
Sobretot el AllowOverride All és important per tal que els fitxers .htaccess del repositori funcionin correctament.