Fedora 8中使用axel加速yum

火星人 @ 2014-03-25 , reply:0



轉亞森羅平大俠的貼子
1.自己編輯相關的repo文件,fedora.repo和fedora-updates.repo

改為不使用鏡像列表,並添加鏡像伺服器,修改如下:
#fedora.repo文件
CODE:
[fedora]
name=Fedora $releasever - $basearch
failovermethod=priority
#baseurl=http://download.fedora.redhat.com/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
baseurl=
http://download.fedora.redhat.com/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://mirrors.usc.edu/pub/linux/distributions/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://mirrors.cat.pdx.edu/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://ftp.iij.ad.jp/pub/linux/fedora/releases/$releasever/Everything/$basearch/os/
ftp://ftp.iij.ad.jp/pub/linux/fedora/releases/$releasever/Everything/$basearch/os/
http://mirror.aarnet.edu.au/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://mirror.internode.on.net/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://gulus.usherbrooke.ca/pub/distro/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://mirror.karneval.cz/pub/linux/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://sunsite.mff.cuni.cz/MIRRORS/fedora.redhat.com/linux/releases/$releasever/Everything/$basearch/os/
http://ftp-stud.hs-esslingen.de/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://fedora.tu-chemnitz.de/pub/linux/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://mirror.fraunhofer.de/download.fedora.redhat.com/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://ftp.uni-bayreuth.de/linux/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://ftp.funet.fi/pub/mirrors/fedora.redhat.com/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
ftp://ftp.free.fr/mirrors/fedora.redhat.com/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://limestone.uoregon.edu/ftp/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://fedora.mirror.iweb.ca/releases/$releasever/Everything/$basearch/os/
ftp://ftp.cse.buffalo.edu/pub/Linux/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://mirror.cc.vt.edu/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://mirrors.tummy.com/pub/fedora.redhat.com/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://mirrors.kernel.org/fedora/releases/$releasever/Everything/$basearch/os/
http://www.gtlib.gatech.edu/pub/fedora.redhat/linux/releases/$releasever/Everything/$basearch/os/
http://ftp.linux.ncsu.edu/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://ftp.iij.ad.jp/pub/linux/fedora/releases/$releasever/Everything/$basearch/os/
ftp://ftp.iij.ad.jp/pub/linux/fedora/releases/$releasever/Everything/$basearch/os/
http://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://ftp.rhnet.is/pub/fedora/linux/releases/$releasever/Everything/$basearch/os/
http://mirror.pacific.net.au/linux/fedora/linux/releases/$releasever/Everything/$basearch/os/


#mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=fedora-$releasever&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora file:///etc/pki/rpm-gpg/RPM-GPG-KEY

#fedora-updates.repo文件
CODE:
[updates]
name=Fedora $releasever - $basearch - Updates
failovermethod=priority
baseurl=
http://download.fedora.redhat.com/pub/fedora/linux/updates/$releasever/$basearch/
http://mirrors.usc.edu/pub/linux/distributions/fedora/linux/updates/$releasever/$basearch/
http://mirrors.cat.pdx.edu/fedora/linux/updates/$releasever/$basearch/
http://ftp.iij.ad.jp/pub/linux/fedora/updates/$releasever/$basearch/
ftp://ftp.iij.ad.jp/pub/linux/fedora/updates/$releasever/$basearch/
http://mirror.aarnet.edu.au/pub/fedora/linux/updates/$releasever/$basearch/
http://mirror.internode.on.net/pub/fedora/linux/updates/$releasever/$basearch/
http://gulus.usherbrooke.ca/pub/distro/fedora/linux/updates/$releasever/$basearch/
http://mirror.karneval.cz/pub/linux/fedora/linux/updates/$releasever/$basearch/
http://sunsite.mff.cuni.cz/MIRRORS/fedora.redhat.com/linux/updates/$releasever/$basearch/
http://ftp-stud.hs-esslingen.de/pub/fedora/linux/updates/$releasever/$basearch/
http://fedora.tu-chemnitz.de/pub/linux/fedora/linux/updates/$releasever/$basearch/
http://mirror.fraunhofer.de/download.fedora.redhat.com/fedora/linux/updates/$releasever/$basearch/
http://ftp.uni-bayreuth.de/linux/fedora/linux/updates/$releasever/$basearch/
http://ftp.funet.fi/pub/mirrors/fedora.redhat.com/pub/fedora/linux/updates/$releasever/$basearch/
ftp://ftp.free.fr/mirrors/fedora.redhat.com/fedora/linux/updates/$releasever/$basearch/
http://limestone.uoregon.edu/ftp/fedora/linux/updates/$releasever/$basearch/
http://fedora.mirror.iweb.ca/updates/$releasever/$basearch/
ftp://ftp.cse.buffalo.edu/pub/Linux/fedora/linux/updates/$releasever/$basearch/
http://mirror.cc.vt.edu/pub/fedora/linux/updates/$releasever/$basearch/
http://mirrors.tummy.com/pub/fedora.redhat.com/fedora/linux/updates/$releasever/$basearch/
http://mirrors.kernel.org/fedora/updates/$releasever/$basearch/
http://www.gtlib.gatech.edu/pub/fedora.redhat/linux/updates/$releasever/$basearch/
http://ftp.linux.ncsu.edu/pub/fedora/linux/updates/$releasever/$basearch/
http://ftp.iij.ad.jp/pub/linux/fedora/updates/$releasever/$basearch/
ftp://ftp.iij.ad.jp/pub/linux/fedora/updates/$releasever/$basearch/
http://ftp.yz.yamagata-u.ac.jp/pub/linux/fedora/linux/updates/$releasever/$basearch/
http://ftp.rhnet.is/pub/fedora/linux/updates/$releasever/$basearch/
http://mirror.pacific.net.au/linux/fedora/linux/updates/$releasever/$basearch/

#mirrorlist=http://mirrors.fedoraproject.org/mirrorlist?repo=updates-released-f$releasever&arch=$basearch
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-fedora

或下載我打包好的repo文件yum.repos.tar.gz[誰下載了此文件?],將原來的文件備份,然後覆蓋

注意:這裡的伺服器可以自己定義,你可以只選擇對自己來說最快的幾個伺服器即可

2.a.下載axel源碼包並進行編譯
到下面站點下載最新的axel源碼包,http://wilmer.gaast.net/main.php/axel.html

.進入下載目錄:
$tar zxvf 文件名
$cd 解壓出來的目錄
$./configure --i18n=1
$make
$make install

b.下載站點上有axel的rpm包提供,我沒有試,有興趣的幫忙試一下

3.我修改了伺服器的地址,直接定位到rpm包所在的目錄,因此無須進行判斷,直接下載即可,如果使用的是鏡像列表,則仍然需要進行i386和os的判斷,具體請參見wq1977兄弟的帖子--關於yum太慢了的解決方案
我修改過的axelget,去掉了os,axelget.py文件代碼:
CODE:
from yum.plugins import PluginYumExit, TYPE_CORE, TYPE_INTERACTIVE
from urlparse import urljoin
import os

requires_api_version = '2.3'
plugin_type = (TYPE_CORE, TYPE_INTERACTIVE)

enablesize=300000
trymirrornum=-1
maxconn=10

def init_hook(conduit):
global enablesize,trymirrornum,maxconn
enablesize = conduit.confInt('main','enablesize',default=30000)
trymirrornum = conduit.confInt('main','trymirrornum',default=-1)
maxconn = conduit.confInt('main','maxconn',default=10)

def predownload_hook(conduit):
global enablesize
preffermirror=""
for po in (conduit.getDownloadPackages()):
if hasattr(po, 'pkgtype') and po.pkgtype == 'local':
continue
totsize = long(po.size)
ret = False
if totsize <= enablesize:
conduit.info(2, "Package %s download size %d less than %d,Skip plugin!" % (po.repo.id,totsize,enablesize))
continue
else:
conduit.info(2, "Ok,we will try to use axel to download this big file:%d" % totsize)
local = po.localPkg()
if os.path.exists(local):
if not os.path.exists(local+".st"):
fstate=os.stat(local)
if totsize == fstate.st_size:
conduit.info(2,"Target already exists,skip to next file!")
continue
localall = "%s %s" % (local,local+".st")
rmcmd = "rm -f %s" % (localall)
curmirroridx = 0
conduit.info(2,"Before we start,clean all the key files")
os.system(rmcmd)
connnum = totsize / enablesize
if connnum > maxconn:
connnum = maxconn
mirrors=[]
mirrors[:0]=po.repo.urls
if preffermirror != "":
mirrors[:0] = [preffermirror]
for url in mirrors:
curmirroridx += 1
if (curmirroridx > trymirrornum) and (trymirrornum != -1):
conduit.info(2, "Package %s has tried %d mirrors,Skip plugin!" % (po.repo.id,trymirrornum))
break
remoteurl = urljoin(url, "%s" % po.remote_path)
syscmd = "axel -a -n %s %s -o %s" % (connnum,remoteurl,local)
conduit.info(2, "Execute axel cmd:\n%s" % syscmd)
os.system(syscmd)
if os.path.exists(local+".st"):
conduit.info(2,"axel exit by exception,let's try another mirror")
continue
else:
ret = True
preffermirror=url
break
if not ret:
conduit.info (2,"try to run rm cmd:%s" % rmcmd)
os.system(rmcmd)

axelget.conf文件代碼:
CODE:
[main]
enabled=1
enablesize=10000
trymirrornum=3

新建這兩個文件,將文件axelget.conf放入/etc/yum/pluginconf.d/目錄,將axelget.py放入/usr/lib/yum-plugins/即可

然後:
sudo yum clean all
sudo yum update

4.注意事項:
1.如果出現錯誤找不到axel命令,編輯~/.bash_profile ,將PATH改為如下所示:
PATH=$PATH:$HOME/bin:/usr/local/bin:/usr/local/sbin:/bin:/sbin:/usr/bin:/usr/sbin

2.可在http://mirrors.fedoraproject.org/publiclist/Fedora/$releasever/$basearch/查詢可用的伺服器,可能是因為Fedora 8 剛剛發布,所以有部分伺服器還沒有開放updates,如果提示沒有這個目錄,建議換個伺服器或者是等待一段時間再試

3.baseurl的第一個伺服器是絕對可以用的,是穩妥的設置,但速度上比較一般,50-100KB/s的樣子可以根據自己實際情況更改為更快的伺服器。

原文章出處



[火星人 via ] Fedora 8中使用axel加速yum已經有95次圍觀

http://www.coctec.com/docs/linux/show-post-168748.html