使用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;
}

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

另:

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].

原文地址:https://www.cnblogs.com/surplus/p/11441206.html

时间: 2024-11-01 13:21:44

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

debian搭建本地镜像源

1. 安装apt-mirror apt-get install apt-mirror 2. 配置apt-mirror vim /etc/apt/mirror.list 2.1 下载目录什么的基础配置建议使用默认. 2.2 deb 配置的是拖库的目标地址 //次配置中选择的是163镜像站. ############# config ################## # # set base_path /var/spool/apt-mirror # # set mirror_path $base

用debian 7.5 cd/dvd 搭建局域网mirror镜像源来批量网络无人值守安装debian

1.图形化最小安装debian7.5操作系统 2.更改debian的apt源配置文件/etc/apt/sources.list [email protected]:~# cat /etc/apt/sources.list deb http://ftp.de.debian.org/debian wheezy main contrib non-free deb-src http://ftp.de.debian.org/debian wheezy main contrib non-free 3.更新a

debian安装ELK日志服务器配置apt镜像源

网上有很多写Ubantua安装ELK日志服务的文档资料,但是很少有Debian安装的文档.因为前期对ELK接触很少,使用Debian安装总是在配置apt安装源的时候无法进行安装.经过扒翻资料,终于找到ELK官网给出的正解.如下: 1.安装java9 apt install openjdk-9-jdk 2.配置镜像源: 安装公共密钥: wget -qO  -  https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add

Debian利用iso搭建本地软件源

Debian利用iso搭建本地软件源: mount -o loop debian-9.4.0-amd64-DVD-1.iso /space/deb/ vi /etc/apt/source.list (将原有内容注释,前加#) :wq apt-cdrom -m -d /space/deb/ add apt-get update 原文地址:http://blog.51cto.com/yangzhiming/2114562

搭建Debian源基础知识记录

文档一:https://wiki.debian.org/SettingUpSignedAptRepositoryWithReprepro 文档二:http://blog.jonliv.es/2011/04/26/creating-your-own-signed-apt-repository-and-debian-packages/ 搭建Debian源基础知识记录,码迷,mamicode.com

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

Mono软件Ubuntu系统国内镜像源.Mono国内镜像源 http://download.githall.cn/repo 1.授权注册repo源 Ubuntu 18.04 (i386, amd64, armhf, arm64, ppc64el)系统请运行如下命令: sudo apt install gnupg ca-certificates sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 3FA7E0

CentOS,Debian等Linux发行版更新镜像源

安装后CentOS镜像源,默认使用国外的,很慢,你知道的, 国内更换163.aliyun (看了很多人的博客, 今天有空,自己写一篇) 找到想要更换的源的官方网站, 比如 网易163 页脚找到帮助中心 阿里云 找到对应的发行版本,后面有个help可以点击进去看帮助 比如CentOS6使用163镜像 备份系统的配置文件 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup cd /etc/yum.

yum管理——搭建iso镜像私有yum源仓库(1)

在服务器上一般是没有光驱的,那么我们怎么制作iso本地repo镜像源仓库? 通过本地iso镜像,copy到linux系统中一个目录中,进行伪文件系统挂载,执行如下命令: 挂载:mount -o loop -t iso9660 CentOS-7.3-x86_64-DVD-1611.iso 目录名 例如:mount -o loop -t iso9660 CentOS-7.3-x86_64-DVD-1611.iso /mnt 卸载挂载: 例如:umount /mnt 1.在/etc/yum.repos

自建 debian 7 源

由于线上有不少debain 7 操作系统,故准备自建源,方便更新. 使用apt-mirror工具搭建非常方便.它提供了能够反映任何部分(甚至全部)Debian和Ubuntu GNU/Linux发行版或其他来源通常由开源开发者提供. 在debian or ubuntu下使用很简单: $ apt-get install apt-mirror $ nano /etc/apt/mirror.list $ sudo apt-mirror 也可以很容易地设置为手动通过cron或继续跑,当你想更新镜像./et