| ||
|
| Linux首页 | Linux论坛 | 论坛精华 | 开源新闻 | 技术文章 | 专题专栏 | 新手指南 | 迁移方案 | 产品方案 | 开源项目 | 开源图书 | 软件下载 | 人才招聘 | Linux博客 |
| 您的位置:
Linux时代 > 技术文档 > 网络通讯 >
使用apt-mirror构建本地Debian镜像
Version 1.0 本教程将为你演示如何使用apt-mirror这个工具为本地网络建立一个Debian/Ubuntu镜像。因为假如你要为本地多台Ubuntu或者Debian机器安装或者升级,先在本地网络上建好一个镜像是非常有必要的,因为这样将大大的节省你的网络带宽。 This tutorial shows how to create a Debian/Ubuntu mirror for your local network with the tool apt-mirror. Having a local Debian/Ubuntu mirror is good if you have to install multiple systems in your local network because then all needed packages can be downloaded over the fast LAN connection, thus saving your internet bandwidth. I want to say first that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!
1 Preliminary NoteYou can set up a Debian and Ubuntu mirror on both Debian and Ubuntu systems, i.e., a Debian system can be a Debian and a Ubuntu mirror, as well as a Ubuntu system can be a Ubuntu and a Debian mirror. Please note that you need a fast internet connection to download all the packages to your mirror as well as a lot of hard disk space. In my tests I mirrored the main, contrib, and non-free sections of Debian Sarge and the main, restricted, and universe sections of Ubuntu Edgy Eft which took about 25GB of hard disk space and about 6 hours of download time on a 16MBit DSL line. I will not mirror security updates in this tutorial - I think it's a good idea to always download security updates directly from the internet. That way you can be sure you get the latest ones. I've tested this on a Debian Sarge and a Ubuntu Edgy Eft system. If you use different Debian/Ubuntu versions, the procedure might differ a little bit. You should have already set up a basic Debian Sarge system (e.g. as outlined on pages one and two of http://www.howtoforge.com/perfect_setup_debian_sarge) or a basic Ubuntu Edgy Eft system (e.g. as outlined on pages one to three of http://www.howtoforge.com/perfect_setup_ubuntu_6.10). In this example my local mirror has the IP address 192.168.0.100.
2 Install apt-mirror2.1 Modify /etc/apt/sources.list (Debian Sarge only)If you are on Debian Sarge, you must modify /etc/apt/sources.list to install apt-mirror. I don't know if this is necessary on Debian Etch or Sid, please try it yourself. This step is not necessary for Ubuntu Edgy Eft. vi /etc/apt/sources.list Please add the following line to the file:
Then update the packages database: apt-get update
2.2 Install apt-mirrorThis step is for all systems (Debian and Ubuntu). To install apt-mirror, please run apt-get install apt-mirror
3 Install ApacheLater on, I want to access my new local Debian/Ubuntu mirror over http, therefore I install the Apache web server now: apt-get install apache2 The default document root is /var/www, I will create symlinks from that directory to the location of the Debian and Ubuntu repository later on.
4 Configure apt-mirrorapt-mirror's configuration file is /etc/apt/mirror.list. There should already be a default configuration in it; on Debian Sarge the file looks like this:
On Ubuntu Edgy Eft, the file looks like this:
If you compare the file with /etc/apt/sources.list, you will see that it's very similar. /etc/apt/mirror.list mainly lists the repositories that should be mirrored, plus a few other options. Now we modify /etc/apt/mirror.list. As I said before, I want to mirror the main, contrib, and non-free sections of Debian Sarge and the main, restricted, and universe sections of Ubuntu Edgy Eft, but I don't want to mirror the security updates as these should be downloaded directly from the internet. Also, I don't want to mirror the source packages because in 95% of all installations you don't need source packages, and they need a lot of space on the hard disk. So my /etc/apt/mirror.list looks like this: vi /etc/apt/mirror.list
Please note that I used ftp.de.debian.org instead of ftp.fi.debian.org and de.archive.ubuntu.com instead of archive.ubuntu.com. You should use mirrors that are close to you, so if you are in the U.S., for example, replace de with us, and so on. The cleaning section at the end tells apt-mirror in which directories on the local hard disk it should check to see if hard disk space can be freed. I want to check the whole local repositories for both Debian and Ubuntu, therefore I specify clean http://ftp.de.debian.org/ If you want to use other Debian/Ubuntu versions, simply replace sarge with etch or sid and edgy with breezy, dapper, etc. 5 Create The Local RepositoriesNow that apt-mirror is configured, it's time to run it for the first time and download all the packages that form the local Debian and Ubuntu repository. All we have to do is type su - apt-mirror -c apt-mirror apt-mirror tells you how many GB it must download. This can take a few hours, so be patient. The packages will be stored in subdirectories of the /var/spool/apt-mirror/mirror directory, so make sure the partition that holds that directory has enough disk space left. The Debian repository will be in /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian, and the Ubuntu repository will be in /var/spool/apt-mirror/mirror/de.archive.ubuntu.com/ubuntu. If you used different mirrors in chapter 4, the paths will be a little bit different for you.
6 Clean Up The Local RepositoriesAfter apt-mirror has finished downloading all packages, it will most likely tell you can free up some disk space with the /var/spool/apt-mirror/var/clean.sh script. That's what we do now: /bin/bash /var/spool/apt-mirror/var/clean.sh The output will look like this: server1:~# /bin/bash /var/spool/apt-mirror/var/clean.sh Removing 18 unnecessary directories... As you see, some MB have been freed.
7 Update The Local Repositories / Create A Daily Cron JobUpdating the local mirror is easy. Simply run su - apt-mirror -c apt-mirror again. If you don't want to do it manually, you can create a daily cron job for it. Simply edit /etc/cron.d/apt-mirror and uncomment the last line in it so that it looks like this: vi /etc/cron.d/apt-mirror
This will make apt-mirror run at 4.00h each day, and it will log to /var/spool/apt-mirror/var/cron.log.
8 Make The Local Mirrors Accessible Over HTTPThe default Apache document root under Debian and Ubuntu is /var/www, but our repositories are stored in /var/spool/apt-mirror/mirror. In order to make our repositories accessible by http://192.168.0.100/debian and http://192.168.0.100/ubuntu (in this tutorial 192.168.0.100 is the IP address of our local mirror), we create the symlinks /var/www/debian and /var/www/ubuntu that point to the real repositories: ln -s /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian /var/www/debian Remember to adjust these commands if you use different mirrors than ftp.de.debian.org and de.archive.ubuntu.com. The next thing to consider is that you can refer to Debian Sarge as sarge, but also as stable (at the time of this writing Debian Sarge is stable and the upcoming Debian Etch still testing). When you run ls -l /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian/dists you will see that there is a directory called sarge, but not stable. If you use stable instead of sarge in /etc/apt/sources.list or install a new Debian system with the local mirror, this is a problem (the Debian Sarge installer also refers to stable instead of sarge). The solution is to create a symlink: cd /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian/dists Remember to adjust this command if you use a different mirror than ftp.de.debian.org. At the time Debian Etch becomes stable and you decide to mirror Etch as well, don't forget to change the stable symlink, e.g. like this: cd /var/spool/apt-mirror/mirror/ftp.de.debian.org/debian/dists We don't have this problem with Ubuntu as there's no stable, only breezy, dapper, edgy, etc. 9 Configure Your Client Computers To Use The Local MirrorNow that our local mirror is ready to be used, all we have to do is tell our Debian Sarge and Ubuntu Edgy Eft systems in our local network to use it.
9.1 Debian SargeOn Debian Sarge systems, you can replace the main contrib non-free repository in /etc/apt/sources.list like this: vi /etc/apt/sources.list
Instead of sarge you could also use stable:
Afterwards, run apt-get update
9.2 Ubuntu Edgy EftOn Ubuntu Edgy Eft systems, you can replace the main restricted universe repository in /etc/apt/sources.list like this: vi /etc/apt/sources.list
Afterwards, run apt-get update
9.3 Fresh InstallationIf you install a fresh Debian Sarge or Ubuntu Edgy Eft system, specify your local mirror like this when the installer asks you which repository you'd like to use:
Afterwards the installer will use your local mirror to install the system:
10 Links
本文被浏览次
| |||||||||||||||||||
| 关于我们 | 联系方式 | 广告合作 | 诚聘英才 | 网站地图 | 免费注册 |
Copyright © 2001-2006 ChinaUnix.net All Rights Reserved 感谢所有关心和支持过ChinaUnix的朋友们 |