Setting Up Apt-Cacher-NG on CentOS

Managing a network of Linux systems often involves repetitive downloads of packages and updates, which can consume significant bandwidth and storage space. By setting up apt-cacher-ng with CentOS, you can efficiently cache these packages locally, reducing internet bandwidth usage and speeding up installation on multiple machines. This guide will walk you through installing and configuring apt-cacher-ng as a local mirror with Nginx acting as a reverse proxy.

Prerequisites

Before beginning this setup, ensure you have a CentOS system ready for installation. You'll need root access and basic familiarity with Linux command line operations.

Installation of Apt-Cacher-NG

To install apt-cacher-ng, you'll first need to add the necessary repository and install the package:

sudo yum install epel-release -y
sudo yum install apt-cacher-ng -y
    

Configuring Apt-Cacher-NG

After installation, configure apt-cacher-ng to cache and distribute packages:

sudo nano /etc/apt-cacher-ng/acng.conf
    

Modify the configuration file to optimize performance and ensure compatibility with your network settings. Here are a few key parameters to consider:

Setting Up Nginx as a Reverse Proxy

To configure Nginx as a reverse proxy for apt-cacher-ng, install Nginx and update the configuration:

sudo yum install nginx -y
sudo nano /etc/nginx/nginx.conf
    

Add the following server block to the configuration file to enable port 80 forwarding:

server {
    listen 80;
    server_name _;
    location / {
        proxy_pass http://localhost:3142;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
    }
}
    

Restart Nginx to apply the changes:

sudo systemctl restart nginx
    

Configuring Client Machines

On each client machine that should use the apt-cacher-ng server, configure the package manager to use your cache server:

echo 'Acquire::http { Proxy "http://your-server-ip:80"; };' | sudo tee /etc/apt/apt.conf.d/01proxy
    

Maintaining and Monitoring Apt-Cacher-NG

Regular maintenance and monitoring are crucial to ensure optimal performance of your caching server. Use the following commands to manage and monitor apt-cacher-ng:

sudo systemctl status apt-cacher-ng
sudo tail -f /var/log/apt-cacher-ng/apt-cacher.log
    

Further Resources and Help

For more detailed configuration options and troubleshooting, refer to the Linux Patch Management platform and the official Apt-Cacher-NG documentation.