前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >CentOS 5/6下安装Axel插件加速yum下载

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

作者头像
孙杰
发布2019-10-29 12:24:07
1.3K0
发布2019-10-29 12:24:07
举报

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

axel 是Linux 命令行下多线程的下载工具,支持断点续传,速度通常情况下是Wget的几倍

官方主页:http://axel.alioth.debian.org/

×××:

1

# curl  -O  https://alioth.debian.org/frs/download.php/3015/axel-2.4.tar.gz

编译安装:

123456

# tar -xvf axel-2.4.tar.gz  && cd axel-2.4# ./configure --prefix=/usr/local/axel# make && make install  导出axel执行路径# echo 'PATH=/usr/local/axel/bin:$PATH' > /etc/profile.d/axel.sh && source /etc/profile

添加axel man手册查找路径

12

# vim /etc/man.config  MANPATH /usr/local/axel/share/man

常用选项:

1234

-n : 指定线程数-o : 指定另存为目录-s   :  指定每秒的最大比特数-q  : 静默模式

Axel插件加速yum下载:

12345

# wget https://github.com/crook/yum-axelget/archive/v1.0.5.tar.gz  # tar -xvf v1.0.5 # cd yum-axelget-1.0.5/# cp axelget.conf /etc/yum/pluginconf.d/# cp axelget.py  /usr/lib/yum-plugins/

补充:

 下载配置文件axelget.conf与axelget.py到yum里:

cd /etc/yum/pluginconf.d/ wget http://cnfreesoft.googlecode.com/svn/trunk/axelget/axelget.conf

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

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

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

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

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

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

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://werewolftj.blog.51cto.com/1606482/1415174。原作者:ilove_vc

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2016-10-26 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • Axel插件加速yum下载:
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档