{"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":"<p>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 <span class=\"title\">Apt-Cacher NG<\/span>?<\/p>\n<p><span class=\"title\">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<p>Some of the features of <span class=\"title\">Apt-Cacher NG<\/span> include;<\/p>\n<ul>\n<li>It is lightweight and can run on systems with low memory and processing power<\/li>\n<li>It supports internal threading thus avoids process fork&#8217;ing, kludges for pseudo-thread synchronization nor rely on special file system features for internal operations<\/li>\n<li>Supports HTTP pipelining and thus reduction of resource overhead and minimization of possible points of failure<\/li>\n<\/ul>\n<h2>Installing <span class=\"title\">Apt-Cacher NG<\/span><\/h2>\n<p>Since <span class=\"title\">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<pre>apt install apt-cacher-ng<\/code><\/pre>\n<p><span class=\"title\">Apt-Cacher NG starts automatically by default after the installation. You can verify the same by running the command below;<br \/>\n<\/span><\/p>\n<pre>systemctl status apt-cacher-ng<\/code><\/pre>\n<pre><span style=\"color: #00ff00;\">\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: <span style=\"color: #00ff00;\">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>...<\/strong><\/code><\/pre>\n<p>It is also enabled to run on system reboot;<\/p>\n<pre>systemctl is-enabled apt-cacher-ng<\/code><\/pre>\n<pre><strong>enabled<\/strong><\/code><\/pre>\n<p><span class=\"title\">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.<br \/>\n<\/span><\/p>\n<p><span class=\"title\">Apt-Cacher NG<\/span> also listens on port 3142\/TCP by default. Therefore, if UFW is running, open this port.<\/p>\n<pre>ufw allow 3142\/tcp\r\nufw reload<\/code><\/pre>\n<p>To verify that your Apt-Cacher is working fine, just navigate to your browser and enter the URL in the format, <strong>http:\/\/&lt;hostname or IP&gt;:3142\/apt-cacher<\/strong><\/p>\n<figure id=\"attachment_1352\" aria-describedby=\"caption-attachment-1352\" style=\"width: 837px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/apt-cacher.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1352\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/apt-cacher.png\" alt=\"apt-cacher\" width=\"847\" height=\"842\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/apt-cacher.png 847w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/apt-cacher-768x763.png 768w\" sizes=\"(max-width: 847px) 100vw, 847px\" \/><\/a><figcaption id=\"caption-attachment-1352\" class=\"wp-caption-text\">apt-cacher<\/figcaption><\/figure>\n<h2>Configuring <span class=\"title\">Apt-Cacher NG<\/span><\/h2>\n<h3>Server Configuration<\/h3>\n<p>The main configuration file for <span class=\"title\">Apt-Cacher NG<\/span> is located at <strong>\/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<p>Basically, the following are the some of the parameters that are enabled by default in the <span class=\"title\">Apt-Cacher NG configuration file.<\/span><\/p>\n<pre><strong>...<\/strong>\r\n# <strong>Storage directory for downloaded data<\/strong> and related maintenance activity.\r\n#\r\nCacheDir: \/var\/cache\/apt-cacher-ng\r\n\r\n# <strong>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 <strong>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# <strong>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 <strong>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 <strong>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 <strong>unreferenced file expired<\/strong> (to be deleted).\r\n#\r\nExThreshold: 4\r\n<strong>...<\/strong><\/code><\/pre>\n<p>In order to serve HTPPS repositories, you need to configure HTPPS connection tunneling through the Apt-Cacher proxy by uncommenting the line, <code># PassThroughPattern: .* # this would allow CONNECT to everything<\/code> such that it looks like;<\/p>\n<p><code>PassThroughPattern: .*<\/code><\/p>\n<p>Note, whenever you make any configuration changes, you need to restart <tt>apt-cacher-ng<\/tt> in order for the changes to take effect by running the command;<\/p>\n<pre>systemctl restart apt-cacher-ng<\/code><\/pre>\n<h3>Define Allowed Hosts<\/h3>\n<p>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 <code>\/etc\/hosts.allow<\/code> and <code>\/etc\/hosts.deny<\/code> files to whitelist or blacklist certain hosts respectively.<\/p>\n<p>For example;<\/p>\n<p>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 <code>\/etc\/hosts.allow<\/code><\/p>\n<pre>apt-cacher-ng : 192.168.1.17 192.168.43.0\/24<\/code><\/pre>\n<p>To block all hosts on the network 192.168.43.0\/24 except the host 192.168.43.27;<\/p>\n<ul>\n<li>put the following line in <code>\/etc\/hosts.deny<\/code><\/li>\n<\/ul>\n<pre>apt-cacher-ng : 192.168.43.0\/24<\/code><\/pre>\n<ul>\n<li>and the following line in the <code>\/etc\/hosts.allow<\/code><\/li>\n<\/ul>\n<pre>apt-cacher-ng : 192.168.43.27<\/code><\/pre>\n<h3>Client Configuration<\/h3>\n<p>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<p>There are two ways in which clients can be configured to download packages through the Apt-Cacher.<\/p>\n<ul>\n<li>Specifying the caching machine as HTTP Proxy for the client<br \/>\nIn this method, you need to create the proxy configuration file\u00a0pointing to the caching server in <strong>\/etc\/apt\/apt.conf.d<\/strong> as shown below;<\/li>\n<\/ul>\n<p><code>vim \/etc\/apt\/apt.conf.d\/02proxy<\/code><\/p>\n<p><code>Acquire::http::Proxy \"http:\/\/192.168.43.17:3142\";<\/code><\/p>\n<p>Where <strong>192.168.43.17<\/strong> is your cache server IP address.<\/p>\n<ul>\n<li>Replacing all mirror hostnames with Caching host in sources.list<br \/>\nIn this case, you need to replace all mirror hostnames with the cachin server IP address.<br \/>\nFor example a mirror hostname like <code>deb http:\/\/ke.archive.ubuntu.com\/ubuntu\/ bionic main<\/code>, would be formatted like;<code>deb http:\/\/192.168.43.17:3142\/ke.archive.ubuntu.com\/ubuntu\/ bionic main<\/code><\/li>\n<\/ul>\n<p>The first method is more convenient as compared to the second method.<\/p>\n<p>To verify this, login to your client and configure it as shown below;<\/p>\n<pre>echo \"Acquire::http::Proxy \"http:\/\/192.168.43.17:3142\";\" &gt; \/etc\/apt\/apt.conf.d\/02proxy<\/code><\/pre>\n<p>After that, run a command to update and upgrade the packages. As you can see below, my client has <strong>173 packages<\/strong> that can be updated.<\/p>\n<figure id=\"attachment_1353\" aria-describedby=\"caption-attachment-1353\" style=\"width: 791px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/client-updates.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-1353\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/client-updates.png\" alt=\"client-updates\" width=\"801\" height=\"124\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/client-updates.png 801w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/client-updates-768x119.png 768w\" sizes=\"(max-width: 801px) 100vw, 801px\" \/><\/a><figcaption id=\"caption-attachment-1353\" class=\"wp-caption-text\">client-updates<\/figcaption><\/figure>\n<p>Before you can update your client server, tail the logs on the server so you can see the client actions:<\/p>\n<pre>tail -f \/var\/log\/apt-cacher-ng\/apt-cacher.log<\/code><\/pre>\n<p>Then tun the update command<\/p>\n<pre>apt-get update<\/code><\/pre>\n<p>You should be able to see some actions on the log file.<\/p>\n<p>You can also check the report from the server.<\/p>\n<figure id=\"attachment_1354\" aria-describedby=\"caption-attachment-1354\" style=\"width: 830px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/apt-cacher-report.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1354 size-full\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/apt-cacher-report.png\" alt=\"Apt-Cacher NG report\" width=\"840\" height=\"626\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/apt-cacher-report.png 840w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/apt-cacher-report-768x572.png 768w\" sizes=\"(max-width: 840px) 100vw, 840px\" \/><\/a><figcaption id=\"caption-attachment-1354\" class=\"wp-caption-text\">apt-cacher-report<\/figcaption><\/figure>\n<p>You can click on <strong>Count Data<\/strong> button to show the number of requests and data hits that have been processed already<\/p>\n<figure id=\"attachment_1356\" aria-describedby=\"caption-attachment-1356\" style=\"width: 785px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/requests-data-hits.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1356 size-full\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/requests-data-hits.png\" alt=\"Apt-Cacher NG requests-data-hits\" width=\"795\" height=\"314\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/requests-data-hits.png 795w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/requests-data-hits-768x303.png 768w\" sizes=\"(max-width: 795px) 100vw, 795px\" \/><\/a><figcaption id=\"caption-attachment-1356\" class=\"wp-caption-text\">requests-data-hits<\/figcaption><\/figure>\n<p>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 <strong>Start Scan and\/or Expiration<\/strong>.<\/p>\n<figure id=\"attachment_1355\" aria-describedby=\"caption-attachment-1355\" style=\"width: 790px\" class=\"wp-caption alignnone\"><a href=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/clean-local-cache.png\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-1355 size-full\" src=\"http:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/clean-local-cache.png\" alt=\"Apt-Cacher NG clean-local-cache\" width=\"800\" height=\"626\" title=\"\" srcset=\"https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/clean-local-cache.png 800w, https:\/\/kifarunix.com\/wp-content\/uploads\/2018\/11\/clean-local-cache-768x601.png 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-1355\" class=\"wp-caption-text\">clean-local-cache<\/figcaption><\/figure>\n<p>That is all we could cover about installing and setting up Apt-Cacher server on Ubuntu 18.04. You can learn more about it <a href=\"https:\/\/help.ubuntu.com\/community\/Apt-Cacher-Server\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a> and <a href=\"https:\/\/www.unix-ag.uni-kl.de\/~bloch\/acng\/html\/index.html\" target=\"_blank\" rel=\"noopener noreferrer\">here<\/a>. We hope this guide helped. Thanks for reading.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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}]}}