今天看到同事做了一個公司本地的apache鏡像源,感覺好叼的樣子。然后就自己上網找些資料,嘗試自己搭建一套出來。然后就有了這篇博文。。。
聲明:本文中充滿了濃濃的技術嫉妒的心理,閱讀需謹慎。
本文以 [ubuntu16.4LTS 64位] 為例子進行配置,其他系統大同小異,如果在配置中遇到了奇葩問題,請留言討論或自行百度。
第一步:找到源配置文件
在ubuntu下,源文件的位置為: /etc/apt/source.list 。使用vim或者nano等編輯器,以管理員身份打開即可觀賞代碼。
第二部:找一個好用的鏡像地址列表
我找的是阿里的一個鏡像站,其他的也有很多,我覺着阿里至少在五年之內不會倒閉,所以就選它了。
首先將原文件備份:
cp ./source.list ./source.list.bak
然后開始修改 source.list 文件,將文件中所有的代碼全部注釋掉,使用 # 符號實現。然后將以下代碼拷貝到文件中去:
# 源碼
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse # 測試版源 deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse # 源碼(src) deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse # 測試版源 deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse # Canonical 合作伙伴和附加 deb http://archive.canonical.com/ubuntu/ xenial partner deb http://extras.ubuntu.com/ubuntu/ xenial main
保存退出。至此,我們就將原來的`蝸牛`版的源替換成了`急速`版的源了。執行下update試試,是不是發現速度快了很多?
第三步:執行完update后,我們來安裝一個工具先
sudo apt-get install -y apt-mirror
這個工具是用來拷貝配置本地源的。安裝完后來配置此工具:
vim /etc/apt/mirrors.list
set nthreads 20
set _tilde 0
deb http://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
clean http://mirrors.aliyun.com/ubuntu
現在都配置好了,開始執行下載操作:
apt-mirror
NOTE:大約80G,先看看硬盤在決定要不要繼續吧。速度么,再快能怎么快呢?畢竟80G。
第四步:配置本機源
假設你已經下載完了,無論是下一半玩技術還是真的等了一夜下載,無所謂,現在開始對本地源進行配置了。
下載的源路徑大概再這里 /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu
執行以下代碼完成配置:
# 編輯source.list文件 vim /etc/apt/sources.list deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu trusty main restricted universe multiverse deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu trusty-security main restricted universe multiverse deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu trusty-updates main restricted universe multiverse deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu trusty-proposed main restricted universe multiverse deb file:///var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu trusty-backports main restricted universe multiverse
至此,本地源配置完成,恭喜恭喜。
第五步:將源開放
如果自己一個人用一個80G的源,有點自私,也有點浪費資源了。互聯網本着開放自由共享的原則才發展到現在的境地,為何不把本地的80G源開放共享下呢?同事們也會很感激你的。
首先,要安裝一個工具:
sudo apt-get install apache2
然后將鏡像文件鏈接到 apache2 的根目錄下(大概是這個目錄 /var/www/html/):
ln -s /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu /var/www/html/ubuntu
此時,本地源的開放已經完成了。別人要使用你的源,則需要稍微進行下配置即可:
# 在別人家的機器上操作 vim /etc/apt/sources.list # 添加源配置,x.x.x.x 表示你的機器的IP地址 deb http://x.x.x.x/ubuntu trusty main restricted universe multiverse deb http://x.x.x.x/ubuntu trusty-security main restricted universe multiverse deb http://x.x.x.x/ubuntu trusty-updates main restricted universe multiverse deb http://x.x.x.x/ubuntu trusty-proposed main restricted universe multiverse deb http://x.x.x.x/ubuntu trusty-backports main restricted universe multiverse
好了,這下就徹底配置完成了。