debian官方提供了脚本ftpsync来搭建源镜像,而 apt-mirror 是一个更简单便捷的源镜像搭建工具。

安装 apt-mirror

sudo apt-get install apt-mirror

配置文件/etc/apt/mirror.list只要修改很少的地方,大部分使用默认值即可。

这里使用中科大镜像 ftp.cn.debian.org 作为上游镜像,只镜像 debian jessie amd64 架构,不镜像源代码包。

############# config ##################
#
# 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 cleanscript $var_path/clean.sh
# set defaultarch  # 默认架构与镜像主机的架构一致,这里是amd64
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads 20
set _tilde 0
#
############# end config ############## deb http://ftp.cn.debian.org/debian jessie main contrib non-free
deb http://ftp.cn.debian.org/debian/ jessie-backports main contrib non-free
deb http://ftp.cn.debian.org/debian/ jessie-proposed-updates main contrib non-free
deb http://ftp.cn.debian.org/debian/ jessie-updates main contrib non-free
deb http://ftp.cn.debian.org/debian-security/ jessie/updates main contrib non-free
#deb-src http://ftp.us.debian.org/debian unstable main contrib non-free # mirror additional architectures
#deb-alpha http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-amd64 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-armel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-hppa http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-i386 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-ia64 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-m68k http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mips http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-mipsel http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-powerpc http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-s390 http://ftp.us.debian.org/debian unstable main contrib non-free
#deb-sparc http://ftp.us.debian.org/debian unstable main contrib non-free clean http://ftp.cn.debian.org/debian

开启自动同步

只需 root 权限 cron 自动运行 apt-mirror 命令即可。

# vim /etc/cron.d/apt-mirror
0 0 * * * apt-mirror > /var/spool/apt-mirror/var/cron.log 2>&1

或者crontab -e

# m h  dom mon dow   command
0 0 * * * apt-mirror

发布镜像服务

使用nginx发布源镜像

将 apt-mirror 的镜像目录链接到/var/www/mirror

# ln -sf /var/spool/apt-mirror/mirror/ftp.cn.debian.org/ mirror

然后将nginx默认主机default(或者单独虚拟主机)的根目录设置为/var/www/mirror,并开启目录列表

root /var/www/mirror
location / {
autoindex on;
}

其他机器就可以正常使用新建的源镜像了。

另:

apt-mirror能够将官方镜像下载到本地,并保证目录结构与其一致,但是不能对镜像仓库进行修改。如果想要修改镜像仓库,需要使用reprepro。

1、安装apt-mirror

# aptitude update
# aptitude install -y apt-mirror # dpkg -L apt-mirror
/.
/usr
/usr/bin
/usr/bin/apt-mirror
/usr/share
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/apt-mirror.1.gz
/usr/share/doc
/usr/share/doc/apt-mirror
/usr/share/doc/apt-mirror/changelog.gz
/usr/share/doc/apt-mirror/changelog.Debian.gz
/usr/share/doc/apt-mirror/copyright
/etc
/etc/cron.d
/etc/cron.d/apt-mirror
/etc/apt
/etc/apt/mirror.list
/var
/var/spool
/var/spool/apt-mirror
/var/spool/apt-mirror/skel
/var/spool/apt-mirror/mirror
/var/spool/apt-mirror/var

2、修改配置文件,添加要下载的源(我这里添加的是debian_squeeze的源)

# vim /etc/apt/mirror.list

set base_path    /docker/debian_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 40
set _tilde 0 deb-amd64 http://archive.debian.org/debian squeeze main
deb-amd64 http://archive.debian.org/debian squeeze-lts main

3、手动运行apt-mirror下载镜像

# apt-mirror
Downloading 28 index files using 28 threads...
Begin time: Mon Aug 21 11:24:11 2017
[28]... [27]... [26]... [25]... [24]... [23]... [22]... [21]... [20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Mon Aug 21 11:24:18 2017 Processing tranlation indexes: [TT] Downloading 32 translation files using 32 threads...
Begin time: Mon Aug 21 11:24:19 2017
[32]... [31]... [30]... [29]... [28]... [27]... [26]... [25]... [24]... [23]... [22]... [21]... [20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Mon Aug 21 11:24:20 2017 Processing indexes: [PP] 32.8 GiB will be downloaded into archive.
Downloading 25138 archive files using 40 threads...
Begin time: Mon Aug 21 11:24:23 2017
[40]... [39]... [38]... [37]... [36]... [35]... [34]... [33]... [32]... [31]... [30]... [29]... [28]... [27]... [26]... [25]... [24]... [23]... [22]... [21]... [20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Mon Aug 21 21:38:48 2017 0 bytes in 0 files and 0 directories can be freed.
Run /docker/debian_mirror/var/clean.sh for this purpose.

4、设置定时任务,定时与官方源同步

# vim /etc/cron.d/apt-mirror
0 0 * * * apt-mirror > /docker/mirror.log 2>&1

5、设置发布目录软链接

# ln -sv /docker/debian_mirror/mirror/archive.debian.org /docker/mirror

6、配置nginx发布镜像目录

# cd /usr/local/nginx/conf/vhosts/
# vim debian_mirror.conf server {
listen 8081;
server_name debian_mirror; root /docker/mirror
location / {
autoindex on;
} access_log /usr/local/nginx/logs/debian_mirror.access.log oupeng_logs;
error_log /usr/local/nginx/logs/debian_mirror.error.log;
} # /usr/local/nginx/sbin/nginx -t
# /usr/local/nginx/sbin/nginx -s reload

7、找一台debian6的机器添加本地源测试

# vim /etc/apt/sources.list
deb http://117.119.33.138:8081/debian squeeze main
deb http://117.119.33.138:8081/debian squeeze-lts main # aptitude update
Hit http://117.119.33.138 squeeze Release.gpg
Ign http://117.119.33.138/debian/ squeeze/main Translation-en
Ign http://117.119.33.138/debian/ squeeze/main Translation-en_US
Get:1 http://117.119.33.138 squeeze-lts Release.gpg [819 B]
Ign http://117.119.33.138/debian/ squeeze-lts/main Translation-en
Ign http://117.119.33.138/debian/ squeeze-lts/main Translation-en_US
Hit http://117.119.33.138 squeeze Release
Get:2 http://117.119.33.138 squeeze-lts Release [34.3 kB]
Hit http://117.119.33.138 squeeze/main amd64 Packages
E: Release file expired, ignoring http://117.119.33.138:8081/debian/dists/squeeze-lts/Release (invalid since 524d 12h 54min 42s)

其中第二个源squeeze-lts会提示过期,在apt配置文件中添加一项配置即可

# vim /etc/apt/apt.conf
Acquire::Check-Valid-Until false; # aptitude update
Get:1 http://apt.oupeng.com squeeze Release.gpg [1,655 B]
Ign http://apt.oupeng.com/debian/ squeeze/main Translation-en
Ign http://apt.oupeng.com/debian/ squeeze/main Translation-en_US
Get:2 http://apt.oupeng.com squeeze-lts Release.gpg [819 B]
Ign http://apt.oupeng.com/debian/ squeeze-lts/main Translation-en
Ign http://apt.oupeng.com/debian/ squeeze-lts/main Translation-en_US
Get:3 http://apt.oupeng.com squeeze Release [96.0 kB]
Get:4 http://apt.oupeng.com squeeze-lts Release [34.3 kB]
Get:5 http://apt.oupeng.com squeeze/main amd64 Packages [6,527 kB]
Get:6 http://apt.oupeng.com squeeze-lts/main amd64 Packages [305 kB]
Hit http://apt.puppetlabs.com squeeze Release.gpg
Ign http://apt.puppetlabs.com/ squeeze/dependencies Translation-en
Ign http://apt.puppetlabs.com/ squeeze/dependencies Translation-en_US
Ign http://apt.puppetlabs.com/ squeeze/main Translation-en
Ign http://apt.puppetlabs.com/ squeeze/main Translation-en_US
Hit http://apt.puppetlabs.com squeeze Release
Ign http://apt.puppetlabs.com squeeze/main Sources
Ign http://apt.puppetlabs.com squeeze/dependencies Sources
Ign http://apt.puppetlabs.com squeeze/main amd64 Packages
Ign http://apt.puppetlabs.com squeeze/dependencies amd64 Packages
Hit http://apt.puppetlabs.com squeeze/main Sources
Hit http://apt.puppetlabs.com squeeze/dependencies Sources
Hit http://apt.puppetlabs.com squeeze/main amd64 Packages
Hit http://apt.puppetlabs.com squeeze/dependencies amd64 Packages
Fetched 6,965 kB in 2s (3,148 kB/s) Current status: 43 updates [+41], 27994 new [+27654].

使用apt-mirror搭建debian镜像源的更多相关文章

  1. debian搭建本地镜像源

    1. 安装apt-mirror apt-get install apt-mirror 2. 配置apt-mirror vim /etc/apt/mirror.list 2.1 下载目录什么的基础配置建 ...

  2. 使用apt-mirror建立局域网内的Debian/Ubuntu源镜像

    转:http://forum.ubuntu.org.cn/viewtopic.php?t=41791 第一次翻译,翻译得不好还请大家见谅,多多指出错误~!:) 原文可以见如下的贴子:http://fo ...

  3. 替换 Docker 或 Laradock 中 Debian 系统镜像源解决软件安装问题

    Docker Debian 镜像源替换 因多数默认的 Docker 镜像为国外的,而采用的镜像源也是国外的,故访问很慢,所以我们需要替换为国内的(比如阿里云或163等). 163 - Debian A ...

  4. 使用apt-mirror建立本地debian仓库源

    先介绍一下环境: 主机:Win7 虚拟机:VirtualBox + Debian7 由于软件源的体积比较大,所以我又给虚拟机添加了一块50GB的虚拟硬盘(给虚拟机添加虚拟硬盘的方法参见:http:// ...

  5. Ubuntu切换为阿里镜像源

    前言 在VM虚拟机搭建Ubuntu系统学习或者测试时,常常要使用apt安装测试,但是由于系统自带的下载源在国外服务器上,下载速度慢的无法忍受.所以我们需要切换为国内镜像源,能显著加快安装包下载速度. ...

  6. 无法更新apt镜像源?树莓派安装最新版Debian11(bullseye)arm64位系统步骤

    镜像下载.域名解析.时间同步请点击阿里云开源镜像站 树莓派系统在2022年1月28日迎来了更新,更新了64位的系统,同时也有lite系统供我们使用.32位系统很多软件都用不了,特别是宝塔面板.下面是安 ...

  7. [How to]基于本地镜像的yum镜像源搭建

    1.简介 本文介绍如何在封闭环境(无外网)下安装离线安装本地镜像与基于本地镜像的yum镜像源. 2.环境版本交代: OS:CentOS-6.7-x86_64-minimal yum: yum-3.2. ...

  8. 使用Docker Toolbox基于boot2docker搭建的Docker如何修改镜像源

    镜像源 由于众所周知的原因,我们直接连接这些位于国外服务器上的仓库去获取依赖包速度是非常慢的,这时候我们通常会采用国内一些组织或开发者贡献的国内镜像仓库. 1.首先Docker也提供了国内的镜像源:h ...

  9. 十分钟内在Ubuntu系统上搭建Mono开发环境(Mono软件Ubuntu系统国内镜像源、Mono国内镜像源)

    Mono软件Ubuntu系统国内镜像源.Mono国内镜像源 http://download.githall.cn/repo 替换为国内源(非官方)有利于加快mono的安装速度,一般情况下,完成mono ...

随机推荐

  1. 【转载】C#中遍历DataTable中的数据行

    在C#中的Datatable数据变量的操作过程中,有时候我们需要遍历DataTable变量获取每一行的数据值,例如将DataTable变量转换为List集合的时候,我们就会遍历DataTable变量, ...

  2. Node.js 中 exports 和 module.exports 的区别

    每一个模块中都有一个 module 对象, module 对象中有一个 exports 对象 我们可以把需要导出的成员都放到 module.exports 这个接口对象中,也就是 module.exp ...

  3. 爬虫requests库 之爬虫贴吧

    首先要观察爬虫的URL规律,爬取一个贴吧所有页的数据,观察点击下一页时URL是如何变化的. 思路: 定义一个类,初始化方法什么都不用管 定义一个run方法,用来实现主要逻辑 3 class Tieba ...

  4. 微服务——SpringCloud(Eureka注册中心搭建)

    IDE:IDEA,说实话,真不怎么喜欢用Eclipse这个IDE,太锻炼人了 配置模式:Grandle 微服务框架:SpringCloud 第一步 创建一个Spring Initializr项目 第二 ...

  5. mac python3 安装mysqlclient

    brew install openssl export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ pip install mysql ...

  6. Codeforces A. Password(KMP的nxt跳转表)

    题目描述: Password time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

  7. NLP文本分类方法汇总

    模型: FastText TextCNN TextRNN RCNN 分层注意网络(Hierarchical Attention Network) 具有注意的seq2seq模型(seq2seq with ...

  8. httprunner学习20-跳过用例skip/skipIf/skipUnless

    前言 在实际工作中,我们有时候会需要对测试用例加判断,比如某个接口功能暂时去掉了,我们希望对这个用例skip不去执行. 当其它的接口依赖于登陆接口返回的token时候,如果登陆都失败了,后面的接口,我 ...

  9. js动画---一个小bug的处理

    对于前面的课程,大家似乎看不出来存在什么问题,一切都很顺利,但是其实是存在一个很大的bug的,这个bug是什么呢?? 我们来看看下面这个程序就知道了 <!DOCTYPE html> < ...

  10. 斐波那契数性质 gcd(F[n],F[m])=F[gcd(n,m)]

    引理1 结论: \[F(n)=F(m)F(n-m+1)+F(m-1)F(n-m)\] 推导: \[ \begin{aligned} F(n) &= F(n-1)+F(n-2) \\ & ...