我们是一个分布式团队,这就是我们的 VM 使用 Ubuntumirror://
设置的原因。我们的/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
Run Code Online (Sandbox Code Playgroud)
这本身就非常了不起,对在不同地点工作的人非常有帮助——不需要本地定制等。理论上的故障转移。
在日常工作中,此设置经常失败。这周我想说2-3次。
现在作为我的壁橱镜子mirrors.ubuntu.com
回来了ftp.uni-bayreuth.de
。不幸的是,它似乎下降了。
这已经持续了几个小时,镜子由一所大学的志愿者主持,今天是星期五,我希望这会很快得到纠正。
所有的谈话,我的问题是:
Rad*_*anu 10
我个人认为选择最佳 Ubuntu 存储库镜像的最佳方法是使用 GUI 方法:
现在,为了改善问题中描述的情况,您需要以某种方式设置一些规则。这些规则必须付诸行动mirrors.ubuntu.com
。我可以建议一些规则如下:
netselect
,apt-spy
或者apt-fast
接下来,为了了解您可以如何解决,我可以通过三个 bash 脚本示例为您提供一个逐步描述的方法。第一个脚本使用您当前所在国家/地区的镜像而不是mirrors.ubuntu.com/mirrors.txt
(对于每个国家/地区都有一个带有镜像关联的文本文件;请参阅http://mirrors.ubuntu.com/):
mkdir -p bin
-如果您还没有,此命令将bin
在您的home
文件夹中创建一个目录。gedit ~/bin/change_sources.sh
- 这将change_sources.sh
在 gedit 中创建新文件。#!/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
Run Code Online (Sandbox Code Playgroud)
或者,类似于可以在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
Run Code Online (Sandbox Code Playgroud)
或者,使用脚本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
Run Code Online (Sandbox Code Playgroud)
chmod +x ~/bin/change_sources.sh
- 授予脚本的执行访问权限。~/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
Run Code Online (Sandbox Code Playgroud)
sudo crontab -l
。注意:要恢复此脚本所做的更改,请删除 cron 作业并按照上图中的指示操作或在终端中使用下一个命令:
Run Code Online (Sandbox Code Playgroud)cp -f /etc/apt/sources.list.bak /etc/apt/sources.list
从现在开始,该文件将在发现 IP 地址更改后动态更改。
这可能不是最好的解决方案,但在我看来,可以像上面的脚本那样以这种方式给出一个好的解决方案。
我感谢有关这个问题的所有意见,但由于没有人提出适合我们情况的简单解决方案,因此我决定自己解决这个问题。
\n\n我创建了一个工具(专门用于 Ubuntu),我称之为apt-spy2
.
该工具的主要目标是快速找到工作镜。工作的定义是镜像服务器可用并且(希望是:)是最新的。
\n\n我不假设所选服务器是否一定是最近且最快的。我没有执行任何 ping 或 GEO DNS 技巧 \xe2\x80\x94 但到目前为止,当出现问题时,这会起作用。
\n\n简而言之,它是如何工作的 \xe2\x80\x94:
\n\n/etc/apt/sources.list
。请注意:这假设人们玩得很好并放置了额外的镜像(例如将第 3 方存储库放入/etc/apt/sources.list.d
. 但我想这意味着还有改进的空间。
您可以像这样获取这个工具:
\n\n\n$ [sudo] gem install apt-spy2\n
cli 附带list
、check
和(带有有关如何使用它的扩展信息)fix
。help
我尝试在项目的README中尽可能多地记录。
\n\n目前的版本是非常保守的0.5.0
。
该代码是开源的,并且许可证是自由的。我接受所有的贡献。
\n 归档时间: |
|
查看次数: |
18630 次 |
最近记录: |