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

############# 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的):

############ 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命令开始同步源即可。

$ 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.”这样的错误,折腾了我一个下午。原因不怎么清楚,不过,貌似按照上面我的流程做,至少可以避免这个错误。具体原因,难道和我配置文件中没去掉注释有关系,总之,稍诡异。

最后完成后的输出如下:

$ 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.

1.4 设置源自动更新

修改 /etc/cron.d/apt-mirror 取消掉被注释了的命令即可。这样系统会在指定的时间(默认是本地凌晨4点)自动开始同步。

2、apache2

2.1 安装

sudo apt-get install apache2

2.2 配置

apache2的配置,这里就不班门弄斧了。反正我是直接在网上搜的帖子,方法很简单。

(1) 进入/var/www目录
cd /var/www
(2) 创建一个指向apt-mirror的mirror存放路径的软链接,这里命名为ubuntu
$ ln -s /var/spool/apt-mirror/mirror/mirrors.ustc.edu.cn/ubuntu ubuntu

到这里,去查看下apache是否已经启动。实际上,apache2启动后回去找/etc/apache2/sites-enabled下面去找000-default(而一般情况下000-default是一个指向/etc/apache2/sites-available/目录下的default文件的一个链接)。通过查看这个文件,可以找到apache2的端口配置和默认目录。

<VirtualHost *:8087>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log

    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn

    CustomLog ${APACHE_LOG_DIR}/access.log combined

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

</VirtualHost>
通过上面的配置文件,可以看到这里apache2的端口是在8087,默认的root目录是在/var/www(因为之前已经在www目录下面创建了一个指向Ubuntu源目录的链接)。所以,现在直接在浏览器地址栏输入“202.xxx.xxx.xxx:8087/ubuntu”来访问该源目录了。

3、使用源

为了使用该源之需要修改/etc/apt/source.list文件:

比如原来用的是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就可以看到,我们搭建的似有源的确已经生效了,速度飞快。 微笑

你可能感兴趣的:(apache,ubuntu,apt-mirror,自有源)