搭建本地镜像源解决方案



1. 安装apt-mirror

sudoapt-get install apt-mirror

2.挂载硬盘到/data目录,用来存放下载下来的镜像文件

/data目录下新建以下几个文件夹

/data/ubuntu

/data/ubuntu/mirror

/data/ubuntu/skel

/data/ubuntu/var



3. 配置apt-mirror

打开/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 <running host architecture>

替换为

#############config ##################









setbase_path /data/ubuntu

setmirror_path $base_path/mirror

setskel_path $base_path/skel

setvar_path $base_path/var

setcleanscript $var_path/clean.sh

setdefaultarch <running host architecture>

#############end config ##############



#把常用的软件同步过来

#See http://help.ubuntu.com/community/UpgradeNotes for how to upgradeto

#newer versions of the distribution.

debhttp://us.archive.ubuntu.com/ubuntu/ xenial main restricted

#deb-src http://us.archive.ubuntu.com/ubuntu/ xenial main restricted

##Major bug fix updates produced after the final release of the

##distribution.

debhttp://us.archive.ubuntu.com/ubuntu/ xenial-updates main restricted

#deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates mainrestricted

##N.B. software from this repository is ENTIRELY UNSUPPORTED by theUbuntu

##team. Also, please note that software in universe WILL NOT receiveany

##review or updates from the Ubuntu security team.

debhttp://us.archive.ubuntu.com/ubuntu/ xenial universe

#deb-src http://us.archive.ubuntu.com/ubuntu/ xenial universe

debhttp://us.archive.ubuntu.com/ubuntu/ xenial-updates universe

#deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updates universe







##N.B. software from this repository is ENTIRELY UNSUPPORTED by theUbuntu

##team, and may not be under a free licence. Please satisfy yourself asto

##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.

debhttp://us.archive.ubuntu.com/ubuntu/ xenial multiverse

#deb-src http://us.archive.ubuntu.com/ubuntu/ xenial multiverse

debhttp://us.archive.ubuntu.com/ubuntu/ xenial-updates multiverse

#deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-updatesmultiverse

##N.B. software from this repository may not have been tested as

##extensively as that contained in the main release, although itincludes

##newer versions of some applications which may provide usefulfeatures.

##Also, please note that software in backports WILL NOT receive anyreview

##or updates from the Ubuntu security team.

debhttp://us.archive.ubuntu.com/ubuntu/ xenial-backports main restricteduniverse multiverse

#deb-src http://us.archive.ubuntu.com/ubuntu/ xenial-backports mainrestricted universe 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 andthe

##respective vendors as a service to Ubuntu users.

#deb http://archive.canonical.com/ubuntu xenial partner

#deb-src http://archive.canonical.com/ubuntu xenial partner







debhttp://security.ubuntu.com/ubuntu xenial-security main restricted

#deb-src http://security.ubuntu.com/ubuntu xenial-security mainrestricted

debhttp://security.ubuntu.com/ubuntu xenial-security universe

#deb-src http://security.ubuntu.com/ubuntu xenial-security universe

debhttp://security.ubuntu.com/ubuntu xenial-security multiverse

deb[arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntuxenial stable

#deb-src [arch=amd64]https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu xenial stable

#deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse

cleanhttp://archive.ubuntu.com/ubuntu

保存退出,执行

sudo apt-mirror 进行同步





4.安装nginx

sudoapt-get install nginx


5.配置nginx,打开/etc/nginx/sites-enabled/default,将其替换为以下文件

server{


listen80;


#这里填写你的域名,填写localhost就直接通过IP地址访问


server_name169.168.66.66;


#显示目录


autoindexon;


location/ {


indexindex.html index.htm;


#这里填写镜像保存位置


root/data/ubuntu/mirror/archive.ubuntu.com/ubuntu;


}


access_log/var/log/nginx/localhost.log;


}



6.保存更改,执行以下命令

sudonginx -t

sudoservice nginx restart

此时服务器端已完成配置


7.配置定时同步


打开/etc/cron.d/apt-mirror中,取消最后一行的#注释即可生效:

0 4 * * * apt-mirror /usr/bin/apt-mirror >/var/spool/apt-mirror/var/cron.log
以上设置每日4点同步一次


8.客户端配置

先备份好/etc/apt/source.list

然后新建source.list,将配置好的服务器ip替换自建源ip





























9.错误解决

9.1当出现以下错误Err:5http://192.168.60.60/ubuntu xenial Release


404 Not Found


解决办法,增加链接符

/data/ubuntu/mirror/archive.ubuntu.com/ubuntu$sudo ln -s /data/ubuntu/mirror/archive.ubuntu.com/ubuntu/dists/xenial




9.2 当错误出现GPGerror报错时

需添加GPGkey,添加某些package时,基本都需要添加GPGkey,官方网站一般都会给出

sudoapt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值