CentOS and Apt-Cacher-NG
Somebody asked about an equivalent apt-cacher-ng
software package for CentOS. While I don’t deal with CentOS any more, professionally or personally, in a previous role as Linux Admin I configured apt-cacher-ng
to support CentOS. I claim no originality as the information is available online.
Caching Proxy Server
CentOS is designed to use a mirror list to update packages. The intent is to distribute the download demand across different upstream CentOS servers. This CentOS default does not work well with the caching proxy server because commonly CentOS systems are configured to use mirrors and commonly each individual CentOS system will choose a different mirror. The result is package downloads are duplicated, thereby defeating the purpose of the caching proxy server. To obtain a list of all current CentOS mirrors:
wget https://www.centos.org/download/full-mirrorlist.csv | sed ’s/^.*"http:/http:/’ | sed ’s/.”*$//’ | grep ^http > /etc/apt-cacher-ng/centos_mirrors
Generally this CSV file is downloaded to the caching proxy server at /etc/apt-cacher-ng/centos_mirrors
. The caching proxy server is then configured to use this CSV list. This CSV file is useful as a starting template, but in the end only one server is desired. Edit the CSV list to comment out all servers except one.
The /etc/apt-cacher-ng/acng.conf
file needs the following modifications to cache CentOS package requests:
# Allow volatile short caching of results and GPG key retrievals: VfilePatternEx: ^(/\?release[0-9]+&arch.*|.*/RPM-GPG-KEY-examplevendor)$ # Add a remap directive: Remap-centos: file:centos_mirrors /centos # Allow SSL pass through: PassThroughPattern: (mirrors\.fedoraproject\.org|some\.other\.repo|yet\.another\.repo):443
Any time there are changes to the apt-cacher-ng configuration the service must be restarted:
systemctl restart apt-cacher-ng.service
Client Systems
Three configuration options are required.
In /etc/yum/pluginconf.d/fastestmirror.conf
, disable the yum fastest mirror plugin:
[main] enabled=0
In /etc/yum.conf
, add the caching proxy URL
[main] proxy=http://some_local_proxy_server_ip_address:3142
in /etc/yum.repos.d/CentOS-Base.repo
, disable using the built-in mirror system and explicitly update only from a specific server:
[base] #mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra baseurl=http://centos.mirrors.tds.net/centos/$releasever/os/$basearch/
Before updating any CentOS system using the caching proxy server, delete the package cache data:
yum clean expire-cache
The example shows centos.mirrors.tds.net
, but choose an optimal regional server.
Posted: Usability Tagged: CentOS
Category:Next: Reducing Computer Fatigue
Previous: Configuring Clementine with LIRC