Ubuntu本地镜像搭建
2.1 本地镜像搭建的主要步骤
使用apt-mirror下载镜像文件到本地
计划任务定期更新
使用nginx发布
客户端使用测试
2.2 具体实现过程
2.2.1 apt-mirror的安装配置和使用
(1) 安装apt-mirror
$ sudo apt-get install apt-mirror
(2) apt-mirror配置
编辑配置文件/etc/apt/mirror.list,以ubuntu 14.04 为例:
############# config ##################
#
set base_path /var/spool/apt-mirror
#
set mirror_path /data/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 nthreads20#用20个线程去wget镜像
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-i386 http://cn.archive.ubuntu.com/ubuntu trusty main restricted universe multiverse
deb-i386 http://cn.archive.ubuntu.com/ubuntu trusty-security main restricted universe multiverse
deb-i386 http://cn.archive.ubuntu.com/ubuntu trusty-updates main restricted universe multiverse
deb-i386 http://cn.archive.ubuntu.com/ubuntu trusty-proposed main restricted universe multiverse
deb-i386 http://cn.archive.ubuntu.com/ubun trustytu-backports main restricted universe multiverse
# 如果这个源是要用来做pxe启动的话需要添加(因为默认没有将这几个文件同步过来)
deb http://cn.archive.ubuntu.com/ubuntu trusty main/debian-installer restricted/debian-installer universe/debian-installer multiverse/debian-installer
deb-i386 ttp://cn.archive.ubuntu.com/ubuntu trusty main/debian-installer restricted/debian-installer universe/debian-installer multiverse/debian-installer
(3)镜像官方仓库所有软件
$ sudo apt-mirror //apt-mirror成功后会执行/var/spool/apt-mirror/var/clean.sh完成同步后的清理工作
2.2.2 源的升级与更新
(1)日常升级
$ sudo apt-mirror
(2)计划任务自动更新
0 4 * * * /usr/bin/apt-mirror >> /var/spool/apt-mirror/var/cron.log
2.3 使用nginx搭建本地镜像源
2.3.1 nginx 安装配置
(1) nginx 安装
参考:官方文档
(2) nginx 基本配置
编辑配置文件 /usr/local/nginx/conf/sites-enabled/mirror.conf
server {
listen 80;
server_name _;
root /data/mirror/web;
autoindex on;
}
在/data/mirror/web
目录做一个镜像目录的软连接
$ ln -s /data/mirror/archive.ubuntu.com/ubuntu/ /data/mirror/web/ubuntu
(3) 启动nginx服务
$ sudo /usr/local/nginx/sbin/nginx -t
$ sudo /usr/local/nginx/sbin/nginx
(4) 本地测试
在浏览器输入搭建nginx机器IP,也可以配置域名访问
2.5 客户端使用测试
(1) 编辑配置文件 /etc/apt/sources.list 或在/etc/apt/sources.list.d/ 目录下新建文件,并在文件最前面写入如下字段:
deb http://10.249.17.26/ubuntu precise main universe
(2) 使用
$ apt-get update
$ apt-get install (packagename)