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

axel插件是基于yum下的一个多线程下载插件,通过打开多个HTTP/FTP连接来将一个文件进行分段下载,从而达到加速下载的目的。对于下载大文件,该工具特别有用。可用于CentOS、RHEL、Fedora等使用yum的Linux发行版。暂时找不到rpm包,只能编译安装。使用Axel可以在低速网络环境里提高数倍的下载速度。

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

1  下载axel插件的rpm包

下载地址

如果为centos 5  64位系统的话 使用

如果为centos 6  64位系统  使用

2  安装rpm 包    rpm -ivh

可以直接运行命令安装

yum install axel

3  下载配置文件axelget.conf与axelget.py到yum里:
cd /etc/yum/pluginconf.d/
wget

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

[main]
enabled=1
onlyhttp=1
enablesize=54000
cleanOnException=1

cd /usr/lib/yum-plugins/
wget

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

from yum.plugins import PluginYumExit, TYPE_CORE, TYPE_INTERACTIVE
from urlparse import urljoin
import os,time

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

enablesize=300000
trymirrornum=-1
maxconn=10
httpdownloadonly=False
cleanOnException=0

def init_hook(conduit):
 global enablesize,trymirrornum,maxconn,cleanOnException,httpdownloadonly
 enablesize = 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)
 return

def predownload_hook(conduit):
 global enablesize,cleanOnException,httpdownloadonly
 preffermirror=""
 PkgIdx=0
 TotalPkg=len(conduit.getDownloadPackages())
 for po in (conduit.getDownloadPackages()):
  PkgIdx+=1
  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, "[%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!")
     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*enablesize<totsize:
   connnum+=1
  if connnum > maxconn:
   connnum = maxconn
  mirrors=[]
  mirrors[:0]=po.repo.urls
  if preffermirror != "":
   mirrors[:0] = [preffermirror]
  for url in mirrors:
   if url.startswith("ftp://") and httpdownloadonly:
    print "Skip Ftp Site:",url
    continue
   if url.startswith("file://"):
    print "Skip Local Site:",url
    continue
   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 =  "%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)
    continue
   elif not os.path.exists(local):#this mirror may not update yet
    continue
   else:
    ret = True
    preffermirror=url
    break
  if not ret:
   conduit.info (2,"try to run rm cmd:%s"  % rmcmd)
   os.system(rmcmd)

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

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/16031.html