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

评论

评论查看选项

选择您喜欢的显示评论的模式,并点击"保存设置"来激活您所做的改变。
Louis Vuitton UK 提交者: jackets123
A big surprise here-mulberry 提交者: lishaohong163
A big surprise here-mulberry 提交者: lishaohong163
lebron james shoes 提交者: 123xiaolaoshu
nike air force 提交者: 123xiaolaoshu
christian louboutin 提交者: 123xiaolaoshu
ナイキ エアマックス 提交者: yess
Anquan Boldin Jersey 提交者: jersey209
Coach Outlet Online 提交者: sdtrysdt15
Barbour Jacket 提交者: q5251355
Replica Watches UK 提交者: q5251355
Nike has been criticized for 提交者: boer11111111
authentic nfl jerseys Very 提交者: zhangqi123
designer bags fashion 提交者: love784
australia ghd 提交者: Lonly
australia ghd 提交者: Lonly
australia ghd 提交者: Lonly
Buy Runescape Gold 提交者: tomorrowto
The best gift for 提交者: Requiem
moncler coat moncler 提交者: Requiem
The new features can even 提交者: ysl
In which lost or damaged 提交者: ysl
For your famous brand lv 提交者: ysl
windows 7 serial key 提交者: ______T1987
Canada Goose Outlet sale 提交者: shoeslin
バーバリー 提交者: バーバリー11
Authentic Matt Ryan Jersey 提交者: jersey208
COACH アウトレット 提交者: wwwmm
グッチ バッグ 激安 提交者: wwwmm
Shopping on Coach Purses 提交者: Donna2090
Replica Jeremy Maclin Jersey 提交者: jersey208
The best gift for you. The 提交者: Requiem
moncler coat moncler 提交者: Requiem
The best gift for you. The 提交者: Requiem
moncler coat moncler 提交者: Requiem
The best gift for you. The 提交者: Requiem
moncler coat moncler 提交者: Requiem
The best gift for you. The 提交者: Requiem
moncler coat moncler 提交者: Requiem
The best gift for you. The 提交者: Requiem
moncler coat moncler 提交者: Requiem
belstaff jackets 提交者: uggs classic boots
belstaff jackets 提交者: uggs classic boots
ugg 提交者: ugg 158
Gerald McCoy Jersey Authentic 提交者: jersey205
Louis Vuitton Bags 提交者: weihanteng
Louis Vuitton Bags 提交者: weihanteng