Setting Up an Offline Ubuntu APT Mirror with Aliyun Synchronization

Environment Preparation and Tool Installation

Deploying a local package repository for isolated networks requires a synchronization utility and an HTTP daemon. Install the necessary components on an Ubuntu 18.04 host using the following commands:

sudo apt update
sudo apt install -y apt-mirror apache2
sudo systemctl enable apache2

Configuring the Synchronization Profile

Modify the mirror configuration file at /etc/apt/mirror to specify upstream Aliyun endpoints and define local storage directories. The rewritten profile uses a consolidated path structure and optimizes concurrent connections.

set base_path    /srv/aptrepo
set mirror_path  $base_path/pool
set skel_path    $base_path/indexes
set var_path     $base_path/logs
set cleanscript  $var_path/purge_old_pkgs.sh
set nthreads     16
set run_postmirror 0
set _tilde 0

# 64-bit architecture repositories
deb-amd64 http://mirrors.aliyun.com/ubuntu bionic main restricted universe multiverse
deb-amd64 http://mirrors.aliyun.com/ubuntu bionic-security main restricted universe multiverse
deb-amd64 http://mirrors.aliyun.com/ubuntu bionic-updates main restricted universe multiverse
deb-amd64 http://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse
deb-amd64 http://mirrors.aliyun.com/ubuntu bionic-proposed main restricted universe multiverse

# 32-bit architecture repositories
deb-i386 http://mirrors.aliyun.com/ubuntu bionic main restricted universe multiverse
deb-i386 http://mirrors.aliyun.com/ubuntu bionic-security main restricted universe multiverse
deb-i386 http://mirrors.aliyun.com/ubuntu bionic-updates main restricted universe multiverse
deb-i386 http://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse
deb-i386 http://mirrors.aliyun.com/ubuntu bionic-proposed main restricted universe multiverse

The base_path variable controls the root directory for all downloaded assets. Thread concurrency is adjusted via nthreads to balance bandwidth usage. Both 32-bit and 64-bit architecture definitions are retained alongside all standard component classifications to guarantee full dependency coverage.

Initializing Storage and Executing Sync

Verify that the target volume has sufficient capacity, as a complete Ubuntu release repository typically exceeds 200 GB. Create the directory and initiate the synchronization process:

sudo mkdir -p /srv/aptrepo
sudo apt-mirror

The tool will first retrieve metadata indexes, followed by the binary packages. Track disk consumption during the operation to confirm data ingestion:

df -h /srv/aptrepo

Initial synchronization duration depends heavily on available bandwidth and server load. The terminal output will display real-time progress for each thread as indices and archives are fetched.

Serving the Repository via Apache

Configure the Apache web server to expose the synchronized directory tree over the internal network. Edit /etc/apache2/sites-available/000-default.conf and update the document root and directory permissions:

<VirtualHost *:80>
    ServerAdmin repo-admin@internal.lan
    DocumentRoot /srv/aptrepo

    <Directory /srv/aptrepo>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/mirror-error.log
    CustomLog ${APACHE_LOG_DIR}/mirror-access.log combined
</VirtualHost>

Restart the service and adjust firewall rules to permit internal traffic:

sudo systemctl restart apache2
sudo ufw allow 'Apache Full'

Validate the setup by navigating to http://<server_ip>/pool/mirrors.aliyun.com/ubuntu in a web browser. The directory listing should reflect the synchronized package structure.

Connecting Client Machines

Replace the default repository sources on offline clients to direct package requests to the local mirror. Edit /etc/apt/sources.list on each target system, substituting <mirror_server_ip> with the actual address of the hosting node:

deb [arch=amd64] http://<mirror_server_ip>/pool/mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb [arch=amd64] http://<mirror_server_ip>/pool/mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb [arch=amd64] http://<mirror_server_ip>/pool/mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb [arch=amd64] http://<mirror_server_ip>/pool/mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb [arch=amd64] http://<mirror_server_ip>/pool/mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

Refresh the local package cache to apply the new endpoints:

sudo apt update

A succesfull run will display retrieval logs pointing to the internal server IP, confirming that isolated workloads can now resolve dependencies and install software through the synchronized local repository.

Tags: Ubuntu apt-mirror aliyun-repository apache2 offline-package-management

Posted on Sun, 19 Jul 2026 16:38:03 +0000 by zmoerf