Ubuntu搭建本地源

2016年3月25日14:27:34 评论 6,646

公司要开始限制所有VM直接上外网,于是就需要在本地搭建一套本地源,之前分享了一篇Centos的本地源搭建,同样今天也把Ubuntu的整理出来。

一、安装apt-mirror工具

# apt-get install apt-mirror

二、配置apt-mirror

由于源的内容比较多,所以最好可以单独划出一块盘存放,我放在/cache1/apt-soutce中

# vim /etc/apt/mirror.list

############# config ##################
#
set base_path /cache1/apt-source
#
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 40
set _tilde 0
#
############# end config ##############
##########################################trusty############################
deb-amd64 http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse

deb-i386 http://mirrors.sohu.com/ubuntu/ trusty main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/ trusty-security main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/ trusty-updates main restricted universe multiverse

##########################################precise###########################
deb-amd64 http://mirrors.sohu.com/ubuntu/ precise main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/ precise-security main restricted universe multiverse
deb-amd64 http://mirrors.sohu.com/ubuntu/ precise-updates main restricted universe multiverse

deb-i386 http://mirrors.sohu.com/ubuntu/ precise main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/ precise-proposed main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/ precise-security main restricted universe multiverse
deb-i386 http://mirrors.sohu.com/ubuntu/ precise-updates main restricted universe multiverse

三、配置定时同步

# vim /etc/cron.d/apt-mirror

0 0 * * 0 apt-mirror /usr/bin/apt-mirror > /cache1/apt-source/var/cron.log

四、开始同步

同步过程会有提示,也可以中断,下次只要再次运行apt-mirror还会继续

# apt-mirror

五、搭建web服务

我使用的是nginx,根据自己喜好选择。

把源链接到/var/www下面

# cd /var/www

# ln -s /cache1/apt-source/mirror/mirrors.sohu.com/ubuntu ubuntu

六、更新本地源

源设置的是"deb http://",默认是同步64位的包,如果需要32位的支持需改成"deb-i386 http://"

# vim /etc/apt/sources.list

deb http://xx.xx.xx.xx/ubuntu precise main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu precise-backports main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu precise-proposed main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu precise-updates main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu precise-security main multiverse restricted universe
deb http://xx.xx.xx.xx/ubuntu precise-security main multiverse restricted universe

设置完成后,更新apt数据库信息

# apt-get update
weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: