ubuntu14.04用apt-mirror 制作ubuntu本地镜像源

sudo apt-get install apt-mirror

首先修改/etc/apt/mirror.list,使用cn.archive.ubuntu.com的源作镜像,即在所有archive.ubuntu.com前加上cn.:gksu gedit /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 
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

deb http://cn.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
#deb http://cn.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
#deb http://cn.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse

deb-src http://cn.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
#deb-src http://cn.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
#deb-src http://cn.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse

clean http://cn.archive.ubuntu.com/ubuntu

--------------------- 内容完 ------------------------
然后运行

apt-mirror

出错:

~$ apt-mirror
flock() on closed filehandle LOCK_FILE at /usr/bin/apt-mirror line 206.
apt-mirror is already running, exiting at /usr/bin/apt-mirror line 209.

ls -l 查看/usr/bin/apt-mirror的权限: drwxr-xr-x 5 apt-mirror apt-mirror 4096 11\u6708 10 12:37 apt-mirror

权限是 apt-mirror:apt-mirror

修改为当前用户权限 sudo chown : /usr/bin/apt-mirror

这里用当前用户名替换

修改目录权限:sudo chmod 777 -R /var/spool/apt-mirror

再运行 apt-mirror , 开始下载镜像:(如果没有裁减,将下载135G)

......

135.0 GiB will be downloaded into archive.
Downloading 119219 archive files using 20 threads...
======================================================================

下面是完整镜像ubuntu14.04的mirror.list文件设置

对于i386

############# config ##################
#
set base_path    /var/spool/apt-mirror-i386
#
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  i386
set postmirror_script $var_path/postmirror.sh
set run_postmirror 0
set nthreads     20
set _tilde 0
#
############# end config ##############

deb http://cn.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb http://cn.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse

deb-src http://cn.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb-src http://cn.archive.ubuntu.com/ubuntu trusty-backports main restricted universe multiverse

deb http://security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted
deb http://security.ubuntu.com/ubuntu trusty-security universe
deb-src http://security.ubuntu.com/ubuntu trusty-security universe
deb http://security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse
deb http://extras.ubuntu.com/ubuntu trusty main
deb-src http://extras.ubuntu.com/ubuntu trusty main

clean http://cn.archive.ubuntu.com/ubuntu

对于amd64,将上面的i386都换成amd64即可。注意建立/var/spool/apt-mirror-amd64目录及子目录 mirror skel var 并设置权限。

==============================================

使用做好的镜像源。有两种方法:1 安装web服务,类似网上镜像;2 直接文件访问,简单,可放入移动硬盘

1, 安装web服务

安装apache网站服务器

sudo apt-get install apache2

缺省的网站主目录为 /var/www/html

建立镜像目录软链接

sudo ln -s /var/spool/apt-mirror-i386/mirror /var/www/html/ubuntu-mirror-i386

察看目录

ls /var/www/html/ubuntu-mirror-i386
cn.archive.ubuntu.com  extras.ubuntu.com  security.ubuntu.com

察看本机ip地址

ifconfig

eth0      192.168.0.101

编辑源列表 gksu gedit /etc/apt/sources.list,在http://后面加上192.168.0.101/ubuntu-mirror-i386/,如下

#deb cdrom:[Ubuntu 14.04.3 LTS _Trusty Tahr_ - Beta i386 (20150805)]/ trusty main restricted

# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty main restricted
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty main restricted

## Major bug fix updates produced after the final release of the
## distribution.
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-updates main restricted

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty universe
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty universe
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-updates universe
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-updates universe

## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty multiverse
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty multiverse
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-updates multiverse

## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.

## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src http://192.168.0.101/ubuntu-mirror-i386/cn.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse

deb http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security main restricted
deb-src http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security main restricted
deb http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security universe
deb-src http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security universe
deb http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security multiverse
deb-src http://192.168.0.101/ubuntu-mirror-i386/security.ubuntu.com/ubuntu trusty-security multiverse

## Uncomment the following two lines to add software from Canonical's
## 'partner' repository.
## This software is not part of Ubuntu, but is offered by Canonical and the
## respective vendors as a service to Ubuntu users.
# deb http://archive.canonical.com/ubuntu trusty partner
# deb-src http://archive.canonical.com/ubuntu trusty partner

## This software is not part of Ubuntu, but is offered by third-party
## developers who want to ship their latest software.
deb http://192.168.0.101/ubuntu-mirror-i386/extras.ubuntu.com/ubuntu trusty main
deb-src http://192.168.0.101/ubuntu-mirror-i386/extras.ubuntu.com/ubuntu trusty main

保存,然后执行

sudo apt-get update 更新源列表

测试,安装dia图表制作软件

sudo apt-get install dia

下载7M多软件包1秒完成。


2 直接文件访问

如果不想安装web服务,可以直接文件访问镜像。

修改 /etc/apt/sources.list

将http://192.168.0.101/ubuntu-mirror-i386/全部替换为file:///var/spool/apt-mirror-i386/mirror/即可

保存,然后执行

sudo apt-get update 更新源列表

此方法可以不建立软连接

如果镜像在移动磁盘,路径替换为移动磁盘镜像就行了

==================================================================

apt-mirror可以随时ctrl+c退出,重新开始。利用空闲时间建立的ubuntu镜像,显著减少了安装软件包的下载时间,提高了效率。

对于当前以T计的磁盘容量,存储镜像早已不是问题。



你可能感兴趣的:(ubuntu14.04用apt-mirror 制作ubuntu本地镜像源)