使用apt-mirror搭建debian镜像源

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 命令即可。

# 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;
}

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


原文发布时间:2016-12-28
本文来自云栖社区合作伙伴“Debian社区”,了解相关信息可以关注“Debian社区”。
上一篇:Hadoop何以快速成为最佳网络安全工具?


下一篇:阿里云开发者社区问答栏目提问规范