目录

服务端

apt-mirror下载软件包

  1. 安装apt-mirror
    sudo apt-get install apt-mirror -y
    #修复FAQ1
    sudo curl -fsSL https://raw.githubusercontent.com/Stifler6996/apt-mirror/master/apt-mirror > apt-mirror
    
  2. 配置mirror.list
    sudo nano /etc/apt/mirror.list
    
    ############# config ##################
    set base_path    /data/apt-mirror
    #set mirror_path  $base_path/mirror
    #set skel_path    $base_path/skel
    #set var_path     $base_path/var
    #set cleanscript $var_path/clean.sh
    #set defaultarch  <running host architecture>
    #set postmirror_script $var_path/postmirror.sh
    #set run_postmirror 0
    set nthreads     20
    set _tilde 0
    ############# end config ##############
    deb http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu focal-security main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu focal-proposed main restricted universe multiverse
    deb http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
    #deb-src http://archive.ubuntu.com/ubuntu focal main restricted universe multiverse
    #deb-src http://archive.ubuntu.com/ubuntu focal-security main restricted universe multiverse
    #deb-src http://archive.ubuntu.com/ubuntu focal-updates main restricted universe multiverse
    #deb-src http://archive.ubuntu.com/ubuntu focal-proposed main restricted universe multiverse
    #deb-src http://archive.ubuntu.com/ubuntu focal-backports main restricted universe multiverse
    clean http://archive.ubuntu.com/ubuntu
    
  3. 下载软件包
    sudo apt-mirror
    

部署HTTP服务

  • 1.安装Apache
    sudo apt-get install apache2 -y
    
  • 2.配置
    sudo nano /etc/apache2/sites-enabled/000-default.conf
    
<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www     
    <Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
  • 3.创建软链接
    sudo ln -s /data/apt-mirror/mirror/archive.ubuntu.com/ubuntu /var/www/ubuntu
    
  • 4.重启Apache
    sudo service apache2 restart
    

客户端

编辑软件源

sudo nano /etc/apt/sources.list
deb http://172.16.33.174/ubuntu focal main restricted universe multiverse
deb http://172.16.33.174/ubuntu focal-updates main restricted universe multiverse
deb http://172.16.33.174/ubuntu focal-security main restricted universe multiverse
deb http://172.16.33.174/ubuntu focal-proposed main restricted universe multiverse
deb http://172.16.33.174/ubuntu focal-backports main restricted universe multiverse

更新软件包索引

sudo apt update

FAQ

  1. can’t open index archive.ubuntu.com
    sudo apt-mirror
    Processing indexes: [SSSapt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal/main/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal/restricted/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal/universe/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal/multiverse/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal-security/main/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal-security/restricted/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal-security/universe/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal-security/multiverse/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal-updates/main/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal-updates/restricted/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal-updates/universe/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    apt-mirror: can't open index archive.ubuntu.com/ubuntu//dists/focal-updates/multiverse/binary-<running/Packages in process_index at /usr/bin/apt-mirror line 800.
    PPP]
    

参考资料