LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 946|回复: 8

apt-cacher: 下载一次, 用在所有debian上

[复制链接]
发表于 2006-9-11 21:24:47 | 显示全部楼层 |阅读模式
apt-cacher: 下载一次, 用在所有debian上
apt -cacher是一个小巧的软件包, 用来缓冲debian软件包. 如果局域网上有多台debian机器, 通过apt-cacher, 你所安装的软件包, 只需要从互联网上下载一次, 所有的debian机器都可以使用, 看上去就像是所有机器上的apt都是只接从互联网上下载软件包, 然后安装, 并且速度更快.

apt-cacher是包含在debian unstable中, 安装只需要一个命令

apt-get install apt-cacher

安装完成后apt-cacher并不自动起动, 如果希望apt-cacher自动起动, 则需要修改/etc/default/apt-cacher, 将AUTOSTART=1, 然后运行

/etc/init.d/apt-cacher start

或者重启系统.

apt -cacher的配置文件在/etc/apt-cacher/apt-cacher.conf, 比较常用的选项有: daemon_port用来指定apt-cacher监听的地址, http_proxy用来指定代理服务器的地址, cache_dir用来指定软件包缓存的地址, 默认为/var/cache/apt-cacher.

要想通过apt-cacher使用apt, 需要修改apt的配置文件/etc/apt/sources.list, 比如我原先的sources.list中包含

deb http://debian.ustc.edu.cn/debian sid main non-free contrib

则可修改为

deb http://127.0.0.1:3142/debian.ustc.edu.cn/debian sid main non-free contrib

这样, 使用apt然装软件包时, apt就会去访问监听在127.0.0.1:3142上的apt-cacher, 然后由apt-cacher去http://debian.ustc.edu.cn/debian抓取你需要的软件包, 并在本地, 如果有别的机器也需要这个软件包, 则只接将保存在本地的软件包传送给请求的机器.

apt默认情况下会吧软件包保存在 /var/cache/apt/archives中, 安装apt-cacher后, 我们可能希望apt-cacher先将这些包缓冲起来, 避免有客户机访问apt-cacher的时候, apt=cacher重新下载这些包, 这是, 可以将/var/cache/apt/archives中的软件包复制到/var/cache/apt-cacher/import中, 然后运行

/usr/share/apt-cacher/apt-cacher-import.pl

将这些软件包导入到/var/cache/apt-cacher/packages中, 由apt-cacher管理.

由于所有的软件包都在本地网络上有保存, 我们安装完软件包后, 可以运行

apt-get clean

删除保存在/var/cache/apt/archives中的副本.

在debian中除apt-cacher, 还有apt-proxy, approx等软件可以实现类似的功能.

原文地址:
http://www.cublog.cn/u/7667/showart.php?id=169578
对管理多台debian 服务器的兄弟可能会有用一些
发表于 2006-9-12 09:51:17 | 显示全部楼层
网内的其他机器怎么获取这台装了apt-cacher的机子上的包呢?如果都装上apt-cacher,都是一样的设置,那也没啥意义。这篇文章的重点可是没说呀,找了那个连接,同样也是翻译的,而且没个出去,等会google下看看。
回复 支持 反对

使用道具 举报

发表于 2006-9-12 10:01:11 | 显示全部楼层
是不是类似于代理服务器?
回复 支持 反对

使用道具 举报

发表于 2006-9-12 10:35:07 | 显示全部楼层
刚才看了英文介绍,其实也就是server-client模式,英文手册可能有点老了,领会精神就可以了,看了还是不错的,比作镜像简易多了,也是需要apache的。以下是英文手册吧,有两个插图,把它省了。

Apt-cacher Structure

Apt-cacher is different to many other caching systems because rather than being a stand-alone program it runs as a CGI under Apache. That has a number of advantages, such as making it small and simple and therefore more robust because it doesn't need its own protocol-handling code, and also very flexible because you can use Apache's built in access control mechanism in case you want to only let certain machines use your cache.

Apt-cacher itself only needs to be set up on one machine, the one you decide to use as your local cache. Then all computers on your local network have a setting modified to tell them to direct all package requests to your cache machine rather than directly to the package server.

Apt-cacher works by intercepting requests for packages and fetching them on behalf of local machines, while simultaneously storing them on disk in case other machines later ask for the same package. Once set up there is no need to do anything differently to install packages: just install a package on one machine with Apt or Synaptic and it comes off the Internet, then when you install it on other machines it comes from the local cache. Easy!
Installing Apt-cacher

Getting Apt-cacher working involves two parts: setting up the cache server itself, and then telling your local machines to use it.
Server Setup

First select a machine to use as your cache server. Apt-cacher puts very little load on the system so you can safely run it on just about any machine you have available, even one that's normally used as a workstation. Probably the most critical things are to make sure your cache server has a fixed IP address so other computers on your network can find it, and that there is plenty of disk space because the cache itself can become quite large. Disk usage depends on how many packages you have cached, so the greater variety of software you run the more space you will need. A few hundred megabytes is common while large caches may need several gigabytes.

On the machine nominated to be your cache server issue the command

apt-get install apt-cacher

as root, and Apt-cacher will be installed and set up for you. It will also install Apache plus a couple of other packages unless they were already in place. Then just restart Apache by typing

/etc/init.d/apache restart

and you're done. You can test that the installation worked properly by opening a web browser and going to the address 'http://[cache.example.com]/apt-cacher', where [cache.example.com] is the hostname or IP address of your cache server. If all went well you'll see an information page generated by Apt-cacher that looks something like this:

Client Setup

Client machines don't need to have anything installed to use Apt-cacher: they just need to have their list of package sources modified so they send their package requests to the cache server.

The list of package sources is stored in a file called '/etc/apt/sources.list'. If you open this file in a text editor such as Vim or Anjuta you'll see a number of lines that look something like this:

deb http://ftp.au.debian.org/debian unstable main contrib non-free

Each HTTP entry needs to have the address of your cache server prepended, so the example above becomes something like this:

deb http://cache.example.com/apt-cacher/ftp.au.debian.org/debian unstable main contrib non-free

Once you've done that, do

apt-get update

to tell your machine to update its package list, and you're set. Any packages you install from then on will come via the cache server.
Configuration Options

At this point you'll probably have a working installation of Apt-cacher without touching a single config setting on the cache server. However, Apt-cacher has a number of options you can set by editing the file '/etc/apt-cacher/apt-cacher.conf'. You don't need to restart anything after editing the file, all changes are immediate.

The config file is very well commented so for all the gory details just read the file itself, but for reference the items you can set include:
admin_email

The email address displayed in traffic reports and when problems occur.
generate_reports

If this option is set to 1 Apt-cacher will generate a daily traffic report. If set to 0 it won't.
cache_dir

Specifies the location on disk to use for storing cached packages and package lists.
logfile

Specifies the location of the log file used to record package requests. The log file is used by Apt-cacher to generate traffic reports.
errorfile

Specifies the location of the error log. Very useful when debugging problems.
expire_hours

How many hours to keep package lists around before they are deleted from the cache. Note that this doesn't directly affect package expiry: packages are expired on a special algorithm that determines if they still exist in available package lists.
http_proxy

The address and port of an HTTP proxy to use. This allows you to tell Apt-cacher to use an external proxy server if you've got one available. This probably won't save you much bandwidth, but some ISPs give you discounted data rates if you use their proxies.
use_proxy

Specifies whether to activate the http_proxy setting above: 1 is active, 0 is inactive. Make sure you set this to 1 if you want to use http_proxy.
debug

Turns debug mode on or off. When this is turned on Apt-cacher will store heaps of internal information in the errorlog for every package that's requested. This is really only useful for developers, and in normal use should be left at 0 (off).
Reporting and Cleaning

Apt-cacher does scheduled maintenance on itself to generate traffic reports and clean old packages out of the cache.
Traffic Reports

Apt-cacher can be configured to generate traffic reports daily. Generating reports is extremely fast even with a high-traffic cache and only happens once per day, so this option can safely be turned on without impacting performance. To access the report just point your browser at 'http://[cache.example.com]/apt-cacher/report', and you should see something like this:

Cache Cleaning

Over time your cache will start to fill up with old packages that aren't required anymore. Apt-cacher runs a cleanup script every 24 hours to find old packages that are no longer referenced by package lists and delete them from the cache.

While I've covered a lot of options here, you generally won't need to care about any of them: in most situations you can install Apt-cacher and it will just work.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-12 20:24:45 | 显示全部楼层
Post by favoyun
网内的其他机器怎么获取这台装了apt-cacher的机子上的包呢?如果都装上apt-cacher,都是一样的设置,那也没啥意义。这篇文章的重点可是没说呀,找了那个连接,同样也是翻译的,而且没个出去,等会google下看看。


文章是我自己写的, 我有几台虚拟机, 也用vmware sid,  我在host上装了apt-cacher, 在虚拟机上运行apt的时候速度就很快了.

我写了客户机的配置方法, 就是修改 sources.list 文件

ps: apt-cacher是一个perl程序, 不需要apache的支持.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-12 20:26:36 | 显示全部楼层
Post by 超级用户
是不是类似于代理服务器?


很类似, 通过缓存的方式减少了网络流量, 减少了响应时间, 但是只缓存deb软件包及其相关文件, 不是同用代理服务器
回复 支持 反对

使用道具 举报

发表于 2006-9-12 20:53:42 | 显示全部楼层
还有类似的如apt-proxy
回复 支持 反对

使用道具 举报

发表于 2006-9-12 20:54:59 | 显示全部楼层
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-10-31 23:39:01 | 显示全部楼层
我测ÕÇapt-proxy, 最终选择了apt-cacher
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表