zoukankan      html  css  js  c++  java
  • Axel多线程工具安装

    Axel 是 Linux 下一个不错的轻量级高速下载工具,支持HTTP/FTP/HTTPS/FTPS协议,支持多线程下载、断点续传,且可以从多个地址或者从一个地址的多个连接来下载同一个文件。

    大家使用yum下载一些资源的时候,经常会遇到网速不佳或者资源限速,多次下载中断无法正常下载的情况,我们可以使用Axel来支持yum续点下载。

    下载安装axel(需要先配置好epel源),gcc环境。

    # yum -y install axel 
    # yum -y install gcc

    修改yum配置文件

    # sed -i 's/plugins=0/plugins=1/g' /etc/yum.conf
    # cd /etc/yum/pluginconf.d/
    修改配置文件,添加以下内容。
    cat >axelget.conf<<EOF
    [main]
    enabled=1
    onlyhttp=1
    enablesize=54000
    cleanOnException=1
    EOF
    
    
    # cd /usr/lib/yum-plugins/
    修改配置文件,添加以下内容。
    
    cat >axelget.py<<EOF
    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:
    %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)
    EOF

    测试使用:

    #yum -y install zabbix-agent
    Opening output file /var/cache/yum/x86_64/7/zabbix/packages/zabbix-agent-4.0.15-1.el7.x86_64.rpm
    Starting download
    
    Connection 0 finished                                                          ]
    Connection 4 finished                                                          ]
    Connection 1 finished                                                          ]
    Connection 3 finished                                                          ]
    Connection 7 finished                                                          ]
    Connection 6 finished                                                          ]
    Connection 5 finished                                                          ]
    [100%] [..................................................] [ 208.8KB/s] [00:00]
    
    出现多线程下载说明配置OK!
  • 相关阅读:
    .net core获取数据库连接 抛出The type initializer to throw an exception
    解决本地Bootstrap字体图标不可见的问题
    Bootstrap 遮罩插件jquery.mloading
    oracle 数据库触发器,插入更新时间戳
    入门wpf—— 3、样式
    VisualStudio 连接 MySql 实现增删查改
    Bootstrap-table 使用总结,和其参数说明
    oracle数据库 TIMESTAMP(6)时间戳类型
    3.xadmin配置
    2.Model设计
  • 原文地址:https://www.cnblogs.com/dthum/p/11994325.html
Copyright © 2011-2022 走看看