通过apt-mirror建立ubuntu离线软件源

ubuntu server的官方ISO只有几百兆,在离线环境的或者网络不佳的环境下,通过apt-get安装软件包及其依赖就是一件很痛苦的事情。

不过,我们可以通过apt-mirror将apt软件源下载到本地,建立本地的镜像源。制作方法如下:

apt-get install apt-mirror

如果只使用deb二进制包,完成克隆一个外部的mirror可能需要60G大小的空间,如果需要源码的话,则可能需要130G的空间不等。

mkdir /data/apt-mirror

vim /etc/apt/mirror.list
 
############# config ##################
#
 
set base_path    /data/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  # set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############
 
deb http://mirrors.aliyun.com/ubuntu trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu trusty-updates main restricted universe multiverse
#deb http://mirrors.aliyun.com/ubuntu trusty-proposed main restricted universe multiverse
#deb http://mirrors.aliyun.com/ubuntu trusty-backports main restricted universe multiverse
 
deb-src http://mirrors.aliyun.com/ubuntu trusty main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu trusty-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu trusty-updates main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu trusty-proposed main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu trusty-backports main restricted universe multiverse
 
clean http://mirrors.aliyun.com/ubuntu

说明:

  • set base_path /data/apt-mirror设置deb包下载到哪个目录;
  • set nthreads 20 启动20个线程下载;

apt-mirror

说明:

  • 支持断点续传,任何中断都不会造成影响;
  • 定时执行上面的命令,可以达到定时同步远程仓库的效果;

#建立软链接
ln -s /data/apt-mirror/mirror/mirrors.aliyun.com /data/mirrors
cd /etc/apt
mv source.list source.list.bak
vim source.list
 
#加入如下内容
deb file:///data/mirrors/ubuntu  trusty main restricted universe multiverse
deb file:///data/mirrors/ubuntu  trusty-security main restricted universe multiverse
deb file:///data/mirrors/ubuntu  trusty-updates main restricted universe multiverse
deb file:///data/mirrors/ubuntu  trusty-proposed main restricted universe multiverse
deb file:///data/mirrors/ubuntu  trusty-backports main restricted universe multiverse

#创建一个软链接
ln -s /data/apt-mirror/mirror/mirrors.aliyun.com/ubuntu  /var/www/html/ubuntu
#局域网中每个ubuntu用户都可以执行以下命令
 
vi /etc/hosts
10.10.10.10 local.sysit.cn
 
cd /etc/apt
mv source.list source.list.bak
 
vim source.list
#加入如下内容
deb http://local.sysit.cn/ubuntu trusty main restricted universe multiverse
deb http://local.sysit.cn/ubuntu trusty-security main restricted universe multiverse
deb http://local.sysit.cn/ubuntu trusty-updates main restricted universe multiverse
deb http://local.sysit.cn/ubuntu trusty-proposed main restricted universe multiverse
deb http://local.sysit.cn/ubuntu trusty-backports main restricted universe multiverse
  • linux/ubuntu/setup-apt-mirros.txt
  • 最后更改: 2019/04/16 18:31
  • (外部编辑)