歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> ubuntu12.04本地搭建ubuntu更新源

ubuntu12.04本地搭建ubuntu更新源

日期:2017/3/1 14:55:57   编辑:關於Linux
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 0 set nthreads 20 set _tilde 0 # ############# end config ############## deb http://debian.ustc.edu.cn/ubuntu/ precise main multiverse restricted universe deb http://debian.ustc.edu.cn/ubuntu/ precise-backports main multiverse restricted universe deb http://debian.ustc.edu.cn/ubuntu/ precise-proposed main multiverse restricted universe deb http://debian.ustc.edu.cn/ubuntu/ precise-security main multiverse restricted universe deb http://debian.ustc.edu.cn/ubuntu/ precise-updates main multiverse restricted universe deb-src http://debian.ustc.edu.cn/ubuntu/ precise main multiverse restricted universe deb-src http://debian.ustc.edu.cn/ubuntu/ precise-backports main multiverse restricted universe deb-src http://debian.ustc.edu.cn/ubuntu/ precise-proposed main multiverse restricted universe deb-src http://debian.ustc.edu.cn/ubuntu/ precise-security main multiverse restricted universe deb-src http://debian.ustc.edu.cn/ubuntu/ precise-updates main multiverse restricted universe deb-i386 http://debian.ustc.edu.cn/ubuntu/ precise main multiverse restricted universe deb-i386 http://debian.ustc.edu.cn/ubuntu/ precise-backports main multiverse restricted universe deb-i386 http://debian.ustc.edu.cn/ubuntu/ precise-proposed main multiverse restricted universe deb-i386 http://debian.ustc.edu.cn/ubuntu/ precise-security main multiverse restricted universe deb-i386 http://debian.ustc.edu.cn/ubuntu/ precise-updates main multiverse restricted universe deb 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 universe deb http://222.24.24.175/ubuntu/ precise-backports main multiverse restricted universe deb http://222.24.24.175/ubuntu/ precise-proposed main multiverse restricted universe deb http://222.24.24.175/ubuntu/ precise-security main multiverse restricted universe deb http://222.24.24.175/ubuntu/ precise-updates main multiverse restricted universe deb-src http://222.24.24.175/ubuntu/ precise main multiverse restricted universe deb-src http://222.24.24.175/ubuntu/ precise-backports main multiverse restricted universe deb-src http://222.24.24.175/ubuntu/ precise-proposed main multiverse restricted universe deb-src http://222.24.24.175/ubuntu/ precise-security main multiverse restricted universe deb-src http://222.24.24.175/ubuntu/ precise-updates main multiverse restricted universe 即可。如果你還想同時使用其他的ubunt source服務器,那麼把上述配置放在配置文件的上面,以先匹配。   然後執行sudo apt-get update更新,以重建本地索引。以後就會使用本地的ubunt source服務器了。速度嗖嗖的:)
Copyright © Linux教程網 All Rights Reserved