養了很多 Debian/Ubuntu 機器時,時常得利用 apt 大量更新軟體。最常見的需求是 Security updates,所有伺服器都會抓取同一份軟體,機器量一大用掉的頻寬也很可觀。為了省下這些頻寬,得在伺服器區域網路設定一組快取伺服器,讓全區域網路下載一次。
有得人會自己建一份 archive mirror.
- reprepro http://mirrorer.alioth.debian.org/
- debmirror – http://packages.debian.org/unstable/net/debmirror
- debmirror – Debian partial mirror script, with ftp and package pool support
- debpartial-mirror – tools to create partial Debian mirrors
但是 Debian/Ubuntu 套件眾多,全部映射一份實在很費空間。我個人偏好只快取曾經抓過得檔案。
Debian/Ubuntu 中已經有幾個選項可用
approx – caching proxy server for Debian archive files
apt-cacher – Caching proxy for Debian package and source files
apt-cacher-ng – caching proxy server for software repositories
apt-p2p – apt helper for peer-to-peer downloads of Debian packages
debtorrent – bittorrent proxy for downloading Debian packages
apt-transport-debtorrent – an APT transport for communicating with DebTorrent
squid-deb-proxy – Squid proxy configuration to optimize package downloads
squid-deb-proxy-client – Automatic proxy discovery for apt based on avahi
其中 apt-p2p 與 debtorrent / apt-transport-debtorrent 是大約 2006-2008 年 p2p 技術熱門時的嘗試。而 debtorrent 直接利用 bittorrent 協定,而 apt-p2p 使用 kademlia DHT 協定來處理分散檔案,需要安裝 Twisted. 兩個概念都很有趣,但是我並不想在每台機器上架設 p2p server,純粹只是需要供應新的安裝檔案。
個人評估之後,選了 apt-cacher-ng. 設定簡便,apt-get 安裝完即可用,不相依於其他網站伺服軟體。還有簡易的管理界面可以看快取效率唷!
由於它基本上是個 http proxy,所以你可以用 transparent proxy 來導引所有的下載,或者在 /etc/apt/apt.conf.d/90aptcacher-ng 加入以下設定即可。
Acquire::http { Proxy "http://10.11.11.254:3142"; };
除了可以透過預設網頁來看快取狀態,也可以在 console 跑 /usr/lib/apt-cacher-ng/distkill.pl
來看硬碟上佔用了多少空間。
References
AptProxyCache – Ubuntu Wiki https://wiki.ubuntu.com/AptProxyCache
apt-cacher-ng
- Apt-Cacher NG – Software Package Download Proxy https://www.unix-ag.uni-kl.de/~bloch/acng/
- Apt-Cacher-NG – HTTP download proxy for software packages Ubuntu Geek http://www.ubuntugeek.com/apt-cacher-ng-http-download-proxy-for-software-packages.html-Cacher
- Ubuntu Manpage: apt-cacher-ng – caching proxy for software package downloads http://manpages.ubuntu.com/manpages/maverick/en/man8/apt-cacher-ng.8.html
apt-cacher
- Apt-Cacher-Server – Community Ubuntu Documentation https://help.ubuntu.com/community/Apt-Cacher-Server
approx
- approx: Package caching for Ubuntu (and Debian) lovers – Be the signal http://bethesignal.org/blog/2009/04/13/approx-package-caching-ubuntu-debian-lovers
DebTorrent
- DebTorrent http://debtorrent.alioth.debian.org/
- DebTorrent – Debian Wiki https://wiki.debian.org/DebTorrent
- Ian’s TechBlog: Using debtorrent to contribute to the community http://cheesehead-techblog.blogspot.com/2009/04/using-debtorrent-to-contribute-to.html
apt-p2p
- apt-p2p http://www.camrdale.org/apt-p2p/
- Ubuntu Manpage: apt-p2p — apt helper for peer-to-peer downloads of Debian packages http://manpages.ubuntu.com/manpages/raring/man8/apt-p2p.8.html
- HOWTO: Using apt-p2p (torrent) For Faster Upgrades From Hardy To Intrepid http://ubuntuforums.org/showthread.php?t=962741
AptProxy
- AptProxy – Community Ubuntu Documentation https://help.ubuntu.com/community/AptProxy