搭建本地镜像源解决方案



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
    评论
搭建本地apt镜像源是为了提高软件包下载速度并减轻网络流量,特别是在网络状况较差或者需要频繁更新的环境中。以下是搭建本地apt镜像源的步骤: 1. 确保已经安装了一个可用的Linux发行版,如Ubuntu,Debian等,并且已经连接到互联网。 2. 打开终端,在命令行下执行以下命令以安装所需的软件包: ``` $ sudo apt-get install apt-mirror ``` 3. 编辑`/etc/apt/mirror.list`文件,创建一个新的镜像源配置文件。配置文件中的注释提供了每个设置的说明,根据自己的需求进行相应的修改。确保设置`mirror_dir`为要存储镜像的本地目录。 4. 运行以下命令以启动apt-mirror并开始下载软件包: ``` $ sudo apt-mirror ``` apt-mirror将根据配置文件中的设置下载软件包并保存到本地目录。这可能需要一些时间,具体的时间取决于镜像源的大小以及当前的网络速度。 5. 当下载完成后,你可以通过将本地镜像源添加为apt的源来使用它。编辑`/etc/apt/sources.list`文件,并将以下行添加到文件中: ``` deb file:/path/to/local/mirror ``` 将`/path/to/local/mirror`替换为实际镜像存储目录的路径。 6. 最后,执行以下命令以更新apt缓存并开始使用本地镜像源: ``` $ sudo apt-get update ``` 现在,你可以使用本地apt镜像源来安装软件包,它将从本地目录中读取软件包,而不是从互联网上下载。 通过搭建本地apt镜像源,你可以显著提高软件包下载速度,减轻网络负载,并获得更好的软件包管理体验。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值