this is obsolete doc -- see http://doc.nethence.com/ instead

Setting up a Debian / Ubuntu mirror 

 

Update: apt-cacher-ng might be a better solution unless you really need a full mirror 

 

apt-cacher-ng 

Note. -ng is written in C++ and also has some improvements over apt-cacher which is in Perl. 

 

Install the shit and no need to configure it, 

apt install apt-cacher-ng 

grep var /etc/apt-cacher-ng/acng.conf 

cd /var/cache/ 

ls -ld apt-cacher-ng 

touch apt-cacher-ng/NOT_MOUNTED 

cat >> /etc/fstab <<EOF 

/dev/mapper/cachervg-cacherlv /var/cache/apt-cacher-ng ext4 defaults 0 2 

EOF 

mount /var/cache/apt-cacher-ng/ 

grep apt /etc/passwd 

grep apt /etc/group 

chown apt-cacher-ng:apt-cacher-ng /var/cache/apt-cacher-ng/ 

/etc/init.d/apt-cacher-ng restart 

ls -ld /var/cache/apt-cacher-ng/ 

ls -al /var/cache/apt-cacher-ng/ 

check, 

  /etc/init.d/apt-cacher-ng status 

  netstat -an --inet --inet6 | grep 3142 

 

Setup clients, 

cd /etc/apt/apt.conf.d/ 

vi 01proxy 

Acquire::http::Proxy "http://cacher:3142"; 

 

Eventually add this script to daily crontabs, to check for space usage, 

  df -h /boot / /var/cache/apt-cacher-ng 

 

apt-mirror 

You need a debian or ubuntu system to use apt-mirror. 

 

To create a repository mirror for Ubuntu 15.10 (wily), 

apt-get install apt-mirror 

apt-get install bozohttpd 

grep ^www /etc/inetd.conf 

netstat -an --inet --inet6 | grep LISTEN 

cd /var/www/ 

mkdir ubuntu_mirror/ 

ln -s ubuntu_mirror/mirror/fr.archive.ubuntu.com/ubuntu 

cd /etc/apt/ 

cp mirror.list mirror.list.dist 

vi mirror.list 

:%s/archive/fr.archive/g 

set base_path /var/www/ubuntu_mirror 

set defaultarch amd64 

set nthreads 20 

set limit_rate 40k 

deb-amd64 http://fr.archive.ubuntu.com/ubuntu wily main main/debian-installer restricted restricted/debian-installer universe multiverse 

deb-amd64 http://fr.archive.ubuntu.com/ubuntu wily-security main restricted universe multiverse 

deb-amd64 http://fr.archive.ubuntu.com/ubuntu wily-updates main restricted universe multiverse 

clean http://fr.archive.ubuntu.com/ubuntu 

cd /var/www/ 

apt-mirror 

Refs. 

http://askubuntu.com/questions/692364/how-to-limit-network-bandwidth-apt-mirror 

https://serverfault.com/questions/88780/how-can-i-limit-the-bandwidth-of-apt-mirror 

http://askubuntu.com/questions/500167/install-ubuntu-14-04-with-pxe-using-local-repository 

 

Once the mirror is in place enable the cron job, 

cd /etc/cron.daily/ 

vi custom_apt-mirror 

#!/bin/sh 

/usr/bin/apt-mirror 

chmod +x custom_apt-mirror 

 

Troubleshooting 

If you get this error when the mirroring is done, 

  /bin/sh: 0: Can't open /var/www/ubuntu_mirror/var/postmirror.sh 

create the postmirror script as shown below, 

cd /var/www/ubuntu_mirror/var/ 

vi postmirror.sh 

#!/bin/sh 

/var/www/ubuntu_mirror/var/clean.sh 

#rsync -avz --bwlimit=512 rsync://fr.archive.ubuntu.com/ubuntu/dists/wily/main/installer-amd64 /var/www/ 

rsync -avz --bwlimit=512 rsync://de.archive.ubuntu.com/ubuntu/dists/wily/main/installer-amd64 /var/www/ 

chmod +x postmirror.sh 

Note. you cannot put installer-amd64 into the mirror otherwise it will get wiped out by clean.sh. 

 

Refs. 

https://github.com/apt-mirror/apt-mirror/blob/master/postmirror.sh 

https://help.ubuntu.com/community/Rsyncmirror