Setup Debian or Ubuntu Mirror

From banana_wiki
Jump to: navigation, search

Running a local mirror can be very beneficial if there are several servers on the local network requiring access to the same repo of software for installing and for updating. There are several ways to mirror apt repos this tutorial just shows one, simple way to do so. This tutorial only covers apt based distribution and their repos.

In this tutorial I will be using debian stable (wheezy at the time of writing) for other apt distros just substitute the debian specifics for the other’s.

Installing needed software

First and foremost on a apt based server we need to install the required software for running a mirror.

apt-get update
apt-get install apt-mirror apache2

Configuring apt-mirror

nano /etc/apt/mirror.list
root@mirror:~# cat /etc/apt/mirror.list
############# config ##################
#
# set base_path    /var/spool/apt-mirror
#
# set mirror_path  $base_path/mirror
# set skel_path    $base_path/skel
# set var_path     $base_path/var
# set cleanscript $var_path/clean.sh
# set defaultarch  <running host architecture>
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

deb http://ftp.us.debian.org/debian stable main contrib non-free
#deb-src http://ftp.us.debian.org/debian unstable main contrib non-free

# mirror additional architectures
#deb-alpha http://ftp.us.debian.org/debian unstable main contrib non-free
deb-amd64 http://ftp.us.debian.org/debian stable main contrib non-free
#deb-armel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-hppa http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-i386 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-ia64 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-m68k http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mips http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mipsel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-powerpc http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-s390 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-sparc http://ftp.us.debian.org/debian unstable main contrib non-free

clean http://ftp.us.debian.org/debian

Note the uncommented line, to add more architectures just uncomment the other lines.

Running a mirror

Now everything is all configured, we need to run the actual mirror process. This may take a long time as repos are fairly large. The one repo we have selected in our config is about 44Gb.

su - apt-mirror -c apt-mirror

This command switches you as the apt-mirror user and then runs apt-mirror.

Cleaning the mirror

Every so often apt-mirror will tell you to clean up the repo. This can be done as follows.

/bin/bash /var/spool/apt-mirror/var/clean.sh

Automating the mirroring

Now changes do occur to the repos so we want the mirror to regularly check and download changes to the repo. To do that we will use cron.

/etc/cron.d/apt-mirror

And uncomment the already existing line.

Serving the mirror

Earlier you recall we installed apache2, the http daemon. This will serve the mirror to our other servers. To do so we just need to add some things to the already existing default www document root. The apache config can be adjusted but does not need to for this mirror to work.

Make the folder servable

ln -s /var/spool/apt-mirror/mirror/ftp.us.debian.org/debian /var/www/debian

Also since debian also uses release names we want to link stable to wheezy in case we want to use wheezy instead of stable in the clients apt sources.

cd /var/spool/apt-mirror/mirror/ftp.us.debian.org/debian/dists
ln -s stable/ wheezy

//Note: when the next stable version comes out, we need to remember to delete wheezy and relink to the new name.//

Using the mirror on new and existing installs

On existing systems

On an existing debian stable system we just have to open the apt sources file and adjust it to point to our mirror.

nano /etc/apt/sources.list

And change:

deb http://ftp.debian.org/debian wheezy main contrib non-free

to

deb http://192.168.0.22/debian wheezy main contrib non-free
apt-get update

During new install

During a fresh install we just have to specify our own mirror server when the installer asks for which mirror we would like to use. Demonstrated in the screenshots below.

2.png

3.png

4.png