2021-05-12 14:32:11
CentOS 5/6下安裝Axel外掛加速yum下載
axel外掛是基於yum下的一個多執行緒下載外掛,通過開啟多個HTTP/FTP連線來將一個檔案進行分段下載,從而達到加速下載的目的。對於下載大檔案,該工具特別有用。可用於CentOS、RHEL、Fedora等使用yum的Linux發行版。暫時找不到rpm包,只能編譯安裝。使用Axel可以在低速網路環境裡提高數倍的下載速度。
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
也可以自己編輯,全文如下:
[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
更多YUM相關教學見以下內容:
RedHat 6.2 Linux修改yum源免費使用CentOS源 http://www.linuxidc.com/Linux/2013-07/87383.htm
設定EPEL YUM源 http://www.linuxidc.com/Linux/2012-10/71850.htm
Redhat 本地yum源設定 http://www.linuxidc.com/Linux/2012-11/75127.htm
yum的組態檔說明 http://www.linuxidc.com/Linux/2013-04/83298.htm
RedHat 6.1下安裝yum(圖文) http://www.linuxidc.com/Linux/2013-06/86535.htm
YUM 安裝及清理 http://www.linuxidc.com/Linux/2013-07/87163.htm
CentOS 6.4上搭建yum本地源 http://www.linuxidc.com/Linux/2014-07/104533.htm
本文永久更新連結地址:http://www.linuxidc.com/Linux/2015-08/122072.htm
相關文章