Ubuntu2004制作本地源并发布

1、安装apt-mirror
apt-get install apt-mirror
2、修改apt-mirror配置文件
在修改配置文件之前,我们首先要确定自己系统的版本,命令:sudo lsb_release -a

$sudo lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 16.04 LTS
Release: 16.04
Codename: xenial
Codename代号的意思,16.04代号xenial,所以我们接下来的配置文件跟xenial有关,当然14.04代号是trusty,一样的操作。
打开 阿里云源(也可以使用别的源,网址可以自己百度)
进入dists目录,在目录下找到跟系统代号相关问文件夹,一般是5个,将下面规则文本复制出来,把加粗部分替换成相应的5个文件目录名。进入这5个目录,里面有4个跟源有关的目录(by-hash除外),目录名与下面斜体部分比较,如果不一样请修改。

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

然后

vim /etc/apt/mirror.list

参考以下配置文件:
清空原有的配置文件,修改以下配置文件相应代号部分即可,如果想添加多个版本的源,可以依次在下面增加相应的规则(就是增加对应代号的源地址)

############# config ##################
# 以下注释的内容都是默认配置,如果需要自定义,取消注释修改即可
set base_path /var/spool/apt-mirror
#
# 镜像文件下载地址
# set mirror_path $base_path/mirror
# 临时索引下载文件目录,也就是存放软件仓库的dists目录下的文件(默认即可)
# set skel_path $base_path/skel
# 配置日志(默认即可)
# set var_path $base_path/var
# clean脚本位置
# set cleanscript $var_path/clean.sh
# 架构配置,i386/amd64,默认的话会下载跟本机相同的架构的源
set defaultarch amd64
# set postmirror_script $var_path/postmirror.sh
# set run_postmirror 0
# 下载线程数
set nthreads 20
set _tilde 0
#
############# end config ##############
# Ali yun(这里没有添加deb-src的源)
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

clean http://mirrors.aliyun.com/ubuntu

3、开始同步
执行 apt-miiror

然后等待很长时间(该镜像差不多100G左右,具体时间看网络环境),同步的镜像文件目录为/var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu/,当然如果增加了其他的源,在/var/spool/apt-mirror/mirror目录下还有其他的地址为名的目录。

注意:当apt-mirror 被意外中断时,只需要重新运行即可,apt-mirror支持断点续存;另外,意外关闭,需要在/var/spool/apt-mirror/var目录下面删除 apt-mirror.lock文件【 sudo rm apt-mirror.lock 】,之后执行apt-mirror重新启动

4、安装apache2
apt-get install apache2

由于Apache2的默认网页文件目录位于/var/www/html,因此,可以做个软链接(这样我们就可以直接访问了,无需将其直接导入该目录)

ln -s /var/spool/apt-mirror/mirror/mirrors.aliyun.com/ubuntu /var/www/html/ubuntu

然后就可以通过如下地址访问了

http://127.0.0.1/ubuntu
#ip和port是自己本机的,其中端口默认为80
在测试时可能遇到打不开的情况,查看下iptables规则是否限制或者selinux的问题(这点相信大家在学习lanmp的时候都已经了解过了)

客户端配置:
1、编辑/etc/apt/source.list,参考以下内容(以下是64位机,ubuntu16.04),修改相应的代号,硬件架构arch,加入文件中

# Local Source      #ip和port是自己本机的,其中端口默认为80
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial-security main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial-updates main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial-proposed main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ xenial-backports main restricted universe multiverse

2、更新apt-get源

sudo apt-get update    #这步很重要
sudo apt-get upgrade

 

 

执行apt-get update时,本身amd64的系统,竟然找i386的package,例如:

Reading package lists... Done
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal-security/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal-updates/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal-proposed/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Failed to fetch http://127.0.0.1/ubuntu/dists/focal-backports/main/binary-i386/Packages 404 Not Found [IP: 127.0.0.1 80]
E: Some index files failed to download. They have been ignored, or old ones used instead.

 

此时,需要修改/etc/apt/sources.list文件,指定架构即可

# Local Source      #ip和port是自己本机的,其中端口默认为80
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal main restricted universe multiverse
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal-security main restricted universe multiverse
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal-updates main restricted universe multiverse
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal-proposed main restricted universe multiverse
deb [arch=amd64] http://127.0.0.1/ubuntu/ focal-backports main restricted universe multiverse

posted @ 2021-12-10 15:13  二虎  阅读(364)  评论(1编辑  收藏  举报