本文主要是介绍使用容器搭建 APT Cacher NG 缓存代理服务,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
使用容器搭建 APT Cacher NG 缓存代理服务
最近在对公有云服务器进行梳理和资源整合,难免要进行机器初始化,以及针对部分镜像进行重新构建。
在这个过程中,最浪费时间的莫过于软件包的下载,为了提升整体部署和镜像构建效率,可以搭建一台用于缓存各种常用软件包的缓存代理服务器。
写在前面
虽然缓存代理服务器对于计算的需求非常低,但是因为考虑到长期维护、后续潜在的数据迁移,服务快速升降级,这里选择使用支持显式声明环境和运行配置的 Docker 方式来搭建,故采取了2核心2GB的虚拟机,如果你的日常 CI 构建、虚拟机数量非常大,可以适当提升机器配置。
基础系统环境准备
既然选择使用 Docker 方式来构建,首先自然是安装容器引擎和基础的编排工具。
apt update && apt upgrade -y && apt install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/gpg | apt-key add -
add-apt-repository "deb http://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
apt install -y docker-ce
curl -L https://github.com/docker/compose/releases/download/1.29.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
依次执行上面的命令,等待环境安装完毕,然后检查一下命令是否正常:
# docker -v
Docker version 20.10.5, build 55c4c88
# docker-compose -v
docker-compose version 1.29.0, build 07737305
构建 APT Cacher NG 容器镜像
在构建应用镜像之前,我们需要先准备应用配置文件:
CacheDir: /var/cache/apt-cacher-ngLogDir: /var/log/apt-cacher-ngPort:80Remap-debrep: file:deb_mirror*.gz /debian ; https://mirrors.tuna.tsinghua.edu.cn/debian/ file:backends_debian
Remap-secdeb: security.debian.org ; https://mirrors.tuna.tsinghua.edu.cn/debian-security/ deb.debian.org/debian-security
Remap-uburep: file:ubuntu_mirrors /ubuntu ; https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ file:backends_ubuntu
Remap-cygwin: file:cygwin_mirrors /cygwin
Remap-alpine: /alpine ; https://mirrors.tuna.tsinghua.edu.cn/alpine/
Remap-alpine: /docker-ce ; https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu/ReportPage: acng-report.htmlUnbufferLogs: 1VerboseLog: 1ForeGround: 1ExThreshold: 4MaxConThreads: 120VfilePatternEx: (metalink\?repo=[0-9a-zA-Z-]+&arch=[0-9a-zA-Z_-]+|/\?releas
这篇关于使用容器搭建 APT Cacher NG 缓存代理服务的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!