Create a local apt-mirror

Download an apt-mirror

To create a local Debian APT mirror, you can follow these general steps:

  1. Set up a server: You will need a server with sufficient storage capacity and network bandwidth to host the mirror.

  2. Install the necessary packages: Start by installing the apt-mirror package, which is available in the Debian repositories. Use the following command to install it:

    sudo apt-get install apt-mirror
    
  3. Configure the mirror: Open the apt-mirror configuration file using a text editor. The file is located at /etc/apt/mirror.list. You can use the following command to open it with nano:

    sudo nano /etc/apt/mirror.list
    

    Inside the file, you need to define the repositories you want to mirror. Uncomment the lines for the desired repositories, or add new lines if needed. For example:

    deb http://deb.debian.org/debian buster main contrib non-free
    deb-src http://deb.debian.org/debian buster main contrib non-free
    

    Save the file after making the necessary changes.

  4. Configure the mirror directory: By default, apt-mirror uses the directory /var/spool/apt-mirror to store the mirrored files. Ensure that you have enough space available in that directory, or specify a different location in the apt-mirror configuration file if needed.

  5. Run apt-mirror: Execute the apt-mirror command with root privileges to start the mirroring process. Use the following command:

    sudo apt-mirror
    

    The mirroring process will take some time, depending on the speed of your network connection and the size of the repositories you're mirroring. Ensure that the server remains connected to the internet during this process.

  6. Serve the mirror using a web server: After the mirroring process completes, you need to serve the mirror using a web server. You can use any web server of your choice, such as Apache or Nginx. Install and configure the web server, ensuring that it points to the mirror directory you specified earlier.

  7. Configure clients to use the local mirror: On the machines where you want to use the local mirror, modify the /etc/apt/sources.list file to point to your mirror's URL. Replace the original Debian repository URLs with the URL of your local mirror. For example:

    deb http://your-mirror-url/debian buster main contrib non-free
    deb-src http://your-mirror-url/debian buster main contrib non-free
    

    Save the file after making the changes.

That's it! Your local Debian APT mirror should be ready to use. Clients can now update and install packages from the mirror, which will be significantly faster than downloading from the official Debian repositories. Remember to periodically update your mirror by running apt-mirror again to keep it synchronized with the official repositories.


Provide apt-mirror

To provide your local Debian APT mirror via Apache2, you can follow these steps:

  1. Install Apache2: If you don't already have Apache2 installed, you can install it using the package manager. On Debian-based systems, you can use the following command:

    sudo apt-get install apache2
    
  2. Configure Apache2: Once Apache2 is installed, you need to configure it to serve your APT mirror. Open the Apache2 configuration file using a text editor. On Debian-based systems, the file is located at /etc/apache2/sites-available/000-default.conf. Use the following command to open it with nano:

    sudo nano /etc/apache2/sites-available/000-default.conf
    

    Inside the file, you need to add a new Alias directive that maps a URL path to the directory where your mirror is located. For example, if your mirror is stored in /var/spool/apt-mirror, you can add the following line within the <VirtualHost> block:

    Alias /debian /var/spool/apt-mirror/mirror/deb.debian.org/debian
    

    Save the file after making the changes.

  3. Enable the Alias module: By default, the alias module is not enabled in Apache2. Enable it using the following command:

    sudo a2enmod alias
    
  4. Give folder and Alias the right permissions, by editing /etc/apache2/apache2.conf

      <Directory /debian>
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
    </Directory>
    
    <Directory /var/spool/apt-mirror/mirror/ftp.us.debian.org/debian>
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all granted
    </Directory>  
    
  5. Restart Apache2: After making the configuration changes, restart Apache2 for the changes to take effect:

    sudo service apache2 restart
    
  6. Test the mirror: Open a web browser and enter the URL http://your-server-ip/debian (replace your-server-ip with the IP address or hostname of your server). You should see the directory listing of the Debian mirror, indicating that Apache2 is serving the mirror correctly.

    Note: If you want to restrict access to the mirror and only allow specific clients to use it, you can configure Apache2 to add authentication or restrict access based on IP addresses.

With these steps, you have configured Apache2 to provide your local Debian APT mirror. Clients can now update their /etc/apt/sources.list file to point to your mirror URL, such as http://your-server-ip/debian, and use it to download packages from the local mirror.


Revision #5
Created 19 June 2023 05:38:22 by tinfoil-hat
Updated 5 November 2023 02:56:02 by tinfoil-hat