制作镜像://mirrors.ubuntu.com高度可用

我们是一个分布式团队,这就是我们的VM使用Ubuntu mirror:// setup的原因。 我们的/etc/apt/sources.list如下所示:

 deb mirror://mirrors.ubuntu.com/mirrors.txt lucid main restricted universe multiverse deb mirror://mirrors.ubuntu.com/mirrors.txt lucid-updates main restricted universe multiverse deb mirror://mirrors.ubuntu.com/mirrors.txt lucid-backports main restricted universe multiverse deb mirror://mirrors.ubuntu.com/mirrors.txt lucid-security main restricted universe multiverse 

对于在不同地点工作的人来说,这本身就非常了不起并且非常有用 – 必要的本地定制等。 理论上的故障转移。

在日常工作中,此设置过于频繁。 我想说本周2-3次。

现在, mirrors.ubuntu.comftp.uni-bayreuth.de作为我的壁橱镜子返回。 不幸的是,它似乎已经失败了。

这已经持续了几个小时,镜子由一所大学的志愿者主持,今天是一个星期五,我的希望很低,很快就会得到纠正。

所有的谈话,我的问题是:

  • 有没有人用这个?
  • 你如何解决停机问题? (我的快速修复是一个shell脚本)
  • 我该如何帮助改善这种情况?

我个人认为选择最好的Ubuntu存储库镜像的最佳方法是使用GUI方法:

下载服务器

现在,为了改善问题中描述的情况,您需要以某种方式设置一些规则。 这些规则必须作用于mirrors.ubuntu.com 。 我可以建议一些规则如下:

  • 列出最佳/首选镜像; 你可以在这里 , 这里或这里看到很多镜子
  • 如果你找到一个好镜子,把它添加到列表中
  • 如果镜子有时掉下或损坏,这意味着它不是一个好镜子,你应该从列表中删除它
  • 你可以使用netselectapt-spyapt-fast
  • 和其他人,取决于您的要求。

接下来,为了了解如何解决这个问题,我可以通过三个bash脚本示例逐步介绍一个方法。 第一个脚本使用您当前所在国家/地区的镜像而不是mirrors.ubuntu.com/mirrors.txt (对于每个国家/地区,都有一个带有镜像的文本文件;请参阅http://mirrors.ubuntu.com/ ) :

  • 在终端运行mkdir -p bin – 如果您还没有它,则此命令将在您的home文件夹中创建一个bin目录。
  • 运行gedit ~/bin/change_sources.sh – 这将在gedit中创建新文件change_sources.sh
  • 复制并粘贴新创建文件中的下一个脚本之一:
 #!/bin/bash export DISPLAY=:0 if ! [ "`ping -c 1 google.com`" ]; then notify-send "No internet connection" exit 0 fi ip=$(curl -s 'http://ipecho.net/plain') country=$(curl -s 'http://geoiplookup.net/geoapi.php?output=countrycode' \ | awk '{ print toupper($2) }') release=$(lsb_release -sc) file="/etc/apt/sources.list" old_file="/etc/apt/sources.list.old" line=$(head -n 1 $file) new_line="## Ubuntu Repos for $ip" if [ "$line" == "$new_line" ] ; then exit 0 fi cp -f $file $old_file printf "$new_line deb mirror://mirrors.ubuntu.com/$country.txt $release main restricted universe multiverse deb mirror://mirrors.ubuntu.com/$country.txt $release-updates main restricted universe multiverse deb mirror://mirrors.ubuntu.com/$country.txt $release-backports main restricted universe multiverse deb mirror://mirrors.ubuntu.com/$country.txt $release-security main restricted universe multiverse " > $file notify-send "$file has been changed" "The old file has been put in $old_file" exit 0 

或者,类似于http://repogen.simplylinux.ch/上可以找到的内容:

 #!/bin/bash export DISPLAY=:0 if ! [ "`ping -c 1 google.com`" ]; then notify-send "No internet connection" exit 0 fi ip=$(curl -s 'http://ipecho.net/plain') country=$(curl -s 'http://geoiplookup.net/geoapi.php?output=countrycode' \ | awk '{ print tolower($2) }') release=$(lsb_release -sc) file="/etc/apt/sources.list" old_file="/etc/apt/sources.list.old" line=$(head -n 1 $file) new_line="## Ubuntu Main Repos for $ip" if [ "$line" == "$new_line" ] ; then exit 0 fi cp -f $file $old_file printf "$new_line deb http://$country.archive.ubuntu.com/ubuntu/ $release main restricted universe multiverse deb-src http://$country.archive.ubuntu.com/ubuntu/ $release main restricted universe multiverse ## Ubuntu Update Repos for $ip deb http://$country.archive.ubuntu.com/ubuntu/ $release-security main restricted universe multiverse deb http://$country.archive.ubuntu.com/ubuntu/ $release-updates main restricted universe multiverse deb-src http://$country.archive.ubuntu.com/ubuntu/ $release-security main restricted universe multiverse deb-src http://$country.archive.ubuntu.com/ubuntu/ $release-updates main restricted universe multiverse " > $file notify-send "$file has been changed" "The old file has been put in $old_file" exit 0 

或者,使用netselect的脚本(从这里下载, 在这里安装说明),因为izx在这个答案中解释得非常好:

 #!/bin/bash export DISPLAY=:0 if ! [ "`ping -c 1 google.com`" ]; then notify-send "No internet connection" exit 0 fi url=$(netselect \ `wget -q -O- https://launchpad.net/ubuntu/+archivemirrors \ | grep -P -B8 "statusUP|statusSIX" \ | grep -o -P "(f|ht)tp.*\"" \ | tr '"\n' ' '` \ | awk '{print $2}') release=$(lsb_release -sc) if [ "$url" == "" ] ; then exit 0 fi file="/etc/apt/sources.list" old_file="/etc/apt/sources.list.old" cp -f $file $old_file printf "## Ubuntu Best Repos deb http://extras.ubuntu.com/ubuntu $release main deb-src http://extras.ubuntu.com/ubuntu $release main deb $url $release main universe restricted multiverse deb http://security.ubuntu.com/ubuntu/ $release-security restricted universe main multiverse deb $url $release-updates restricted universe main multiverse " > $file notify-send "$file has been changed" "The old file has been put in $old_file" exit 0 
  • 保存文件并关闭它。
  • 返回终端并运行: chmod +x ~/bin/change_sources.sh – 授予脚本的执行访问权限。
  • 只是为了测试,要运行新脚本,请输入terminal ~/bin/change_sources.sh 。 它会给你一个错误,因为你没有权利编辑/etc/apt/sources.list 。 所以,使用sudo ~/bin/change_sources.sh
  • 使用sudo crontab -e命令编辑root用户的crontab文件,并添加以下行:
 @hourly /home/$USER/bin/change_sources.sh #change $USER with your user name 
  • 我已经为每小时设置了cron工作,但您可以根据自己的意愿或您认为更好的方式进行更改。 从这个意义上看http://en.wikipedia.org/wiki/Cron 。
  • 保存文件并使用sudo crontab -l检查新的crontab条目。

注意:要还原此脚本所做的更改,请删除cron作业并按照上图中的指示或使用终端中的下一个命令:

 cp -f /etc/apt/sources.list.bak /etc/apt/sources.list 

从现在开始,文件将在找到IP地址更改后动态更改。

它可能不是最好的解决方案,但是,在我看来, 可以像上面的脚本一样以这种方式给出一个好的解决方案

我很欣赏这个问题的所有意见,但由于没有人想出一个适合我们情况的简单解决方案,我决定自己解决这个问题。

我创建了一个工具(专门用于Ubuntu),我称之为apt-spy2

该工具的主要目标是快速找到工作镜像。 工作的定义是镜像服务器可用并且(希望:)是最新的。

我不假设所选服务器是否最接近且最快。 我没有做任何ping或GEO DNS技巧 – 但到目前为止,这在某些事情发生时有效。

它是如何工作的 – 简而言之:

  1. 我使用http://mirrors.ubuntu.com或launchpad的镜像列表来检索服务器。
  2. 我对每个(对于HTTP响应状态代码)进行简单检查。
  3. LBNL,我更新/etc/apt/sources.list

请注意:这假设人们玩得很好并且添加额外的镜像(例如第三方存储库到/etc/apt/sources.list.d 。但我想这意味着还有改进的余地。

您可以像这样获得此工具:

$ [sudo] gem install apt-spy2

cli附带listcheckfixhelp (有关如何使用它的扩展信息)。

我试图在项目的README中尽可能地记录。

目前的版本是非常保守的0.5.0

代码是开源的,许可证是自由的。 我会全力以赴。

在Debian 6.0.4上有这个命令:

易间谍

这样做可以自动找到下一个最近的可用服务器并生成新的sources.list

在Ubuntu中这个命令似乎不存在?

它仍然存在于Debian 7.0喘息声中:

https://launchpad.net/debian/wheezy/+source/apt-spy/+copyright

您可以在此处下载* .deb包:

http://packages.debian.org/sid/apt-spy

……仍然在寻找消息来源……

您显然需要Debian-7.0-Installation来在编辑sources-list后输入源代码:

deb-src http://http.debian.net/debian wheezy main

然后在sudo apt-get update之后你会简单地用以下代码来代码:

sudo apt-get source apt-spy

也许没有使用你喜欢的解决方案,但是当你下载几个MB的软件包(我打赌它们大多相同)时,为.deb文件设置一个本地缓存应该是理想的,因为你是从同一台服务器下载的,所以你可能会牺牲PC来制作缓存并使服务器不那么繁忙。

程序

您应该能够在硬盘驱动器中有足够空间的机器中设置apt-cacher (您需要它)。 您可以使用Apt-cacher服务器指南进行配置 ,但我们可以快速恢复。

  1. 安装apt-cacher

    sudo apt-get install apt-cacher apache2

  2. 编辑/etc/default/apt-cacher并将autostart值设置为1,以便在计算机启动时启动缓存。
  3. 重启apache sudo /etc/init.d/apache2 restart
  4. 使用http://ip-of.your.cache:3142/apt-cacher测试缓存。
  5. 您应该允许主机使用缓存,因此请编辑/etc/apt-cacher/apt-cacher.conf并查找allowed_hosts行。 您可以为所有主机设置子网,如192.168.0.0/24*
  6. 寻找快速可靠的服务器 。 您可以使用apt-spy (此命令可能需要数小时,因为它还会测试每个服务器的速度)。
  7. 在您的客户中,您有两种选择:

    • 设置sources.list如下:

    deb http://ip-of.your.cache:3142 / the.server.you.like / ubuntu / lucid主要限制宇宙多元宇宙

    更改缓存的ip的ip-of.your.cache和您将使用的服务器的主机名的the.server.you.like 。 您可以使用多行。

    • 或设置apt使用代理:编辑/etc/apt/apt.conf.d/01proxy并添加以下行:

    获取:: http :: Proxy“ http://ip-of.your.cache:3142 ”;

您可以尝试设置自己的Ubuntu镜像。 那样更新将是本地的。

apt-mirror需要高速互联网连接和大量磁盘空间

使用apt-mirror可以非常轻松地设置自己的Ubuntu镜像。

1)进入apt-mirror存储库。 像这样备份sources.list文件:

 sudo cp /etc/apt/sources.list /etc/apt/sources.list.old 

2)编辑sources.list文件,如下所示:

 gksudo gedit /etc/apt/sources.list 

3)并在新行上插入以下内容:

 deb http://apt-mirror.sourceforge.net/ apt-mirror 

4)让我们更新包索引

 sudo apt-get update 

5)并安装apt-mirror

 sudo apt-get install apt-mirror 

6)现在设置了Apt-mirror,让我们告诉它镜像的服务器:

 sudo cp /etc/apt/mirror.list /etc/apt/mirror.list.old gksudo gedit /etc/apt/mirror.list 

默认配置会将下载的文件放在/ var / spool / apt-mirror文件夹中。 以下是mirror.list文件的外观:

 ############# config ################## # set base_path /media/silo/repo # # 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 lucid main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu lucid -updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu lucid -backports main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu lucid -security main restricted universe multiverse clean http://archive.ubuntu.com/ubuntu 

这只镜像二进制包,但如果你想要源包,你应该插入适当的行。 他们通常采取以下forms:

 deb-src http://gh.archive.ubuntu.com/ubuntu/ lucid main restricted 

7)现在,运行apt-mirror 。 这将需要相当长的一段时间。 如果你不能一次性下载所有文件,请不要担心, apt-mirror可以恢复下载(使用Ctrl + C组合键将其删除,并在需要继续时重新运行)。 好的,像这样运行apt-mirror:

 sudo apt-mirror /etc/apt/mirror.list 

另请参阅如何使用apt-mirror创建本地Debian / Ubuntu镜像

来源: 使用Apt-mirror创建自己的Ubuntu镜像

我编写了一个名为apt-select的Python脚本,作为GUI方法的CLI替代方案。

该脚本通过TCP查询每个镜像,以最低延迟打印到stdout镜像,并生成新的sources.list文件。 还有多个选项允许您从排序镜像列表中进行选择,并检索上次更新镜像时的信息及其带宽容量。