[翻译]使用apt-mirror建立局域网内的Debian/Ubuntu源镜像

系统安装、升级讨论
版面规则
我们都知道新人的确很菜,也喜欢抱怨,并且带有浓厚的Windows习惯,但既然在这里询问,我们就应该有责任帮助他们解决问题,而不是直接泼冷水、简单的否定或发表对解决问题没有任何帮助的帖子。乐于分享,以人为本,这正是Ubuntu的精神所在。
回复
icyfire
帖子: 13
注册时间: 2006-07-22 8:57

[翻译]使用apt-mirror建立局域网内的Debian/Ubuntu源镜像

#1

帖子 icyfire » 2007-02-19 22:30

第一次翻译,翻译得不好还请大家见谅,多多指出错误~!:)
原文可以见如下的贴子:viewtopic.php?t=40082&highlight=%E7%BF%BB%E8%AF%91
使用apt-mirror建立局域网内的Debian/Ubuntu源镜像
Version 1.0
Author: Falko Timme <ft [at] falkotimme [dot] com>
Last edited 12/26/2006
翻译:icyfire ([email protected]

本教程将指导你如何利用apt-mirror建立局域网内的Debian/Ubuntu源镜像。如果你需要在局域网内安装多套系统,那么建立一个本地的Debian/Ubuntu源镜像将会有益,在您更新系统的时候将获得比互联网连接快得多的速度,而且还能节省您的互联网带宽。

我首先想说的是本文所讲的方法并不是唯一建立Debian/Ubuntu源镜像的方法。有很多方法可以达成这个目标,但是这却是我采用的办法。我并不保证这个方法适用于您。

1 前期准备
你可以在debian和ubuntu系统上建立Debian/Ubuntu源镜像,也就是说,debian系统可以建立Debian和Ubuntu源镜像,ubuntu系统上也能建立Debian和Ubuntu源镜像。

需要注意的是要建立一个源镜像你需要有一个快一点的连接和足够大的硬盘空间。在我的测试过程中我做了一个Debian Sarge的main,contrib 和non-free部分的镜像和 Ubuntu Edgy Eft的 main, restricted, universe部分的镜像,这总共占用了大概25G的硬盘空间,在16M的DSL的带宽下,花了6小时的时间才下载完。

我没有建立安全部分的镜像,因为我认为直接从互联网上下载安全更新会更好一点,因为这样可以保证你总能获得最新的版本。

本测试基于 Debian Sarge 和Ubuntu Edgy Eft操作系统,如果你使用的是其他的版本,那么这个步骤可能会有细微的差异。你需要安装一个基本的 Debian Sarge 系统(安装步骤 http://www.howtoforge.com/perfect_setup_debian_sarge)或者 Ubuntu Edgy Eft系统(安装步骤http://www.howtoforge.com/perfect_setup_ubuntu_6.10
这个例子中本地源镜像的ip是192.168.0.100.

2,1安装apt-mirror
修改/etc/apt/sources.list(Debian Sarge必须)
如果你安装的是 Debian Sarge,你必须要修改sources.list.我不清楚Debian Etch 或者 Sid是否必须要修改,你可以自己尝试一下。对Ubuntu Edgy Eft. 这一步不适必须的。

代码: 全选

vi /etc/apt/sources.list 
加入下面怪这一行。

代码: 全选

deb http://apt-mirror.sourceforge.net/ apt-mirror/ 
然后执行:

代码: 全选

apt-get update 
2.2安装apt-mirror
这一步对Debian和Ubuntu都是必须的,安装apt-mirror,执行

代码: 全选

apt-get install apt-mirror 
3安装阿帕奇。
我想要通过http的方式获得本地Debian/Ubuntu的源镜像,因此需要安装apache web服务器。

代码: 全选

apt-get install apache2 
默认的根目录是/var/www,接下来我会symlink这个目录到Debian and Ubuntu 的软件仓库所在目录。

4配置apt-mirror
apt-mirror的配置文件在/ etc/apt/mirror.list,debian sarge中的默认配置文件如下:
# apt-mirror configuration file

##
## The default configuration options (uncomment and change to override)
##
#
# 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 defaultarch
# set nthreads 20
#


##
## Example sources
##

# sarge's section
deb http://ftp.fi.debian.org/debian sarge main contrib non-free
deb-src http://ftp.fi.debian.org/debian sarge main contrib non-free

deb http://security.debian.org/debian-security sarge/updates main contrib non-free
deb-src http://security.debian.org/debian-security sarge/updates main contrib non-free

deb http://ftp.fi.debian.org/debian sarge main/debian-installer


# sarge-proposed-updates's section
deb http://ftp.fi.debian.org/debian sarge-proposed-updates main contrib non-free
deb-src http://ftp.fi.debian.org/debian sarge-proposed-updates main contrib non-free


# sid's section
deb http://ftp.fi.debian.org/debian sid main contrib non-free
deb-src http://ftp.fi.debian.org/debian sid main contrib non-free

deb http://ftp.fi.debian.org/debian sid main/debian-installer


# experimental section
deb http://ftp.fi.debian.org/debian ../project/experimental main contrib non-free
deb-src http://ftp.fi.debian.org/debian ../project/experimental main contrib non-free


##
## Cleaner configuration example
##
#
# set cleanscript $var_path/clean.sh
#

# Cleaning section
clean http://security.debian.org/
clean http://ftp.fi.debian.org/


skip-clean http://ftp.fi.debian.org/doc/
skip-clean http://ftp.fi.debian.org/tools/
skip-clean http://ftp.fi.debian.org/debian-cd/
skip-clean http://ftp.fi.debian.org/debian-minicd/
skip-clean http://ftp.fi.debian.org/debian/dists/s ... ller-i386/
skip-clean http://ftp.fi.debian.org/debian/dists/s ... ller-i386/
skip-clean http://ftp.fi.debian.org/debian/doc/
skip-clean http://ftp.fi.debian.org/debian/tools/
skip-clean http://ftp.fi.debian.org/debian/project/
skip-clean http://ftp.fi.debian.org/debian-non-US/project/
Ubuntu Edgy Eft中的默认文件如下:
############# config ##################
#
# set base_path /var/spool/apt-mirror
#
# if you change the base path you must create the directories below with write privlages
#
# 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
set nthreads 20
set tilde 0
#
############# end config ##############

deb http://archive.ubuntu.com/ubuntu edgy main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu edgy-updates main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu edgy-backports main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu edgy-security main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu edgy-proposed main restricted universe multiverse

deb-src http://archive.ubuntu.com/ubuntu edgy main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu edgy-updates main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu edgy-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu edgy-security main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu edgy-proposed main restricted universe multiverse

clean http://archive.ubuntu.com/ubuntu
如果你对比/etc/apt/sources.list 和/etc/apt/mirror.list,你会发现两者非常相似,二者都列举了一些应当被镜像的软件库,另外还有一些其他选项。
现在我修改/etc/apt/mirror.list.就象我前面说过的一样,我要镜像Debian Sarge的main,contrib 和non-free部分和 Ubuntu Edgy Eft的 main, restricted, universe部分
,不镜像应该直接从互联网上下载的安全部分。另外,我也没有镜像源代码包,因为95%的安装文件不需要源代码,而源代码包文件又会占据巨大的硬盘空间。所以我的/etc/apt/mirror.list 修改成下面的样子:

代码: 全选

vi /etc/apt/mirror.list 

# apt-mirror configuration file

##
## The default configuration options (uncomment and change to override)
##
#
# 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 defaultarch
# set nthreads 20
#


##
## Example sources
##

# sarge's section
deb http://ftp.de.debian.org/debian sarge main contrib non-free

# Ubuntu Edgy Eft
deb http://de.archive.ubuntu.com/ubuntu/ edgy main restricted universe

##
## Cleaner configuration example
##
#
# set cleanscript $var_path/clean.sh
#

# Cleaning section
clean http://ftp.de.debian.org/
clean http://de.archive.ubuntu.com/
请注意我用ftp.de.debian.org 代替了ftp.fi.debian.org ,用 de.archive.ubuntu.com代替了
archive.ubuntu.com. 你应该选择一个距离你比较近的镜像,所以如果你在美国,就用us替代de。

最后的cleaning部分告诉apt-mirror本地的硬盘应该和哪个软件仓库对比以确定哪些文件可以自动清除掉。我要检查Debian 和Ubuntu全部的软件,所以我修改成了,

clean http://ftp.de.debian.org/
clean http://de.archive.ubuntu.com/

如果你使用了其他的 Debian/Ubuntu版本,请用etch或者sid替换sarge;breezy或者dapper替换edgy。

5创建本地软件仓库
现在apt-mirror已经配置好了,现在应该第一次运行它,下载所有的包构建本地的Debian/Ubuntu软件仓库。我们只需要执行:

代码: 全选

su - apt-mirror -c apt-mirror 
[/eode]
apt-mirror会告诉你到底要下载多少GB的文件。这将会花上几个小时,所以要耐心点。这些包将会存储在/var/spool/apt-mirror/mirror的子目录中,所以你要保证该分区还有足够的硬盘空间。
debian的在/var/spool/apt-mirror/mirror/ftp.de.debian.org/debian,
unbuntu的在/var/spool/apt-mirror/mirror/de.archive.ubuntu.com/ubuntu.
如果你在第四步选择了一个不同的镜像,那么这个路径或许有些不同。

6清理软件仓库
等到apt-mirror下载完了所有的包,它非常可能会告诉你可以清除出一些硬盘空间来,使用以下脚本:
/bin/bash /var/spool/apt-mirror/var/clean.sh 
输出如下:
server1:~# /bin/bash /var/spool/apt-mirror/var/clean.sh 
Removing 157 unnecessary files [13316096 bytes]... 
[0%]................done. 

Removing 18 unnecessary directories... 
[0%]..................done. 

这样你就能看到有多少硬盘空间被清理出来了。

7 更新本地软件仓库
更新本地镜像是非常简单的,执行
[code]su - apt-mirror -c apt-mirror 
如果你不想手工执行更新,那么你可以编写一个定时执行的corn任务。只需要编辑/etc/corn.d/apt-mirror,在最后一行添加如下即可:

代码: 全选

vi /etc/cron.d/apt-mirror 
#
# Regular cron jobs for the apt-mirror package
#
0 4 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log
8 通过http访问镜像

Apache默认的根目录是/var/www,但是软件仓库却在/var/spool/apt-mirror/mirror
为了能够通过 http://192.168.0.100/debian and http://192.168.0.100/ubuntu
访问到相应的软件库,我们可以symlinks /var/www/debian and /var/www/ubuntu到真正的库地址。

代码: 全选

ln -s /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian /var/www/debian 
ln -s /var/spool/apt-mirror/mirror/de.archive.ubuntu.com/ubuntu /var/www/ubuntu
如果你使用了其他镜像,记得调整这两行命令。

接下来要考虑的一件事情是,你认为DebianSarge是sarge而且是稳定的e(至少目前是稳定的,而Etch仍旧在测试中),那么当你运行

代码: 全选

ls -l /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian/dists 
你会发现那里有一个sarge的目录,但却是不稳定的,但是如果你在source.list中用稳定的替换了 sarge,或者在本地全新安装一个debian系统,这样就会出现这样的问题debian sarge的安装工具仍旧会认为stable替换sarge。解决办法是

代码: 全选

cd /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian/dists 
ln -s sarge/ stable
当debian Etch变成稳定版本的时候你也可以镜像Etch。到时候不要忘了修改stable的symlink。

代码: 全选

cd /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian/dists 
rm -f stable 
ln -s etch/ stable 
这个问题不会出现在ubuntu中。

9 配置你的客户端电脑使用本地镜像
现在本地镜像已经可以使用了,我们所要做得是告诉 Debian Sarge和Ubuntu Edgy Eft 系统如何使用本地镜像。

Debian Sarge系统,在source。list中修改main,contrib,non-free的软件仓库
vi /etc/apt/sources.list


[...]
deb http://192.168.0.100/debian sarge main contrib non-free
[...]

Instead of sarge you could also use stable:

[...]
deb http://192.168.0.100/debian stable main contrib non-free
[...]

然后运行:
apt-get update

在 Ubuntu Edgy Eft系统中,你可以在sources.list中更换 main restricted universe的软件仓库。
vi /etc/apt/sources.list
[...]
deb http://192.168.0.100/ubuntu/ edgy main restricted universe
[...]

然后运行:
apt-get update

9.3 全新安装系统
如果你从本地镜像全新安装一个 Debian Sarge 或者 Ubuntu Edgy Eft那么你可以按照以下步骤进行:







10相关链接

* apt-mirror: http://apt-mirror.sourceforge.net
* Debian: http://www.debian.org
* Ubuntu: http://www.ubuntu.com
icyfire
帖子: 13
注册时间: 2006-07-22 8:57

#2

帖子 icyfire » 2007-02-19 22:37

daniel
帖子: 24
注册时间: 2006-06-18 17:51

#3

帖子 daniel » 2007-03-02 16:49

太感谢了!
wsh9308
帖子: 15
注册时间: 2007-03-27 13:18

#4

帖子 wsh9308 » 2007-03-27 20:17

谢谢楼主共享
头像
dsdsdds
帖子: 523
注册时间: 2007-04-05 21:22

Re: [翻译]使用apt-mirror建立局域网内的Debian/Ubuntu源镜像

#5

帖子 dsdsdds » 2008-09-22 17:58

太赞了,谢谢楼主!
授人以鱼,不如授人以渔。
头像
anriqing
帖子: 189
注册时间: 2008-08-19 12:59

Re: [翻译]使用apt-mirror建立局域网内的Debian/Ubuntu源镜像

#6

帖子 anriqing » 2008-12-14 14:41

我上午刚把这篇文章的英文版看完,早知道有人翻译过,就直接看中文版的了。
Windows Vista Ultimate SP1 CHS + Ubuntu 8.04.1 desktop i386

CPU:Intel Core 2 Duo T7250 RAM:2048MB DDR2-667
VGA:NVidia Geforce 8400M GS 128MB HD:SumSung 160G 5400R
LAN:Broadcom NetLink WIFI:Intel 3945ABG
WebCam:2.0M
Mr.noodles
帖子: 11
注册时间: 2011-12-08 13:08

Re: [翻译]使用apt-mirror建立局域网内的Debian/Ubuntu源镜像

#7

帖子 Mr.noodles » 2012-03-02 13:28

求教,怎么把自己打包的软件,或其他开源软件添加到镜像站里面?
rockslee
帖子: 1
注册时间: 2016-11-14 10:50
系统: win10

Re: [翻译]使用apt-mirror建立局域网内的Debian/Ubuntu源镜像

#8

帖子 rockslee » 2016-11-14 10:56

当做好源以后我执行apt-get update 出现如下报错:
Ign:50 http://192.168.1.127/ubuntu xenial-backports/main i386 Packages
Ign:51 http://192.168.1.127/ubuntu xenial-backports/main all Packages
Ign:52 http://192.168.1.127/ubuntu xenial-backports/main Translation-en_US
Ign:53 http://192.168.1.127/ubuntu xenial-backports/main Translation-en
Ign:54 http://192.168.1.127/ubuntu xenial-backports/restricted amd64 Packages
Ign:55 http://192.168.1.127/ubuntu xenial-backports/restricted i386 Packages
Ign:56 http://192.168.1.127/ubuntu xenial-backports/restricted all Packages
Ign:57 http://192.168.1.127/ubuntu xenial-backports/restricted Translation-en_US
Ign:58 http://192.168.1.127/ubuntu xenial-backports/restricted Translation-en
Ign:59 http://192.168.1.127/ubuntu xenial-backports/universe amd64 Packages
Err:69 http://192.168.1.127/ubuntu xenial-security/main amd64 Packages
404 Not Found
Ign:70 http://192.168.1.127/ubuntu xenial-security/main i386 Packages
Ign:71 http://192.168.1.127/ubuntu xenial-security/main all Packages
Ign:72 http://192.168.1.127/ubuntu xenial-security/main Translation-en_US
Ign:73 http://192.168.1.127/ubuntu xenial-security/main Translation-en
Ign:74 http://192.168.1.127/ubuntu xenial-security/restricted amd64 Packages
Ign:75 http://192.168.1.127/ubuntu xenial-security/restricted i386 Packages
Ign:76 http://192.168.1.127/ubuntu xenial-security/restricted all Packages
Ign:77 http://192.168.1.127/ubuntu xenial-security/restricted Translation-en_US
Ign:78 http://192.168.1.127/ubuntu xenial-security/restricted Translation-en
Hit:79 http://ppa.launchpad.net/openjdk-r/ppa/ubuntu xenial InRelease
Hit:80 https://deb.nodesource.com/node_4.x xenial InRelease
Reading package lists... Done
W: The repository 'http://192.168.1.127/ubuntu xenial Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: The repository 'http://192.168.1.127/ubuntu xenial-updates Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: The repository 'http://192.168.1.127/ubuntu xenial-backports Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
W: The repository 'http://192.168.1.127/ubuntu xenial-security Release' does not have a Release file.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
E: Failed to fetch http://192.168.1.127/ubuntu/dists/xenia ... 4/Packages 404 Not Found
E: Failed to fetch http://192.168.1.127/ubuntu/dists/xenia ... 4/Packages 404 Not Found
E: Failed to fetch http://192.168.1.127/ubuntu/dists/xenia ... 4/Packages 404 Not Found
E: Failed to fetch http://192.168.1.127/ubuntu/dists/xenia ... 4/Packages 404 Not Found
E: Some index files failed to download. They have been ignored, or old ones used instead.

有谁遇到过吗?
poloshiao
论坛版主
帖子: 18279
注册时间: 2009-08-04 16:33

Re: [翻译]使用apt-mirror建立局域网内的Debian/Ubuntu源镜像

#9

帖子 poloshiao » 2016-11-14 17:37

瀏覽器 firefox 輸入
http://192.168.1.127/
什麼結果 ?
回复