Ubuntu12.04搭建自有源
其實,這個工作比較簡單,主要兩步:apt-mirror和apache。(這裡的系統是ubuntu12.04)
1、apt-mirror
1.1 安裝
一如既往地簡單,直接sudo apt-get install apt-mirror即可。
1.2 配置apt-mirror
$ sudo vim /etc/apt/mirror.list
[plain]
############# 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://archive.ubuntu.com/ubuntu precise main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse
deb http://archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu precise-proposed main restricted universe multiverse
#deb http://archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu precise main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu precise-security main restricted universe multiverse
deb-src http://archive.ubuntu.com/ubuntu precise-updates main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu precise-proposed main restricted universe multiverse
#deb-src http://archive.ubuntu.com/ubuntu precise-backports main restricted universe multiverse
clean http://archive.ubuntu.com/ubuntu
將其修改為對自己比較快的源(這裡用ustc的):
[plain]
############ 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 ##############
#precise 64bit Mirror
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu precise main restricted universe multiverse
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu precise-security main restricted universe multiverse
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu precise-updates main restricted universe multiverse
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu precise-proposed main restricted universe multiverse
deb-amd64 http://mirrors.ustc.edu.cn/ubuntu precise-backports main restricted universe multiverse
#precise 32bit Mirror
deb-i386 http://mirrors.ustc.edu.cn/ubuntu precise main restricted universe multiverse
deb-i386 http://mirrors.ustc.edu.cn/ubuntu precise-security main restricted universe multiverse
deb-i386 http://mirrors.ustc.edu.cn/ubuntu precise-updates main restricted universe multiverse
deb-i386 http://mirrors.ustc.edu.cn/ubuntu precise-proposed main restricted universe multiverse
deb-i386 http://mirrors.ustc.edu.cn/ubuntu precise-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu precise main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu precise-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu precise-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu precise-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu precise-backports main restricted universe multiverse
clean http://mirrors.ustc.edu.cn/ubuntu
1.3 apt-mirror同步源
用sudo apt-mirror命令開始同步源即可。
[plain]
$ sudo apt-mirror
Downloading 140 index files using 20 threads...
Begin time: Fri Nov 1 17:23:49 2013
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Fri Nov 1 17:23:49 2013
Proceed indexes: [SSSSSPPPPP]
93.0 GiB will be downloaded into archive.
Downloading 85303 archive files using 20 threads...
Begin time: Fri Nov 1 17:23:55 2013
[20]...
這裡,要注意,有時候會碰到“No such file apt-mirror: can't open index in proceed_index_gz at /usr/bin/apt-mirror line 445.”這樣的錯誤,折騰了我一個下午。原因不怎麼清楚,不過,貌似按照上面我的流程做,至少可以避免這個錯誤。具體原因,難道和我配置文件中沒去掉注釋有關系,總之,稍詭異。
最後完成後的輸出如下:
[plain]
$ sudo apt-mirror
Downloading 140 index files using 20 threads...
Begin time: Fri Nov 1 17:23:49 2013
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Fri Nov 1 17:23:49 2013
Proceed indexes: [SSSSSPPPPP]
93.0 GiB will be downloaded into archive.
Downloading 85303 archive files using 20 threads...
Begin time: Fri Nov 1 17:23:55 2013
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Fri Nov 1 18:12:35 2013
0.0 bytes in 0 files and 0 directories can be freed.
Run /var/spool/apt-mirror/var/clean.sh for this purpose.
Running the Post Mirror script ...
(/var/spool/apt-mirror/var/postmirror.sh)
Post Mirror script has completed. See above output for any possible errors.
2、apache2
2.1 安裝
sudo apt-get install apache2
2.2 配置
apache2的配置,這裡就不班門弄斧了。反正我是直接在網上搜的帖子,方法很簡單。
[plain]
(1) 進入/var/www目錄
cd /var/www
(2) 創建一個指向apt-mirror的mirror存放路徑的軟鏈接,這裡命名為ubuntu
$ ln -s /var/spool/apt-mirror/mirror/mirrors.ustc.edu.cn/ubuntu ubuntu
到這裡,就可以在浏覽器地址欄輸入“202.xxx.xxx.xxx/ubuntu”來訪問該源目錄了。
3、使用源
為了使用該源之需要修改/etc/apt/source.list文件:
[plain]
比如原來用的是ustc的源,source.list文件如下:
deb http://mirrors.ustc.edu.cn/ubuntu/ precise main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-security main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-security main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
現在想改成,我們剛剛搭建好的源,只需在vim中用一個命令":%s/mirrors.ustc.edu.cn/202.xxx.xxx.xxx/g",即可將source.list修改為如下:
deb http://202.xxx.xxx.xxx/ubuntu/ precise main restricted universe multiverse
deb http://202.xxx.xxx.xxx/ubuntu/ precise-security main restricted universe multiverse
deb http://202.xxx.xxx.xxx/ubuntu/ precise-updates main restricted universe multiverse
deb http://202.xxx.xxx.xxx/ubuntu/ precise-proposed main restricted universe multiverse
deb http://202.xxx.xxx.xxx/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://202.xxx.xxx.xxx/ubuntu/ precise main restricted universe multiverse
deb-src http://202.xxx.xxx.xxx/ubuntu/ precise-security main restricted universe multiverse
deb-src http://202.xxx.xxx.xxx/ubuntu/ precise-updates main restricted universe multiverse
deb-src http://202.xxx.xxx.xxx/ubuntu/ precise-proposed main restricted universe multiverse
deb-src http://202.xxx.xxx.xxx/ubuntu/ precise-backports main restricted universe multiverse
然後,sudo apt-get update就可以看到,我們搭建的似有源的確已經生效了,速度飛快