Apt Cache Proxy

I face bandwidth caps. For years I have maintained a local mirror of the Slackware repositories to keep all of my Slackware systems updated. As the Slackware repos are small compared to other distros, this works well through some cron jobs.

I started using Ubuntu MATE 16.04 immediately after the official release. Currently I manage five systems using the distro.

I wrote a shell script to keep packages synced between my main server and each 16.04 system. I 1) update one of the Ubuntu systems when I receive an Update Notifier prompt, 2) sync the apt cache to my LAN server, then 3) the next time I use another 16.04 system I sync the apt cache from the server and update.

All doable but clunky. Especially as one of the systems is isolated on a VLAN, which requires me to play sneaker net on a USB flash drive to save bandwidth.

The Ubuntu repos contain 30,000 packages or more. I do not want to maintain a local mirror. Instead I want to create an apt caching proxy server for the Ubuntu MATE systems in the LAN.

I used apt-cacher-ng. I created the apt caching proxy server virtual machine (VM) on my office desktop. I needed to manually start the proxy server VM, but the proxy worked nicely to save me bandwidth.

To conserve VM space I configured the apt caching proxy to use my LAN server to store the apt cache.

Running the apt caching proxy as a VM required some configuration thought.

The LAN server is not on 24/7. Through a cron job the server powers down during the night when there is no LAN activity. The server powers on at a set time or is awakened by any client on the LAN through wake-on-lan.

Auto starting the apt caching proxy VM when the server boots means gracefully powering down the VM or saving the state.

I wrote a graceful VM shutdown script for another person. I tweaked that script for my use.

I use a safe-shutdown script to power down the LAN server. The LAN server runs Slackware. There is no systemd monkey business. Simple init scripts. Everything on the server is configured to use the safe-shutdown script. I updated the safe-shutdown script to run the VM shutdown script to gracefully power down or save the state of the apt caching proxy server.

I want to keep the VM small in size. From the server I used NFS to export an Ubuntu apt cache directory. The VM mounts that location as the caching directory.

I use static IP address on the LAN. I manually configured the networking on the VM. No NetworkManager.

I never ran a VM on the LAN server. All of my existing VMs are installed on my office desktop. I installed and tested the apt caching proxy on the office system. Then moved the VM to the LAN server.

I started with the Ubuntu Server 32-bit ISO. I created a VM with a 3 GB drive and 1 GB RAM.

Tinkering with the Ubuntu Server ISO revealed too much overhead for an apt caching proxy server. I started from scratch using the Ubuntu mini ISO.

After installing I reduced the RAM to 64 MB. The system would not boot. I settled for 144 MB, which at idle is way too much when the system uses about 20 MB.

I do not understand the design decision forcing users to use a PAE enabled CPU on a 32-bit system. PAE is needed only to support more than 3 GB of RAM. Most 32-bit users likely will have main boards that physically do not support more than 1 or 2 GB of RAM. Most people using 32-bit are not focused on large footprint RAM systems.

A simple apt caching server should be fine with 64 MB of RAM or even 32 MB. Nonetheless I settled for the 144 MB footprint. The 3 GB dynamic drive size seems just about right, with my configuration using about 76% capacity.

The default proxy cache location is /var/cache/apt-cacher-ng. My NFS export from my server is /home/public. In that directory I already had /home/public/ubuntu, which I had been using to keep all Ubuntu systems updated. I created /home/public/ubuntu/apt-cacher-ng. I modified the apt-cacher-ng config files for this new location as well as updating /etc/fstab to mount the server NFS export.

I have the apt caching proxy server configured to use bridged networking and is a member of the LAN subnet. That allows me to view the proxy server caching results web page (port 3142). For a couple of weeks I used the VM on my office desktop in this manner with no problems. I manually started the VM when I wanted to update the Ubuntu systems.

I configured the proxy VM to auto-update security packages.

The proxy server worked fine on my office desktop. Next is to move the VM to my server.

Posted: Category: Usability Tagged: Ubuntu, Virtual Machines

Next: Autostarting VirtualBox Virtual Machines

Previous: Buzzword of the Day — Passion