{"id":1205,"date":"2018-11-08T21:47:58","date_gmt":"2018-11-08T18:47:58","guid":{"rendered":"http:\/\/kifarunix.com\/?p=1205"},"modified":"2020-09-09T20:04:47","modified_gmt":"2020-09-09T17:04:47","slug":"how-to-setup-apt-caching-server-using-apt-cacher-ng-on-ubuntu-18-04","status":"publish","type":"post","link":"https:\/\/kifarunix.com\/how-to-setup-apt-caching-server-using-apt-cacher-ng-on-ubuntu-18-04\/","title":{"rendered":"How to Setup APT-Caching Server Using Apt-Cacher NG on Ubuntu 18.04"},"content":{"rendered":"
Good day all. Welcome to our guide on how to set up apt-caching server using Apt-Cacher NG on Ubuntu 18.04 server. Well, so what is Apt-Cacher NG<\/span>?<\/p>\n Apt-Cacher NG<\/span> is special caching proxy for Debian based distributions that creates a local cache of Debian-based mirrors as well as other Linux distributions. This means that whenever a package is pulled from the official repositories, an APT Cache server caches them such that if any other local machine would want to install the same package, it just pulls it from the local caching server. This helps eliminates the bottlenecks of slow internet connections.<\/p>\n Some of the features of Apt-Cacher NG<\/span> include;<\/p>\n Since Apt-Cacher NG<\/span> is available on the default Ubuntu repositories by default, you can install it using the package manager as shown below;<\/p>\n Apt-Cacher NG starts automatically by default after the installation. You can verify the same by running the command below; It is also enabled to run on system reboot;<\/p>\n Apt-Cacher NG comes installed with a web server that enables it to proxy the HTTP package downloads. The web server can also be used to perform other tasks administrative tasks such as reporting. Apt-Cacher NG<\/span> also listens on port 3142\/TCP by default. Therefore, if UFW is running, open this port.<\/p>\n To verify that your Apt-Cacher is working fine, just navigate to your browser and enter the URL in the format, http:\/\/<hostname or IP>:3142\/apt-cacher<\/strong><\/p>\n The main configuration file for Apt-Cacher NG<\/span> is located at \/etc\/apt-cacher-ng\/acng.conf<\/strong>. The file is highly commented and in most cases, it can just run with the default parameters.<\/p>\n Basically, the following are the some of the parameters that are enabled by default in the Apt-Cacher NG configuration file.<\/span><\/p>\n In order to serve HTPPS repositories, you need to configure HTPPS connection tunneling through the Apt-Cacher proxy by uncommenting the line, Note, whenever you make any configuration changes, you need to restart apt-cacher-ng<\/tt> in order for the changes to take effect by running the command;<\/p>\n As a security measure, you need to define hosts that are only allowed to download packages via the Apt-Cacher. Apt-Cache-ng supports Access Control Lists using TCP wrappers. Therefore, you can use the For example;<\/p>\n To allow host 192.168.1.17 and all hosts on the network 192.168.43.0\/24 to use Apt-Cacher server, put the following line in To block all hosts on the network 192.168.43.0\/24 except the host 192.168.43.27;<\/p>\n Once you are done customizing your Apt-Cacher server configurations, you need to configure your clients so that they do package installation via the Apt-Cacher server.<\/p>\n There are two ways in which clients can be configured to download packages through the Apt-Cacher.<\/p>\n Where 192.168.43.17<\/strong> is your cache server IP address.<\/p>\n The first method is more convenient as compared to the second method.<\/p>\n To verify this, login to your client and configure it as shown below;<\/p>\n After that, run a command to update and upgrade the packages. As you can see below, my client has 173 packages<\/strong> that can be updated.<\/p>\n Before you can update your client server, tail the logs on the server so you can see the client actions:<\/p>\n Then tun the update command<\/p>\n You should be able to see some actions on the log file.<\/p>\n You can also check the report from the server.<\/p>\n You can click on Count Data<\/strong> button to show the number of requests and data hits that have been processed already<\/p>\n To save on storage, you may want to clean cache from time to time. You can be able to do this from the reporting page. Click on Start Scan and\/or Expiration<\/strong>.<\/p>\n That is all we could cover about installing and setting up Apt-Cacher server on Ubuntu 18.04. You can learn more about it here<\/a> and here<\/a>. We hope this guide helped. Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":" Good day all. Welcome to our guide on how to set up apt-caching server using Apt-Cacher NG on Ubuntu 18.04 server. Well, so what is<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"rank_math_lock_modified_date":false,"footnotes":""},"categories":[121,64],"tags":[231,1972,1973,1971,67],"class_list":["post-1205","post","type-post","status-publish","format-standard","hentry","category-howtos","category-ubuntu-18-04","tag-apt-cache-apt-cacher-ng","tag-apt-cacher-ng","tag-configure-apt-cacher-ng-ubuntu-18-04","tag-install-apt-cacher-ng-on-ubuntu-18-04","tag-ubuntu-18-04","generate-columns","tablet-grid-50","mobile-grid-100","grid-parent","grid-50"],"_links":{"self":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1205"}],"collection":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/comments?post=1205"}],"version-history":[{"count":12,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1205\/revisions"}],"predecessor-version":[{"id":6899,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/posts\/1205\/revisions\/6899"}],"wp:attachment":[{"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/media?parent=1205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/categories?post=1205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kifarunix.com\/wp-json\/wp\/v2\/tags?post=1205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}\n
Installing Apt-Cacher NG<\/span><\/h2>\n
apt install apt-cacher-ng<\/code><\/pre>\n
\n<\/span><\/p>\nsystemctl status apt-cacher-ng<\/code><\/pre>\n
\u25cf<\/span> apt-cacher-ng.service - Apt-Cacher NG software download proxy\r\n Loaded: loaded (\/lib\/systemd\/system\/apt-cacher-ng.service; enabled; vendor preset: enabled)\r\n Active: active (running)<\/span> since Thu 2018-11-08 13:17:15 EAT; 4min 49s ago\r\n Main PID: 30936 (apt-cacher-ng)\r\n Tasks: 1 (limit: 1110)\r\n CGroup: \/system.slice\/apt-cacher-ng.service\r\n \u2514\u250030936 \/usr\/sbin\/apt-cacher-ng SocketPath=\/run\/apt-cacher-ng\/socket -c \/etc\/apt-cacher-ng ForeGround=1\r\n...<\/strong><\/code><\/pre>\n
systemctl is-enabled apt-cacher-ng<\/code><\/pre>\n
enabled<\/strong><\/code><\/pre>\n
\n<\/span><\/p>\nufw allow 3142\/tcp\r\nufw reload<\/code><\/pre>\n
<\/a>
Configuring Apt-Cacher NG<\/span><\/h2>\n
Server Configuration<\/h3>\n
...<\/strong>\r\n# Storage directory for downloaded data<\/strong> and related maintenance activity.\r\n#\r\nCacheDir: \/var\/cache\/apt-cacher-ng\r\n\r\n# Log file directory<\/strong>, can be set empty to disable logging\r\n#\r\nLogDir: \/var\/log\/apt-cacher-ng\r\n\r\n# A place to look for additional configuration and resource files<\/strong> if they are not\r\n# found in the configuration directory\r\n#\r\nSupportDir: \/usr\/lib\/apt-cacher-ng\r\n\r\n# Repository remapping<\/strong>. Defines distributions to cache their packages\r\n#\r\n\r\nRemap-debrep: file:deb_mirror*.gz \/debian ; file:backends_debian # Debian Archives\r\nRemap-uburep: file:ubuntu_mirrors \/ubuntu ; file:backends_ubuntu # Ubuntu Archives\r\nRemap-cygwin: file:cygwin_mirrors \/cygwin # ; file:backends_cygwin # incomplete, please create this file or specify preferred mirrors here\r\nRemap-sfnet: file:sfnet_mirrors # ; file:backends_sfnet # incomplete, please create this file or specify preferred mirrors here\r\nRemap-alxrep: file:archlx_mirrors \/archlinux # ; file:backend_archlx # Arch Linux\r\nRemap-fedora: file:fedora_mirrors # Fedora Linux\r\nRemap-epel: file:epel_mirrors # Fedora EPEL\r\nRemap-slrep: file:sl_mirrors # Scientific Linux\r\nRemap-gentoo: file:gentoo_mirrors.gz \/gentoo ; file:backends_gentoo # Gentoo Archives\r\n\r\n#Virtual page accessible in a web browser to see statistics and status<\/strong>\r\n# information, i.e. under http:\/\/localhost:3142\/acng-report.html\r\n#\r\nReportPage: acng-report.html\r\n\r\n# Store the pid of the daemon process<\/strong> in the specified text file.\r\n# Default: disabled\r\n#\r\nPidFile: \/var\/run\/apt-cacher-ng\/pid\r\n\r\n# Days before considering an unreferenced file expired<\/strong> (to be deleted).\r\n#\r\nExThreshold: 4\r\n...<\/strong><\/code><\/pre>\n
# PassThroughPattern: .* # this would allow CONNECT to everything<\/code> such that it looks like;<\/p>\n
PassThroughPattern: .*<\/code><\/p>\n
systemctl restart apt-cacher-ng<\/code><\/pre>\n
Define Allowed Hosts<\/h3>\n
\/etc\/hosts.allow<\/code> and
\/etc\/hosts.deny<\/code> files to whitelist or blacklist certain hosts respectively.<\/p>\n
\/etc\/hosts.allow<\/code><\/p>\n
apt-cacher-ng : 192.168.1.17 192.168.43.0\/24<\/code><\/pre>\n
\n
\/etc\/hosts.deny<\/code><\/li>\n<\/ul>\n
apt-cacher-ng : 192.168.43.0\/24<\/code><\/pre>\n
\n
\/etc\/hosts.allow<\/code><\/li>\n<\/ul>\n
apt-cacher-ng : 192.168.43.27<\/code><\/pre>\n
Client Configuration<\/h3>\n
\n
\nIn this method, you need to create the proxy configuration file\u00a0pointing to the caching server in \/etc\/apt\/apt.conf.d<\/strong> as shown below;<\/li>\n<\/ul>\nvim \/etc\/apt\/apt.conf.d\/02proxy<\/code><\/p>\n
Acquire::http::Proxy \"http:\/\/192.168.43.17:3142\";<\/code><\/p>\n
\n
\nIn this case, you need to replace all mirror hostnames with the cachin server IP address.
\nFor example a mirror hostname like deb http:\/\/ke.archive.ubuntu.com\/ubuntu\/ bionic main<\/code>, would be formatted like;
deb http:\/\/192.168.43.17:3142\/ke.archive.ubuntu.com\/ubuntu\/ bionic main<\/code><\/li>\n<\/ul>\n
echo \"Acquire::http::Proxy \"http:\/\/192.168.43.17:3142\";\" > \/etc\/apt\/apt.conf.d\/02proxy<\/code><\/pre>\n
<\/a>
tail -f \/var\/log\/apt-cacher-ng\/apt-cacher.log<\/code><\/pre>\n
apt-get update<\/code><\/pre>\n
<\/a>
<\/a>
<\/a>