ubuntu 源镜像学习笔记
Posted 2 years, 5 months ago at 11:32 am. 0 comments
原文 How To Create A Local Debian/Ubuntu Mirror With apt-mirror
类似 windows 系统的SUS机制,ubuntu如果在公司范围内大量使用,到外网重复下载、update,费时费力…
笔记如下:
1. 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.
不包括security的源目前大约25G。
2. This step is for all systems (Debian and Ubuntu). To install apt-mirror, please run
apt-get install apt-mirror
安装 apt-mirror
3. Later 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.
安装 apache2,后面再加入 symlinks。
4. apt-mirror’s configuration file is /etc/apt/mirror.list. There should already be a default configuration in it;On Ubuntu Edgy Eft, the file looks like this:
############# 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
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/
clean http://de.archive.ubuntu.com/
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 Repositories 创建本地源
Now 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 Repositories 清理本地源
After 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 157 unnecessary files [13316096 bytes]…
[0%]…………….done.
Removing 18 unnecessary directories…
[0%]………………done.
As you see, some MB have been freed.
7. Update The Local Repositories / Create A Daily Cron Job
更新本地源/创建cron计划任务
Updating 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
#
# Regular cron jobs for the apt-mirror package
#
0 4 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log
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 HTTP
创建http访问
The 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
ln -s /var/spool/apt-mirror/mirror/de.archive.ubuntu.com/ubuntu /var/www/ubuntu
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
ln -s sarge/ stable
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
rm -f stable
ln -s etch/ stable
We don’t have this problem with Ubuntu as there’s no stable, only breezy, dapper, edgy, etc.
9. 配置 Ubuntu Edgy Eft 使用本地源
On Ubuntu Edgy Eft systems, you can replace the main restricted universe repository in /etc/apt/sources.list like this:
vi /etc/apt/sources.list
…
deb http://192.168.0.100/ubuntu/ edgy main restricted universe
…
Afterwards, run
apt-get update
Fresh Installation 初次安装设置源,参考下图


更多资料:
http://apt-mirror.sourceforge.net
No Replies
Feel free to leave a reply using the form below!