当前位置:
首页 >
CentOS 下多线程下载工具:axel
发布时间:2024/2/28
44
豆豆
生活随笔
收集整理的这篇文章主要介绍了
CentOS 下多线程下载工具:axel
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
环境相关:
OS:CentOS release 7.8
一.Linux多线程下载命令axel编译安装
wget http://www.ha97.com/code/axel-2.4.tar.gz 或者 wget https://files.cnblogs.com/files/xiaochina/axel-2.4.tar.gz# 找到一个还可以下载的网址
# ubuntu可以直接使用apt-get下载使用
# 编译安装,需要gcc环境
axel -h
# 查看帮助
# 测试下载
# 使用5个线程同时下载文件
# 限定下载速度上限为1024B/S
# 可以ctrl+c停掉,再次执行
# 发现可以断点续传
二.Yum加速改造
sed -i 's/plugins=0/plugins=1/g' /etc/yum.confcd /etc/yum/pluginconf.d/ cat >axelget.conf<<EOF [main] enabled=1 onlyhttp=1 enablesize=54000 cleanOnException=1 EOFcd /usr/lib/yum-plugins/ cat >axelget.py<<EOF from yum.plugins import PluginYumExit, TYPE_CORE, TYPE_INTERACTIVE from urlparse import urljoin import os,timerequires_api_version = '2.3' plugin_type = (TYPE_CORE, TYPE_INTERACTIVE)enablesize=300000 trymirrornum=-1 maxconn=10 httpdownloadonly=False cleanOnException=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) EOFyum -y install zip unzip # 测试,观察日志是否使用axel进行下载 yum -y install zip unzip
# 测试,观察日志是否使用axel进行下载
总结
以上是生活随笔为你收集整理的CentOS 下多线程下载工具:axel的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: CentOS下的抓包服务:rpcapd(
- 下一篇: centos7 升级curl版本