个人工具

“AptProxyHowTo”的版本间的差异

来自Ubuntu中文

跳转至: 导航, 搜索
(新页面: == apt-proxy 安装指南 == 原文出处:https://wiki.ubuntu.com/AptProxyHowTo 原文作者: 授权许可: * [http://creativecommons.org/licenses/by-sa/2.0/ 创作共用协议A...)
(没有差异)

2007年5月30日 (三) 18:53的版本

apt-proxy 安装指南

原文出处:https://wiki.ubuntu.com/AptProxyHowTo

原文作者:

授权许可:

翻译人员:leal

校正人员:

贡献人员:

适用版本:所有 文章状态:等待校正



apt-proxy是一个用于apt的代理,它可以在你的硬盘上创建一个远程仓库的完整副本。

导言

apt-proxy是一个用于apt的代理,它可以在你的硬盘上创建一个远程仓库的完整副本。由于apt-proxy行为类似一个带有仓库的HTTP服务器,因此你可以在内部网的其它机器上访问这些包。如果cache中缺少某个包,apt-proxy会自动下载该包并把它放到cache中。如果你得一遍又一遍的安装 包(也即upgrade或dist-upgrade你的所有机器),apt-proxy可以很大程度上减少下载带宽和安装时间。

apt-proxy的当前不稳定版本可以从 hoary universe 仓库获得 (参见: 如何-访问 "universe" 仓库) 你可以通过如下命令快捷安装apt-proxy:

apt-get install apt-proxy/hoary

配置

若要使用apt-proxy,你必须更改apt的sources.list和apt-proxy的配置文件。

apt-proxy-v2.conf

/etc/apt-proxy/apt-proxy-v2.conf 的第一段包含了这个代理(apt-proxy)和其cache的缺省设置。

最应该做的更改是把地址(address)参数设置成适合你的值,也即你的代理服务器在内部网络的IP地址。端口(port)参数指定了apt-proxy要在哪个端口侦听请求,缺省值是9999,如果和系统其它设置不相冲突,那就最好别做改变。

也许你想把仓库的cache目录设置成 /var/cache/apt-proxy 之外的目录,改变cache_dir参数可达此目的。

如果你正在使用一个普通代理(general proxy),设置http_proxy == proxy_server:port你可以令apt-proxy知道其存在。如果你处于防火墙后,那么试图连接到FTP后端时,使用主动(active) FTP连接可能会遇到问题。设置passive_ftp == on应该能解决这个问题。

其它一些值控制包留存在cache中的时间、至少多久之后才让apt-proxy检查某个包的更新版本,或者在cache中检查旧包的频率(??need improve)。这些设置一般使用缺省值即可。

apt-proxy必须知道远端仓库的位置,即后端(backend)。可以在 /etc/apt-proxy/apt-proxy-v2.conf 的backend段中进行设置。ubuntu所用的backend项示例如下:

[ubuntu]
;; Ubuntu archive
backends =
http://archive.ubuntu.com/ubuntu
http://de.archive.ubuntu.com/ubuntu

如你所见,可以指定不止一个服务器,由空格分隔。如果第一个服务器失效,apt-proxy会试着从第二个服务器获取数据,依此类推。你也可以根据default段的值集进行设置。比如,如果你知道某个服务器需很长时间应答请求,就可以增大timeout值:

[ubuntu-slow]
timout = 60 ;wait 1 Minute
backends = prot://some.very.slow.server.net/ubuntu-slow

完整的 apt-proxy-v2.conf 文件(这个是我的)和如下类似:

[DEFAULT]
;; All times are in seconds, but you can add a suffix
;; for minutes(m), hours(h) or days(d)

address = 127.0.0.1
port = 9999
cache_dir = /var/cache/apt-proxy

;; Control files (Packages/Sources/Contents) refresh rate
min_refresh_delay = 1s
complete_clientless_downloads = 1

;; Debugging settings.
debug = all:4 db:0

timeout = 30
passive_ftp = on

;;--------------------------------------------------------------
;; Cache housekeeping

cleanup_freq = 1d
max_age = 120d
max_versions = 3

;;---------------------------------------------------------------
;; Backend servers
;;
;; Place each server in its own [section]

[ubuntu]
; Ubuntu archive
backends =
http://archive.ubuntu.com/ubuntu
http://de.archive.ubuntu.com/ubuntu

[ubuntu-security]
; Ubuntu security updates
backends = http://security.ubuntu.com/ubuntu

[marillat]
backends = ftp://ftp.nerim.net/debian-marillat

[debian]
; Backend servers, in order of preference
backends =
http://ftp.us.debian.org/debian
http://ftp.de.debian.org/debian
http://ftp2.de.debian.org/debian
ftp://ftp.uk.debian.org/debian

[debian-non-US]
; Debian debian-non-US archive
backends =
http://ftp.uk.debian.org/debian-non-US
http://ftp.de.debian.org/debian-non-US
ftp://ftp.uk.debian.org/debian

[security]
; Debian security archive
backends =
http://security.debian.org/debian-security
http://ftp2.de.debian.org/debian-security

[openoffice]
; OpenOffice.org packages
backends =
http://ftp.freenet.de/pub/debian-openoffice
http://ftp.sh.cvut.cz/MIRRORS/OpenOffice.deb
http://borft.student.utwente.nl/debian

[apt-proxy]
; Apt-proxy new versions
backends = http://apt-proxy.sourceforge.net/apt-proxy

sources.list

现在,apt 必须知道系统上存在 apt-proxy 这玩意,并且可以从它那儿获取安装包,而非直接下载这些包。最好的办法是把 sources.list 里的所有直接服务器(注:即外部服务器,非内网)都注释掉,以确保apt-get决不会试图从这些服务器上直接获取包。然后添加 apt-proxy 设置,它们看上去和普通 apt 仓库相似,只不过你总是必须在其后添加 backend 段名(即 apt-proxy-v2.conf 中方括号内的所有项)以组成路径:

deb http://apt-proxy:port/backend dist component

如果你的 apt-proxy 和我的一样侦听 localhost 的 9999 端口,你可以指定一个 ubuntu 段,还有源(代码)行和如下类似:

deb http://localhost:9999/ubuntu hoary main restricted universe multiverse
deb-src http://localhost:9999/ubuntu hoary main restricted universe multiverse
<sup>^^^^</sup>
这是 backend 段(即[ubuntu])

在你更改apt-proxy配置文件后,你必须通过sudo操作重启这个代理:

/etc/init.d/apt-proxy restart

和上述 apt-proxy-v2.conf 对应的完整的 sources.list 如下:

# apt-proxy entries for standard modules
deb http://localhost:9999/ubuntu hoary main restricted universe multiverse
deb-src http://localhost:9999/ubuntu hoary main restricted universe multiverse

# apt-proxy entries for security patches
deb http://localhost:9999/ubuntu-security hoary-security main restricted universe multiverse
deb-src http://localhost:9999/ubuntu-security hoary-security main restricted universe multiverse

# additional repositories
deb http://localhost:9999/marillat unstable main

# debian packages
deb http://localhost:9999/debian unstable main contrib non-free
deb http://localhost:9999/debian-non-US unstable/non-us main contrib non-free
deb http://localhost:9999/security sid main contrib non-free

初始化apt-proxy

现在运行apt-get update来初始化apt-proxy的cache并把新的列表存入cache中。于是你便可以按老样子使用apt-*,好像根本没apt-proxy这玩意。 导入apt的cache

如果你之前已经用 apt-get 下载过包,这些包会缓存在 /var/cache/apt/archives 目录里。根据当前的包列表,你可以用 apt- proxy-import 把这些包导入到 apt-proxy cache 中。因此你应该首先运行 apt-get update 得到最新列表,然后只需简单运行如下命令:

apt-proxy-import -r -i /var/cache/apt/archives

这样apt-proxy就会把apt cache里的所有包导入到它自己的cache中。

链接