pacman终极提速--metalink,类似迅雷的下载方式

您没有发表评论的权限。

作者:tx-cary
来自: archlinux.org.cn ; linuxsir.org
摘要:aria2它是命令行模式的下载工具;


+++++++++++++++++++++++++++++++++++
正文
+++++++++++++++++++++++++++++++++++

一、介绍一个下载器--aria2。

以前有一个叫做aria的下载器,有图形界面的。但是这个aria2似乎和这个aria并没有什么关系。它是命令行模式的下载工具。

pacman -S aria2

可以直接从extra仓库中安装这个软件。

aria2支持多种下载方式(协议)

该软件支持多种下载方式(协议):HTTP/HTTPS/FTP/BitTorrent/Metalink。

前4种就不必我介绍了,这里重点介绍Metalink。什么是Metalink呢?这里的Metalink可不是Oracle中的那个Metalink。这里的Metalink其实说简单一点,就是提供一个所有包含同一个文件的服务器列表,下载工具尝试和这些服务器建立连接,从而实现多个服务器同时下载文件。这和Windows下的迅雷很象。但是不同的是,迅雷需要一个服务器,而且服务器列表是迅雷的服务器帮你完成的,而metalink是连接本身就包含在列表文件中--或者说,列表是你手动给出的。Archlinux官方ISO下载也采用了metalink的方式。

我们该如何使用这个工具呢?

首先,建立一个脚本文件,命名为pacget,脚本内容如下:

#!/bin/bash
#pacget script

rm -f *.aria2
cachedir=/var/cache/pacman/pkg
file=`echo $1|awk -F '/' '{ print $NF }'`
echo Downloading: $file|sed 's,/,,'
repo=`echo $1|awk -F '/' '{x=NF-3 } { print  $x }'`
echo repo: $repo
if [[ $2 = *.db.tar.gz.part || $repo = "testing" ]]; then
       echo "(using one mirror)"
       mirrors=$1
else
       if [ -f /etc/pacman.d/$repo ]; then
       mirrors=`sed -n 's/^Server = //; s,$,/'"$file"', ; /^ftp/p; /^http/p' /etc/pacman.d/$repo`
       fi
fi

aria2c -t20 -m2 -l /var/log/pacget.log $mirrors -o $file.pacget
if [ -f $cachedir/$file.pacget.aria2 ]; then
      rm $cachedir/$file.pacget $cachedir/$file.pacget.aria2
      exit 0
fi

mv $file.pacget $2
exit 0

这个脚本是将/etc/pacman.d下的pacman服务器列表生成每个下载文件的服务器列表。并且调用aria2下载指定包。

别忘了将这个文件放置在/usr/bin下,并且加上可执行权限:

chmod +x pacget

然后,修改/etc/pacman.conf文件,指定下载器为pacget:

XferCommand = pacget %u %o

接下来,就可以以平常的方式使用pacman了。

不过pacman自己带的服务器列表比较老,很多服务器不是不存在了就是更新慢,有些我们这里根本连不上。不符合中国"国情"。服务器贵精不贵多,我这里给出几个更新还算及时,速度还算可以的服务器(国外的,本人是网通):

http://ftp.belnet.be/linux/archlinux
http://mirror.cs.vt.edu/pub/ArchLinux
http://mirrors.easynews.com/linux/archlinux
http://distro.ibiblio.org/pub/linux/distributions/archlinux http://ftp.gigabit.nu/archlinux

将这几个服务器替换到你的/etc/pacman.d/下的服务器列表文件即可。

这里还有一种改进的方案:

上述方案,一是没有续传的功能,因为 aria2不论下载是否完成都会返回0;二是源的添加不方便。于是改了一下,实现了上述的功能。

另外,将源的选择独立了出来,方便添加。安装只要三步。

修改/usr/bin/pacget

#!/bin/bash
#pacget script

cachedir=/var/cache/pacman/pkg
file=`echo $1|awk -F '/' '{ print $NF }'`
echo Downloading: $file|sed 's,/,,'
repo=`echo $1|awk -F '/' '{x=NF-3 } { print  $x }'`
echo repo: $repo
mirrors=`sed -n 's/^Server = //; s,$,/'"$repo/os/i686/$file"', ; /^ftp/p; /^http/p' /etc/pacget.conf`

if [[ $2 = *.db.tar.gz.part || $repo = "testing" ]]; then
       echo "(using one mirror)"
       mirrors=$1
       cachedir=/var/lib/pacman
fi

aria2c -t60 -m5 -l /var/log/pacget.log $mirrors -o $file.pacget
if [ -f $cachedir/$file.pacget.aria2 ]; then
    exit 130
fi
mv $file.pacget $2

添加一个/etc/pacget.conf,将你的源添加进去:

#pacget mirror list file

http://download.ourlinux.net:81/Linux/ArchLinux
ftp://cle.linux.org.tw/pub/ArchLinux
ftp://ftp.archlinux.org
http://mirror.lupaworld.com/archlinux
http://ftp.belnet.be/linux/archlinux
http://mirror.cs.vt.edu/pub/ArchLinux
http://mirrors.easynews.com/linux/archlinux
http://distro.ibiblio.org/pub/linux/distributions/archlinux
http://ftp.gigabit.nu/archlinux

评论

评论查看选项

选择您喜欢的显示评论的模式,并点击"保存设置"来激活您所做的改变。
uggaustraliaAnd if you cant 提交者: uggaustralia
diesel denim 提交者: rjrfft
uggaustraliaUGG Cuff Boots 提交者: uggaustralia
Luxury brands to the oneself 提交者: cn123
uggaustraliaHighest quality 提交者: uggaustralia
Moving coilCustom Beats By 提交者: ning123
uggaustraliaugg boots 提交者: uggaustralia
Lying CXHqwwe1114 disguises 提交者: cxhwere
Robert Griffin III Jersey 提交者: USS01
UGG's happen to be observed 提交者: Becky12393
UGG's happen to be observed 提交者: Becky12393
UGG's happen to have been 提交者: Becky12393
UGG's happen to be observed 提交者: Becky12393
UGG's seem to have been 提交者: Becky12393
UGG's seem to have been 提交者: Becky12393
north face jackets on sale 提交者: kei111
uggaustraliadon't 提交者: uggaustralia
ナイキ エアジョーダン 提交者: wwwmm
planchas ghd baratas 提交者: ghd NZ
http://www.newnhljerseyssupply.com/ 提交者: nhlhomejerseys
ugg boots sale 提交者: qiannian00
cheap beats by dre 提交者: hifdvfdyh456
Red Bottom Heels is 提交者: zhong222
uggaustraliaThe ugg 提交者: uggaustralia
nearly all people can not 提交者: kei111
and thus clean launched 提交者: kei111
uggaustraliaUnlike the other 提交者: uggaustralia
uggaustraliaugg australia 提交者: uggaustralia
Dear Friend,Merry 提交者: cn123
cheap beats by dre 提交者: mivfs45
cheap beats by dre 提交者: mivfs45
uggaustraliaugg nightfall 提交者: uggaustralia
cheap beats by dre 提交者: mivfs45
Ferragamo Outlet has gained 提交者: ning123
fwvhzx 提交者: gvepky
vmzrplk 提交者: gvepky
gkryjqcg 提交者: gvepky
zgxnwwoz 提交者: gvepky
Moncler Jacket 提交者: prada
Discount louboutins 提交者: prada
Moncler Jacket 提交者: prada
christian louboutin shoes. 提交者: prada
Cheap Timberland Boots 提交者: prada
zautut 提交者: gvepky
Discount Michael Kors 提交者: qingggg
new armani watches,new 提交者: cn123