ubuntu12.04本地搭建ubuntu更新源
apt-get實際使用wget命令,從/etc/apt/sources.list設定檔指定的源上下載對應的.deb軟體包,然後使用dpkg -i packageName.deb安裝軟體。如果Ubuntu電腦所在的環境網路效能較差,或者不能串連互連網,那麼就很難安裝Ubuntu Source伺服器上的海量軟體包。需求 為了建立Ubuntu mirror伺服器,你需要至少60G硬碟剩餘空間。Ubuntu每一個版本分為32bit和64bit兩個版本,有兩組deb包。最新的ubuntu版本兩組deb包需要大約90GB的空間。 你可以建立Ubuntu一個版本的32或者64bit伺服器,也可以建立同時服務於32和64bit的伺服器。也可以建立服務於所有ubuntu版本的source伺服器。根據你的硬碟剩餘空間和你的需要而定。使用中國科技大學的Ubuntu Source伺服器作為原始伺服器中國科學技術大學補救伺服器(位於合肥,千兆教育網接入,百兆電信/聯通線路智能路由),由中科大 Linux 使用者協會和中科大學網路資訊中心維護,包含其他開源鏡像,Deepin 官方伺服器 實際亦指向此處:使用apt-mirror建立Ubuntu Source伺服器的本地鏡像伺服器sudo apt-get install apt-mirror sudo apt-get install apache2我們需要上面這兩個軟體來構建我們的本地Ubuntu Source伺服器。 我現在以構建ubuntu12.04的32和64位版本的本地ubunt source伺服器為例進行介紹。如果你需要服務於其他版本,請修改對應的配置。 /etc/apt/mirror.list設定檔修改為如下:############# config #################### set base_path /var/spool/apt-mirror## set mirror_path $base_path/mirror# set skel_path $base_path/skel# set var_path $base_path/var# set cleanscript $var_path/clean.sh# set defaultarch <running host architecture># set postmirror_script $var_path/postmirror.sh# set run_postmirror 0set nthreads 20set _tilde 0############## end config ##############deb http://debian.ustc.edu.cn/ubuntu/ precise main multiverse restricted universedeb http://debian.ustc.edu.cn/ubuntu/ precise-backports main multiverse restricted universedeb http://debian.ustc.edu.cn/ubuntu/ precise-proposed main multiverse restricted universedeb http://debian.ustc.edu.cn/ubuntu/ precise-security main multiverse restricted universedeb http://debian.ustc.edu.cn/ubuntu/ precise-updates main multiverse restricted universedeb-src http://debian.ustc.edu.cn/ubuntu/ precise main multiverse restricted universedeb-src http://debian.ustc.edu.cn/ubuntu/ precise-backports main multiverse restricted universedeb-src http://debian.ustc.edu.cn/ubuntu/ precise-proposed main multiverse restricted universedeb-src http://debian.ustc.edu.cn/ubuntu/ precise-security main multiverse restricted universedeb-src http://debian.ustc.edu.cn/ubuntu/ precise-updates main multiverse restricted universedeb-i386 http://debian.ustc.edu.cn/ubuntu/ precise main multiverse restricted universedeb-i386 http://debian.ustc.edu.cn/ubuntu/ precise-backports main multiverse restricted universedeb-i386 http://debian.ustc.edu.cn/ubuntu/ precise-proposed main multiverse restricted universedeb-i386 http://debian.ustc.edu.cn/ubuntu/ precise-security main multiverse restricted universedeb-i386 http://debian.ustc.edu.cn/ubuntu/ precise-updates main multiverse restricted universedeb http://* 表示下載64位版本的deb軟體。 deb-i386 http://* 表示下載32位版本的deb軟體。 然後執行: sudo apt-mirror 這會啟動20個線程【上面檔案中配置】運行wget到 http://mirrors.sohu.com/Ubuntu 下面下載相應的deb包。 sudo apt-mirror執行完成後,/var/spool/apt-mirror目錄下就有了所有需要的deb包和相應的設定檔。因為我用的是中國科技大學的更新源所以下載好的路徑是/var/spool/apt-mirror/mirror/debian.ustc.edu.cn/ubuntu如果你選擇其他Ubuntu Source服務區,那麼會下載到其他對應的目錄下。現在我們本地已經有了所有Ubuntu Source伺服器需要的檔案,但是現在我們還不能使用本地的Ubuntu Source伺服器。因為它還沒有啟動。 Ubuntu Source伺服器實際上是一個http伺服器。我們訪問sohu的Ubuntu Source伺服器就是用瀏覽器訪問的。 所以,我們也需要啟動一個web伺服器來啟動本地的Ubuntu Source伺服器。 我選擇使用apache2這個web伺服器來為Ubuntu Source伺服器服務。Ubuntu Source伺服器實際上就是一系列靜態檔案。 Apt-cache ,apt-get 程式就是通過wget下載對應的靜態檔案實現軟體下載和安裝的。 眾所周知,Apache2 Web伺服器服務於靜態檔案時非常高效、穩定。因此我選擇apache2伺服器。 apache2伺服器安裝後,預設使用/var/www/目錄作為Web的根目錄。 我這裡取個巧,直接cd /var/www/ ln /var/spool/apt-mirror/mirror/debian.ustc.edu.cn/ubuntu/ -s在/var/www目錄下建立一個Ubuntu超連結,連結到/var/spool/apt-mirror/mirror/debian.ustc.edu.cn/ubuntu/上 sudo /etc/init.d/apache2 start/restart/stop/status 命令可以管理apache2伺服器。使用sudo apache2ctl start啟動。 開啟瀏覽器,輸入http://localhost/Ubuntu 就可以看到和http://mirrors.sohu.com/Ubuntu/ 相同的頁面。 至此,我們的本地Ubuntu Source伺服器已經建立成功了。 每天定時同步本地ubunt source伺服器和遠程ubunt source伺服器我們現在建立的ubunt source伺服器的內容和中國科技大學版本的伺服器相同。但是,每天Ubuntu團隊都在向Ubuntu Source伺服器中添加新的deb包。 中國科技大學每天也都會和Ubuntu官方source伺服器同步。 我們必須經常使用sudo apt-mirror命令才能同步最新的deb包。 我們可以使用一個定時執行的指令碼,實現每天和中國科技大學的Ubuntu Source伺服器同步來解決這個問題。 1 sudovim/etc/cron.d/apt-mirror 把命令簽名的#去掉。命令如下: 1 0 4 * * * apt-mirror /usr/bin/apt-mirror > /var/spool/apt-mirror/var/cron.log這樣,電腦每天就會自動啟動apt-mirror和Ubuntu Source伺服器同步。使用本地Ubuntu Source鏡像伺服器 現在,我們可以修改/etc/atp/source.list檔案以使用本地Ubuntu Source伺服器作為apt源。 如,我的ubunt伺服器的地址是222.24.24.175,那麼加入:deb http://222.24.24.175/ubuntu/ precise main multiverse restricted universedeb http://222.24.24.175/ubuntu/ precise-backports main multiverse restricted universedeb http://222.24.24.175/ubuntu/ precise-proposed main multiverse restricted universedeb http://222.24.24.175/ubuntu/ precise-security main multiverse restricted universedeb http://222.24.24.175/ubuntu/ precise-updates main multiverse restricted universedeb-src http://222.24.24.175/ubuntu/ precise main multiverse restricted universedeb-src http://222.24.24.175/ubuntu/ precise-backports main multiverse restricted universedeb-src http://222.24.24.175/ubuntu/ precise-proposed main multiverse restricted universedeb-src http://222.24.24.175/ubuntu/ precise-security main multiverse restricted universedeb-src http://222.24.24.175/ubuntu/ precise-updates main multiverse restricted universe即可。如果你還想同時使用其他的ubunt source伺服器,那麼把上述配置放在設定檔的上面,以先匹配。 然後執行sudo apt-get update更新,以重建本地索引。以後就會使用本地的ubunt source伺服器了。速度嗖嗖的:)