/ Markus Amersdorfer:home / university / about:me /
\ capsaicin - my blog on growing chilis \


How to set up a Debian mirror

If you have a network full of Debian machines and are steadily installing new ones, it is great to have Debian "in house". This is what I wanted, so I set up my own in-house Debian mirror...
The initial solution was based on miscellaneous mirroring scripts. Nevertheless, since the advent of Debian Sarge comes close, usage of this tree is more and more interesting. Besides lots of great improvements, it also offers debmirror, which makes creating a partial Debian mirror really easy. I'm mirroring Debian Woody and Sarge as well as the corresponding Security repositories (i386 only, no source packages), and this takes about 14 GB space currently (04-12-15).

Remember: It's fine to set up a private mirror for security.debian.org, but keep it private! Do not advertise the mirrored security-branch.

So, here's how to get the mirror working...

  1. Add a special user: I added a special user "mirrorer" in order not to run the updating-processes as root or similar.

  2. The shell script running "debmirror": This is a simple shell script basically holding three debmirror-commands only:

    #!/bin/bash
    
    ## 
    ## Security:
    ##
    echo
    echo "`basename $0`: Upgrading Debian security repository ..."
    debmirror \
      /data/debian-mirrors/debian-security/ \
      -p \
      --nosource \
      --host=security.debian.org \
      --root=debian-security/ \
      --method=http \
      --arch=i386 \
      --section=main,contrib,non-free \
      --dist=woody/updates,sarge/updates
    echo "`basename $0`: Upgrading Debian security repository: Done."
    
    ## 
    ## Non-US:
    ##
    echo
    echo "`basename $0`: Upgrading Debian Non-US repository ..."
    debmirror \
      /data/debian-mirrors/debian-non-US/ \
      -p \
      --nosource \
      --host=ftp.de.debian.org \
      --root=debian-non-US \
      --method=http \
      --arch=i386 \
      --section=main,contrib,non-free \
      --dist=woody/non-US,sarge/non-US
    echo "`basename $0`: Upgrading Debian Non-US repository: Done."
    
    ## 
    ## Default:
    ##
    echo
    echo "`basename $0`: Upgrading Debian default repository ..."
    debmirror \
      /data/debian-mirrors/debian/ \
      -p \
      --nosource \
      --host=ftp.de.debian.org \
      --root=debian \
      --method=http \
      --arch=i386 \
      --section=main,contrib,non-free \
      --dist=woody,sarge 
    echo "`basename $0`: Upgrading Debian default repository: Done."
    
  3. Add a cron-job: Something like "42 2 * * * mirrorer /home/mirrorer/mirror-debian" added to /etc/crontab and reloading cron should do fine.

  4. Set up your webserver: Using Apache2, this boils down to adding a new virtual domain by creating the file /etc/apache2/sites-available/debian.yourdomain.com (and a corresponding sym-link to it from sites-enabled/), with a content such as:

    # make the Debian mirror available internally only
    <Directory /data/debian-mirrors>
       Order deny,allow
       deny from all
       allow from .yourdomain.com
    </Directory>
    
    # and here's the virtual-host definition
    <VirtualHost *>
       ServerName debian.yourdomain.com
       DocumentRoot /data/debian-mirrors/
    
       ServerAdmin webmaster@yourdomain.com
       CustomLog /var/log/apache2/debian.yourdomain.com-access.log combined
       ErrorLog /var/log/apache2/debian.yourdomain.com-error.log
    </VirtualHost>
    
  5. Adapt your clients' /etc/apt/sources.list:

      ## Replace "woody" with "sarge" as needed ...
      deb http://debian.yourdomain.com/debian woody main contrib non-free
      deb http://debian.yourdomain.com/debian-non-US woody/non-US main contrib non-free
      deb http://debian.yourdomain.com/debian-security woody/updates main contrib non-free
    
back to Debian

Valid XHTML 1.0 Strict Valid CSS! Created with Vim [Blue Ribbon Campaign icon]
© Markus Amersdorfer
last modified: 2010-02-23 15:51:29
6543 hits