快速搭建本地Ubuntu APT源镜像


Ubuntu 10.10 已经被抛弃了!
就是在昨天,Ubuntu的官方站点security.ubuntu.com和archive.ubuntu.com下都已经没有了maverick相关的目录,执行apt-get install直接提示"404 Not Found"。
与此同时,国内的诸多门户网站与大学的镜像也在今天同步了,也没有了maverick相关的目录。
个人感觉这真的很坑啊,就算不支持了,也不至于移走吧?这让我们这些还在使用Ubuntu 10.10作为线上服务器的屌丝运维情何以堪。
与此同时非常后悔自己当初没有搭建一个本地的APT源镜像,于是,努力搜寻着那些可能还未更新的镜像。
终于,找到了mirror.lupaworld.com,目前该社区的10.10的镜像还完整的保存着,在微博上进行了感谢之余便赶快搭建一个本地的APT源镜像,这样才是最有保障的!

最后,花费10个小时左右,占用了本地约100G硬盘空间,成功的完成了本地Ubuntu 10.10源镜像搭建。
在此,将相关步骤分享给大家。

将本地的源镜像修改为mirror.lupaworld.com
$ sudo sed -i s/security.ubuntu.com/mirror.lupaworld.com/g /etc/apt/sources.list
$ sudo sed -i s/archive.ubuntu.com/mirror.lupaworld.com/g /etc/apt/sources.list

更新源
$ sudo apt-get update

安装apt-mirror
$ sudo apt-get install apt-mirror

安装apache2,用于提供源的HTTP服务
$ sudo vim apt-get install apache2

编辑mirror.list(我的服务器默认都是64位的,因此需要用deb-i386与deb-i386-src指定镜像同步32位的软件包)
$ sudo vim /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://mirror.lupaworld.com/ubuntu maverick main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu maverick-security main restricted universe multiverse
deb http://mirror.lupaworld.com/ubuntu maverick-updates main restricted universe multiverse

deb-src http://mirror.lupaworld.com/ubuntu maverick main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu maverick-security main restricted universe multiverse
deb-src http://mirror.lupaworld.com/ubuntu maverick-updates main restricted universe multiverse

deb-i386 http://mirror.lupaworld.com/ubuntu maverick main restricted universe multiverse
deb-i386 http://mirror.lupaworld.com/ubuntu maverick-security main restricted universe multiverse
deb-i386 http://mirror.lupaworld.com/ubuntu maverick-updates main restricted universe multiverse

deb-i386-src http://mirror.lupaworld.com/ubuntu maverick main restricted universe multiverse
deb-i386-src http://mirror.lupaworld.com/ubuntu maverick-security main restricted universe multiverse
deb-i386-src http://mirror.lupaworld.com/ubuntu maverick-updates main restricted universe multiverse

clean http://mirror.lupaworld.com/ubuntu

然后新建一个screen终端(个人习惯),用于后台运行镜像同步
$ screen -dmS apt-mirror

$ screen -r apt-mirror
$ sudo apt-mirror

然后会显示如下信息:

Downloading 126 index files using 20 threads...
Begin time: Sat Dec 22 17:38:07 2012
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... [11]... [10]... [9]... [8]... [7]... [6]... [5]... [4]... [3]... [2]... [1]... [0]...
End time: Sat Dec 22 17:38:26 2012

Proceed indexes: [SSSPPPPPPPPP]

91 GiB will be downloaded into archive.
Downloading 20507 archive files using 20 threads...
Begin time: Sat Dec 22 17:38:55 2012
[20]... [19]... [18]... [17]... [16]... [15]... [14]... [13]... [12]... 

按下Ctrl+AD将终端挂起,作为后台运行

在等待约10个小时以后(取决于你的本地网络速度)
$ screen -r apt-mirror

完成镜像同步后可以看到如下信息:

...
End time: Sat Dec 22 17:20:11 2012

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.

则表明镜像同步已经成功完成

接下来启动apache2
$ sudo apt-get install apache2

将镜像目录链接到apache2的根目录下
$ sudo ln -s /var/spool/apt-mirror/mirror/mirror.lupaworld.com/ubuntu ubuntu

创建之后,就可以在其它的服务器上修改APT源地址为该服务器的IP,如"10.6.1.100",然后使用本地镜像服务了。

$ sudo sed -i s/security.ubuntu.com/10.6.1.100/g /etc/apt/sources.list
$ sudo sed -i s/archive.ubuntu.com/10.6.1.100/g /etc/apt/sources.list

$ sudo apt-get update

Get:1 http://10.6.1.100 maverick Release.gpg [198B]
Ign http://10.6.1.100/ubuntu/ maverick/main Translation-en
Ign http://10.6.1.100/ubuntu/ maverick/main Translation-en_US
Ign http://10.6.1.100/ubuntu/ maverick/multiverse Translation-en
Ign http://10.6.1.100/ubuntu/ maverick/multiverse Translation-en_US
Ign http://10.6.1.100/ubuntu/ maverick/restricted Translation-en
Ign http://10.6.1.100/ubuntu/ maverick/restricted Translation-en_US
Ign http://10.6.1.100/ubuntu/ maverick/universe Translation-en
Ign http://10.6.1.100/ubuntu/ maverick/universe Translation-en_US
Get:2 http://10.6.1.100 maverick-updates Release.gpg [198B]
Ign http://10.6.1.100/ubuntu/ maverick-updates/main Translation-en
Ign http://10.6.1.100/ubuntu/ maverick-updates/main Translation-en_US
Ign http://10.6.1.100/ubuntu/ maverick-updates/multiverse Translation-en
Ign http://10.6.1.100/ubuntu/ maverick-updates/multiverse Translation-en_US
Ign http://10.6.1.100/ubuntu/ maverick-updates/restricted Translation-en
Ign http://10.6.1.100/ubuntu/ maverick-updates/restricted Translation-en_US
Ign http://10.6.1.100/ubuntu/ maverick-updates/universe Translation-en
Ign http://10.6.1.100/ubuntu/ maverick-updates/universe Translation-en_US
Get:3 http://10.6.1.100 maverick-security Release.gpg [198B]
Ign http://10.6.1.100/ubuntu/ maverick-security/main Translation-en
Ign http://10.6.1.100/ubuntu/ maverick-security/main Translation-en_US
Ign http://10.6.1.100/ubuntu/ maverick-security/multiverse Translation-en
Ign http://10.6.1.100/ubuntu/ maverick-security/multiverse Translation-en_US
Ign http://10.6.1.100/ubuntu/ maverick-security/restricted Translation-en
Ign http://10.6.1.100/ubuntu/ maverick-security/restricted Translation-en_US
Ign http://10.6.1.100/ubuntu/ maverick-security/universe Translation-en
Ign http://10.6.1.100/ubuntu/ maverick-security/universe Translation-en_US
Get:4 http://10.6.1.100 maverick Release [39.8kB]
Get:5 http://10.6.1.100 maverick-updates Release [39.8kB]
Get:6 http://10.6.1.100 maverick-security Release [39.8kB]
Get:7 http://10.6.1.100 maverick/main Sources [829kB]
Get:8 http://10.6.1.100 maverick/restricted Sources [4,370B]
Get:9 http://10.6.1.100 maverick/universe Sources [4,179kB]
Get:10 http://10.6.1.100 maverick/multiverse Sources [151kB]                                                                                                                            
Get:11 http://10.6.1.100 maverick/main amd64 Packages [1,491kB]                                                                                                                         
Get:12 http://10.6.1.100 maverick/restricted amd64 Packages [6,002B]                                                                                                                    
Get:13 http://10.6.1.100 maverick/universe amd64 Packages [5,771kB]                                                                                                                     
Get:14 http://10.6.1.100 maverick/multiverse amd64 Packages [180kB]                                                                                                                     
Get:15 http://10.6.1.100 maverick-updates/main Sources [179kB]                                                                                                                          
Get:16 http://10.6.1.100 maverick-updates/restricted Sources [778B]                                                                                                                     
Get:17 http://10.6.1.100 maverick-updates/universe Sources [65.2kB]                                                                                                                     
Get:18 http://10.6.1.100 maverick-updates/multiverse Sources [2,513B]                                                                                                                   
Get:19 http://10.6.1.100 maverick-updates/main amd64 Packages [466kB]                                                                                                                   
Get:20 http://10.6.1.100 maverick-updates/restricted amd64 Packages [1,802B]                                                                                                            
Get:21 http://10.6.1.100 maverick-updates/universe amd64 Packages [202kB]                                                                                                               
Get:22 http://10.6.1.100 maverick-updates/multiverse amd64 Packages [5,462B]                                                                                                            
Get:23 http://10.6.1.100 maverick-security/main Sources [106kB]                                                                                                                         
Get:24 http://10.6.1.100 maverick-security/restricted Sources [14B]                                                                                                                     
Get:25 http://10.6.1.100 maverick-security/universe Sources [34.2kB]                                                                                                                    
Get:26 http://10.6.1.100 maverick-security/multiverse Sources [1,761B]                                                                                                                  
Get:27 http://10.6.1.100 maverick-security/main amd64 Packages [330kB]                                                                                                                  
Get:28 http://10.6.1.100 maverick-security/restricted amd64 Packages [14B]                                                                                                              
Get:29 http://10.6.1.100 maverick-security/universe amd64 Packages [116kB]                                                                                                              
Get:30 http://10.6.1.100 maverick-security/multiverse amd64 Packages [4,045B]                                                                                                           
Fetched 14.2MB in 1min 15s (190kB/s)                                                                                                                                                       
Reading package lists... Done

测试安装一个软件,如zip
$ sudo apt-get install zip

Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  unzip
The following NEW packages will be installed:
  unzip zip
0 upgraded, 2 newly installed, 0 to remove and 91 not upgraded.
Need to get 524kB of archives.
After this operation, 1,081kB of additional disk space will be used.
Do you want to continue [Y/n]? Y
Get:1 http://10.6.1.100/ubuntu/ maverick/main unzip amd64 6.0-4 [190kB]
Get:2 http://10.6.1.100/ubuntu/ maverick/main zip amd64 3.0-3 [334kB]
Fetched 524kB in 2s (191kB/s)
Selecting previously deselected package unzip.
(Reading database ... 59554 files and directories currently installed.)
Unpacking unzip (from .../archives/unzip_6.0-4_amd64.deb) ...
Selecting previously deselected package zip.
Unpacking zip (from .../archives/zip_3.0-3_amd64.deb) ...
Processing triggers for man-db ...
Setting up unzip (6.0-4) ...
Setting up zip (3.0-3) ...

成功安装了zip,本地源镜像搭建成功。

,

  1. #1 by mcsrainbow on 2012/12/27 - 14:57

    今天发现,Ubuntu将其已经不再更新维护的版本都移动到了 http://old-releases.ubuntu.com/ 中,并未坑爹的全部删除掉,因此我们可以直接将源替换为这个地址,不过由于国内仍然缺少镜像,所以还是建议自己也搭建一个。

  2. #2 by yuncliul on 2016/01/28 - 09:49

    线上一般用LTS的版本呢

(will not be published)
*