萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

Ubuntu 系統使用 apt-fast 加速套件下載完整教學

在 Debian 或 Ubuntu 系統上,若發現 apt-get 或 aptitude 安裝套件速度緩慢,除了檢查鏡像站點與網路頻寬外,還有一個強而有力的選擇:apt-fast。這是一個封裝 apt-get/aptitude 的 Shell 腳本,核心利用 aria2 多線程下載工具,將單一套件拆分為多個區塊,從多個鏡像站並行下載,原理類似 BitTorrent,能大幅縮短下載時間。

安裝 apt-fast

Debian 系列

$ sudo apt-get install aria2
$ wget https://github.com/ilikenwf/apt-fast/archive/master.zip
$ unzip master.zip
$ cd apt-fast-master
$ sudo cp apt-fast /usr/bin
$ sudo cp apt-fast.conf /etc
$ sudo cp ./man/apt-fast.8 /usr/share/man/man8
$ sudo gzip /usr/share/man/man8/apt-fast.8
$ sudo cp ./man/apt-fast.conf.5 /usr/share/man/man5
$ sudo gzip /usr/share/man/man5/apt-fast.conf.5

Ubuntu 14.04 及更新版本

$ sudo add-apt-repository ppa:saiarcot895/myppa
$ sudo apt-get update
$ sudo apt-get install apt-fast

Ubuntu 11.04 ~ 13.10

$ sudo add-apt-repository ppa:apt-fast/stable
$ sudo apt-get update
$ sudo apt-get install apt-fast

安裝過程會詢問預設套件管理器(apt-get 或 aptitude)及其他選項,日後可編輯 /etc/apt-fast.conf 修改設定。

設定鏡像清單

安裝完成後,需在 /etc/apt-fast.conf 的 MIRRORS 陣列加入地理位置較近的鏡像站。可參考:

格式範例(以逗號分隔同一檔案的多個鏡像):

# Debian
MIRRORS=('https://ftp.us.debian.org/debian/,https://carroll.aset.psu.edu/pub/linux/distributions/debian/,https://debian.gtisc.gatech.edu/debian/,https://debian.lcs.mit.edu/debian/,https://mirror.cc.columbia.edu/debian/')

# Ubuntu / Mint
MIRRORS=('https://us.archive.ubuntu.com/ubuntu,https://mirror.cc.columbia.edu/pub/linux/ubuntu/archive/,https://mirror.cc.vt.edu/pub2/ubuntu/,https://mirror.umd.edu/ubuntu/,https://mirrors.mit.edu/ubuntu/')

注意:/etc/apt/sources.list 中的預設鏡像也必須包含在 MIRRORS 字串內。

使用 apt-fast 安裝套件

語法與 apt-get/aptitude 相同,僅將指令前綴改為 apt-fast:

# 安裝套件
$ sudo apt-fast install texlive-full

# 僅下載不安裝
$ sudo apt-fast download texlive-full

可透過 netstat -nap | grep aria2c 觀察多連線下載狀態:

效能比較與限制

實測顯示,安裝大型套件時 apt-fast 比 apt-get 快 3~4 秒,但提升幅度取決於上游頻寬。此外,apt-fast 不會加速 apt-get update,僅在 install、upgrade、dist-upgrade、build-dep 等需下載 .deb 檔案的操作觸發並行下載,其餘操作會回退至原生管理器。

copyright © 萬盛學電腦網 all rights reserved