ubuntu 内网自建apt源(apt-mirror)
文章目录
1. 安装apt-mirror
- 官网地址:https://apt-mirror.github.io/
- 安装
$ apt-getinstall apt-mirror - 配置文件
/etc/apt/mirror.list - 配置代理
- 修改存储位置
修改配置(非必要)
set unlink 1set use_proxy on set http_proxy 10.10.xxx.xx:1111 set proxy_user user set proxy_password password set base_path /var/spool/apt-mirror set mirror_path $base_path/mirror set skel_path $base_path/skel set var_path $base_path/var set postmirror_script $var_path/postmirror.sh 建议整体设置set base_path到大磁盘就可以了实际使用中,我直接使用软连接把/var/spool/apt-mirror链接到了/data/apt-mirror
2. 更新apt镜像数据
- 启动
$ sudo apt-mirror 输出如下,同步
root@boe:/etc/apt# apt-mirror Downloading 162 index files using 20 threads... Begin time: Fri Feb 7 01:05:14 2025[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]... End time: Fri Feb 7 01:15:46 2025 Processing translation indexes: [TTT] Downloading 558 translation files using 20 threads... Begin time: Fri Feb 7 01:15:46 2025[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]... End time: Fri Feb 7 01:16:02 2025 Processing DEP-11 indexes: [DDD] Downloading 88 dep11 files using 20 threads... Begin time: Fri Feb 7 01:16:02 2025[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]... End time: Fri Feb 7 01:16:09 2025 Processing cnf indexes: [CCC] Downloading 24 cnf files using 20 threads... Begin time: Fri Feb 7 01:16:09 2025[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]... End time: Fri Feb 7 01:16:10 2025 Processing indexes: [SSSPPP]535.4 GiB will be downloaded into archive. Downloading 105806 archive files using 20 threads... Begin time: Fri Feb 7 01:16:19 2025[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... - 停止
- 除了kill好像也没有什么好的方法
- 未结束之前重新执行,此时会报错。删除
/var/spool/apt-mirror/var/apt-mirror.lock文件,再次执行即可。
3. 创建web服务(以nginx为例)
- 创建nginx目录,进入该目录
- 创建docker-compse.yml文件内如如下:
services: nginx-01: image: nginx:1.27 ports: - 80:80 volumes: - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro - /data/apt-mirror/mirror/archive.ubuntu.com:/usr/share/nginx/html restart: always 关于挂载:(注意写你自己的实际目录)前文可见/data/apt-mirror是我软连接的/var/spool/apt-mirror这个地址,你也可以通过配置文件修改
- 创建
nginx.conf文件,内容如下:
# gzip设置 gzip on; gzip_vary on; gzip_comp_level 6; gzip_buffers 16 8k; gzip_min_length 1000; gzip_proxied any; gzip_disable "msie6"; #gzip_http_version 1.0; gzip_types text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript; server { listen 80; server_name web80; location / { root /usr/share/nginx/html; index index.html index.htm; add_header Cache-Control no-store; }}- 启动nginx
docker-compose up -d 4. 客户端使用
- 添加源
找一台其他客户机,修改/etc/apt/sources.list文件,内容如下:
deb http://10.10.239.56/ubuntu/ jammy main restricted universe multiverse deb http://10.10.239.56/ubuntu/ jammy-updates main restricted universe multiverse deb http://10.10.239.56/ubuntu/ jammy-security main restricted universe multiverse - 测试,安装一个小工具试试
apt update aptinstall php-curl 5. 添加一个新源(以docker为例)
- 添加秘钥(如果本机apt源添加过可以略过,两个是一样的)
curl -fsSL https://download.docker.com/linux/ubuntu/gpg |sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg - 修改
/etc/apt/mirror.list文件,添加如下行:
deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu jammy stable - 更新apt镜像
apt-mirror