apt-mirror Ubuntu APT 包镜像/同步工具

发布时间: 更新时间: 总字数:436 阅读时间:1m 作者: IP上海 分享 网址

apt-mirror Ubuntu APT 包镜像/同步工具

安装

$ sudo apt-get install apt-mirror

使用

apt-mirror 配置

  • 创建 apt 存放目录,建议挂载数据盘
sudo mkdir /ubuntu-apt
  • 创建 mirror.list,建议切换为国内源
cat << EOF > /etc/apt/mirror.list
############# config ##################
#
# set base_path    /var/spool/apt-mirror
set base_path    /ubuntu-apt
#
# 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 jammy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu jammy-proposed main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse

deb-src http://archive.ubuntu.com/ubuntu jammy main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu jammy-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu jammy-updates main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu jammy-proposed main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu jammy-backports main restricted universe multiverse

clean http://archive.ubuntu.com/ubuntu
EOF

同步

apt-mirror

# 或通过 crontab 定时同步
$ sudo crontab -e

# 增加一行,每天凌晨两点同步
0 2 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log

Nginx 代理配置

  • 然后通过 nginx 代理 http 服务
docker run \
    --name apt-repository \
    --restart unless-stopped \
    -p 80:80 \
    -v /ubuntu-apt/skel/archive.ubuntu.com/:/usr/share/nginx/html \
    -d nginx:latest

客户端配置

  • 客户端配置 /etc/apt/source.list
deb http://<apt-ip>/ubuntu jammy main restricted universe multiverse
deb http://<apt-ip>/ubuntu jammy-security main restricted universe multiverse
deb http://<apt-ip>/ubuntu jammy-updates main restricted universe multiverse

其他思路

扩展

ubuntu 使用 iso 软件包

# 挂载
sudo mount -o loop usb/ubunto.iso /media/cdrom

# 添加源,-m 参数使用 /media/cdrom 作为节点添加到 /etc/apt/sources.list 中
sudo apt-cdrom add -m

# 使用
apt-get update

其他

deb https://nvidia.github.io/libnvidia-container/ubuntu16.04/amd64 /
deb https://nvidia.github.io/nvidia-container-runtime/ubuntu16.04/amd64 /
deb https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64 /

clean https://nvidia.github.io/libnvidia-container/ubuntu16.04/amd64/
clean https://nvidia.github.io/nvidia-container-runtime/ubuntu16.04/amd64/
clean https://nvidia.github.io/nvidia-docker/ubuntu16.04/amd64/

参考

  1. https://launchpad.net/ubuntu/+archivemirrors
Home Archives Categories Tags Statistics
本文总阅读量 次 本站总访问量 次 本站总访客数