Softpedia
 

NEWS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
Home > News > Linux > Ubuntu Tips and Tricks

February 1st, 2007, 10:23 GMT · By Mihai Marinof

Create a LAN Repository with Apt-Cacher

SHARE:

Adjust text size:


Every bit of software on a Linux system needs to be as up to date as possible. It's the best practice against hackers and other security related risks. Sometimes, updates also add functionality and improve the stability of programs. On Ubuntu systems, the update process is completed through APT (Advanced Packaging Tool), which is a package management system initially made for Debian Linux and later used by its derivatives as well. Once the update command has been executed, APT will download the latest version of the installed packages, from an official repository.

However, if you have a local network of computers running the same distribution, you'll need to think about setting a repository cache on your network so that once an updated package is downloaded from an official repository, all other machines will download it from a local server. This way, common packages won't be downloaded more than once from official repositories, the rest of the computers will download their updates at maximum speed (LAN) and your Internet bandwidth will be saved.

If this is your situation as well, here is what you'll need to do. First, you need to configure a local machine to act as a repository cache, while the rest of the local computers will use it as a repository.

Installing Apt-Cacher

- Run the following command on the local machine that will act as a repository cache:
CODE
sudo apt-get
install apt-cacher

- Ignore the error about not being able to start apt-cacher.

Configuring Apt-Cacher

- Open /etc/apt-cacher/apt-cacher.conf with your favorite text editor and set it according to your needs. Every directive is explained in detail so there's no need for me to explain them here.

- Activate Apt-Cacher: open /etc/default/apt-cacher with your favorite text editor and set AUTOSTART to 1. This will also start Apt-Cacher on each system boot.

- Restart Apt-Cacher:
CODE
sudo /etc/init.d/apt-cacher restart

Setting up the LAN clients

- You now have to edit the file /etc/apt/sources.list on every computer on the network so they will use the local repository-cache machine, not the Internet official repository. To do that, open the sources.list file and edit it to look like this:
CODE
#ubuntu main repository
deb http://10.10.0.1:3142/archive.ubuntu.com/ubuntu/ edgy main restricted
deb-src http://10.10.0.1:3142/archive.ubuntu.com/ubuntu/ edgy main restricted

#ubuntu updates repository
deb http://10.10.0.1:3142/archive.ubuntu.com/ubuntu/ edgy-updates main restricted
deb-src http://10.10.0.1:3142/archive.ubuntu.com/ubuntu/ edgy-updates main restricted

#ubuntu security updates repository
deb http://10.10.0.1:3142/security.ubuntu.com/ubuntu edgy-security main restricted
deb-src http://10.10.0.1:3142/security.ubuntu.com/ubuntu edgy-security main restricted

NOTE: The IP 10.10.0.1 is an EXAMPLE. Replace it with the correct IP address of the machine running apt-cacher. Moreover, if you have more entries in your source.list, you need to prefix each one with the local IP of the machine running apt-cacher and the specified port.

- More examples:
CODE
deb http://archive.ubuntu.com/ubuntu/ edgy universe
deb-src http://archive.ubuntu.com/ubuntu/ edgy universe

becomes:
CODE
deb http://10.10.0.109:3142/ro.archive.ubuntu.com/ubuntu/ edgy universe
deb-src http://10.10.0.109:3142/ro.archive.ubuntu.com/ubuntu/ edgy universe

- Now that everything is set, you need to resynchronize the package index files from their sources. To do this, run the command:
CODE
sudo apt-get update

Automatically update systems every day

- Create a file called auto-update.sh in /usr/bin:
CODE
sudo touch /usr/bin/auto-update.sh

- Change its permissions to root:
CODE
sudo chmod 700 /usr/bin/auto-update.sh
sudo chown root.root /usr/bin/auto-update.sh

- Open the file /usr/bin/auto-update.sh with your favorite directory and add the following code:
CODE
#!/bin/bash

touch /var/log/auto-update.log

apt-get clean > /dev/null
apt-get autoclean > /dev/null

apt-get update >> /var/log/auto-update.log

apt-get -y upgrade >> /var/log/auto-update.log

exit


- Execute the following command to edit the crontab for user root:
CODE
sudo crontab -e

- A text editor will be opened and you'll need to add the following line AT THE END so the script will be executed every day at 14:30:
CODE
30 14 * * * /usr/bin/auto_update.sh > /dev/null

Generating reports

- Set the generate_reports directive to 1 in /etc/apt-cacher/apt-cacher.conf.
- The report is generated once a day, but if you need it at a certain time, you can force it by running:
CODE
sudo /usr/share/apt-cacher/apt-cacher-report.pl
- Check out the reports at: http://local.machine.running.apt-cache:3142/report .

TELL US WHAT YOU THINK:

14,847 hits · 5 comments · Link to this article · Print article · Send to friend · Subscribe to news

MUST-READ RELATED ARTICLES:


Manage Several Desktops with One Keyboard

Automated Remote Back-ups with rdiff-backup

Mounting Remote Directories through SSH

Installing Lighttpd on Fedora and Ubuntu

GNU Screen Tutorial

READER COMMENTS:


Comment #1 by: koolneze on 26 Jan 2009, 00:46 UTC reply to this comment

Hi
Thanks for the HOWTO, but I'm stuck at this.
Ign http://192.168.1.101 intrepid-security/universe Packages
Ign http://192.168.1.101 intrepid-security/universe Sources
Ign http://192.168.1.101 intrepid-security/multiverse Packages
Ign http://192.168.1.101 intrepid-security/multiverse Sources
Err http://192.168.1.101 intrepid/main Packages
502 apt-cacher: libcurl error: Couldn't resolve host 'ubuntu'
Err http://192.168.1.101 intrepid/restricted Packages
502 apt-cacher: libcurl error: Couldn't resolve host 'ubuntu'
Err http://192.168.1.101 intrepid/main Sources
502 apt-cacher: libcurl error: Couldn't resolve host 'ubuntu'
Err http://192.168.1.101 intrepid/restricted Sources
502 apt-cacher: libcurl error: Couldn't resolve host 'ubuntu'


what are the reasons for this and how could I rectify this.

Thanks before hand

Eagerly waiting for your help

Comment #1.1 by: GB on 18 Feb 2009, 18:42 GMT

Check your /etc/hosts file. ie:

sudo nano /etc/hosts

It should look something like:

127.0.0.1 localhost
127.0.1.1 ubuntu

If not, make it so.


Comment #2 by: Skip Da Shu on 29 May 2009, 02:47 UTC reply to this comment

You don't need to modify the sources.list.

Just add a file at /etc/apt/apt.conf.d/01proxy on each client with this in it:

Acquire::http::Proxy "http://192.168.urapt.cacherip:3142";

On the machine running apt-cacher (the server) add the same file but with the following line in it so that it also goes to the cache first.

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

Also you can accomplish the clean functions with this a file called "clean" added to the same /etc/apt/apt.conf.d/

To clean the local cache that file should contain:

DPkg::Post-Invoke {"/bin/rm -f /var/cache/apt/archives/*.deb || true";};

There's also an option in Synaptic that should be checked
Settings -> files tab -> select "Delete downloaded packages after install"

Comment #2.1 by: wammz on 02 Jun 2011, 07:39 GMT

Hi,may u confirm that by Acquire::http::Proxy "http://192.168.urapt.cacherip:3142";
u mean something like this: Acquire::http::Proxy "http://192.168.1.7:3142";


Comment #3 by: Avin on 25 Jan 2011, 11:52 UTC reply to this comment

Can I use this steps to cache package on Ubuntu 10.04 LTS server edition (64-bit). My Clients has 32bit Ubuntu-10.04 LTS.

Copyright © 2001-2012 Softpedia. Contact/Tip us at

WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM