红联Linux门户
Linux帮助

apt-mirror建立本地Ubuntu私有源

发布时间:2014-08-11 22:02:10来源:linux网站作者:shippoo

首先,我们要安装apt-mirror
$sudo apt-get install apt-mirror

假设我们将镜像等文件放在 /service/Ubuntu文件夹下:


请事先新建以下文件夹(mirror.list里面提示要我们事先新建文件夹的):

/service/ubuntu
/service/ubuntu/mirror
/service/ubuntu/skel
/service/ubuntu/var


配置apt-mirror:

$sudo vi /etc/apt/mirror.list
############# config ##################
#
# set base_path /var/spool/apt-mirror
#
# if you change the base path you must create the directories below with write privlages
#
# 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 base_path /service/ubuntu

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 nthreads    20
set _tilde 0
#
############# end config ##############


#我们把常用的软件同步过来就够用了
deb-i386 http://archive.Ubuntu.com/ubuntu hardy main restricted universe multiverse
deb-i386 http://archive.ubuntu.com/ubuntu hardy-updates main restricted universe multiverse
deb-i386 http://archive.ubuntu.com/ubuntu hardy-backports main restricted universe multiverse
deb-i386 http://archive.ubuntu.com/ubuntu hardy-security main restricted universe multiverse
deb-i386 http://archive.ubuntu.com/ubuntu hardy-proposed main restricted universe multiverse

#当某些软件包在服务器端进行了升级,或者服务器端不再需要这些软件包时,我们使用了 apt-mirror与服务器同步后,会在本地的$var_path/下生成一个clean.sh的脚本,列出了遗留在本地的旧版本和无用的软件包,你可以手动运行这个脚本来删除遗留在本地的且不需要用的软件包
clean http://archive.ubuntu.com/ubuntu


如果用amd64位架构下的包,可以加上deb-amd64的标记
如果什么都不加,直接使用deb http.....这种格式,则在同步时,只同步当前系统所使用的架构下的软件包。比如一个64位系统,直接debhttp....只同步64位的软件 包。如果还嫌麻烦,直接去改set defaultarch  <running hostarchitecture>这个参数就好,比如改成set defaultarch i386,这样你使用debhttp.....这种格式,则在同步时,只同步i386的软件包了。


如果你还想要源码,可以把源码也加到mirror.list里面同步过来,比如加上deb-src这样的标记。想要其他的东西也可以追加相应的标记来完成。

配置好后我们就可以和指定的镜像进行同步了
$sudo apt-mirror

如果是第一次同步,官方镜像可能需要几天时间才能同步完整,如果与国内源进行同步,只同步常用软件,平均1秒钟网速1MB(Byte)要同步30G左右的数据,大概需要5-8小时的时间才能同步完整。


同步完成后,我们可以利用clean.sh清理无用软件包(本文档以set base_path /server/ubuntu为例):
$sudo sh /service/ubuntu/var/clean.sh

更新完毕后,可以使用apache发布源镜像了。

以上摘录 我下载了68个G的 64位源 同步的是mirrors.163.com


下面配置apache2

进入httpd.conf修改
#<Directory />
#    AllowOverride none
#    Require all denied
#</Directory>

改成
<Directory />
Options FollowSymLinks
AllowOverride None
Order deny,allow
allow from all
</Directory>


在<IfModule alias_module> 节点中增加虚拟目录
<IfModule alias_module>
Alias /ubuntu /workspace/ubuntu/mirror/mirrors.163.com/ubuntu
</IfModule>


添加虚拟目录的权限
<Directory "/workspace/ubuntu/mirror/mirrors.163.com/ubuntu">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>


由于有opengrok 做了个tomcat的端口转发
ProxyPass /source http://localhost:8081/source
ProxyPassReverse /source http://localhost:8081/source


重启apache即可

客户端配置source.list

sudo vim /etc/source.list

deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty main restricted
deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty-updates main restricted
deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty universe
deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty-updates universe
deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty multiverse
deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty-updates multiverse
deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty-backports main restricted universe multiverse
deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty-security main restricted
deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty-security universe
deb [arch=amd64] http://192.168.19.184/ubuntu/ trusty-security multiverse


sudo apt-get update 即可。