CentOS 5 centos 6下安装Axel插件加速yum下载

来源:互联网 发布:中国保险网络大学堂 编辑:程序博客网 时间:2024/04/28 14:51

1  下载axel插件的rpm包

下载地址 http://pkgs.repoforge.org/axel/

如果为centos 5  64位系统的话 使用http://pkgs.repoforge.org/axel/axel-2.4-1.el5.rf.x86_64.rpm

如果为centos 6  64位系统  使用 http://pkgs.repoforge.org/axel/axel-2.4-1.el6.rf.x86_64.rpm

2  安装rpm 包    rpm -ivh http://pkgs.repoforge.org/axel/axel-2.4-1.el6.rf.x86_64.rpm

可以直接运行命令安装

yum install axel

3  下载配置文件axelget.conf与axelget.py到yum里:
cd /etc/yum/pluginconf.d/
wget http://cnfreesoft.googlecode.com/svn/trunk/axelget/axelget.conf

或wget http://www.ha97.com/code/axelget.conf

也可以自己编辑,全文如下:

<span style="font-family:Arial;font-size:14px;">[main]enabled=1onlyhttp=1enablesize=54000cleanOnException=1</span>

cd /usr/lib/yum-plugins/
wget http://cnfreesoft.googlecode.com/svn/trunk/axelget/axelget.py

或wget http://www.ha97.com/code/axelget.py

也可以自己编辑,全文如下:

from yum.plugins import PluginYumExit, TYPE_CORE, TYPE_INTERACTIVEfrom urlparse import urljoinimport os,timerequires_api_version = '2.3'plugin_type = (TYPE_CORE, TYPE_INTERACTIVE)enablesize=300000trymirrornum=-1maxconn=10httpdownloadonly=FalsecleanOnException=0def init_hook(conduit):global enablesize,trymirrornum,maxconn,cleanOnException,httpdownloadonlyenablesize = conduit.confInt('main','enablesize',default=30000)trymirrornum = conduit.confInt('main','trymirrornum',default=-1)maxconn = conduit.confInt('main','maxconn',default=10)httpdownloadonly=conduit.confBool('main','onlyhttp',default=False)cleanOnException=conduit.confInt('main','cleanOnException',default=0)returndef predownload_hook(conduit):global enablesize,cleanOnException,httpdownloadonlypreffermirror=""PkgIdx=0TotalPkg=len(conduit.getDownloadPackages())for po in (conduit.getDownloadPackages()):PkgIdx+=1if hasattr(po, 'pkgtype') and po.pkgtype == 'local':continuetotsize = long(po.size)ret = Falseif totsize <= enablesize:conduit.info(2, "Package %s download size %d less than %d,Skip plugin!"  % (po.repo.id,totsize,enablesize))continueelse:conduit.info(2, "[%d/%d]Ok,we will try to use axel to download this big file:%d" % (PkgIdx,TotalPkg,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!")continuelocalall = "%s %s" % (local,local+".st")rmcmd = "rm -f %s" % (localall)curmirroridx = 0conduit.info(2,"Before we start,clean all the key files")os.system(rmcmd)connnum = totsize / enablesizeif connnum*enablesize<totsize:connnum+=1if connnum > maxconn:connnum = maxconnmirrors=[]mirrors[:0]=po.repo.urlsif preffermirror != "":mirrors[:0] = [preffermirror]for url in mirrors:if url.startswith("ftp://") and httpdownloadonly:print "Skip Ftp Site:",urlcontinueif url.startswith("file://"):print "Skip Local Site:",urlcontinuecurmirroridx += 1if (curmirroridx > trymirrornum) and (trymirrornum != -1):conduit.info(2, "Package %s has tried %d mirrors,Skip plugin!" % (po.repo.id,trymirrornum))breakremoteurl =  "%s/%s" % (url,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)time.sleep(2)if os.path.exists(local+".st"):conduit.info(2,"axel exit by exception,let's try another mirror")if cleanOnException:conduit.info(2,"because cleanOnException is set to 1,we do remove key file first")os.system(rmcmd)continueelif not os.path.exists(local):#this mirror may not update yetcontinueelse:ret = Truepreffermirror=urlbreakif not ret:conduit.info (2,"try to run rm cmd:%s"  % rmcmd)os.system(rmcmd)


最后确认 /etc/yum.conf中plugins=1

4  测试并安装yum-fastestmirror插件
yum install -y yum-fastestmirror
注:axel插件也可以当独立下载工具来使用。当成独立下载工具使用时,适用于绝大部分Linux发行版。
使用参数如下:
一般使用:axel url(下载文件地址);
限速使用:加上 -s 参数,如 -s 10240,即每秒下载的字节数,这里是 10 Kb;
限制连接数:加上 -n 参数,如 -n 5,即打开 5 个连接。

yum install axel
yum install yum-presto
yum install yum-fastestmirror
yum install yum-metadata-parser
yum install yum-downloadonly
yum install yum-priorities


0 0