ubuntu下的apt-get内网本地源的搭建

1、安装apt-mirror

apt-get install apt-mirror

2、修改apt-mirror配置文件

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/ trusty main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ trusty-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目录下还有其他的地址为名的目录。
在这里插入图片描述
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://[host]:[port]/ubuntu

客户端配置:
1、编辑/etc/apt/source.list,加入以下内容

# Local Source      
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty-security main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty-updates main restricted universe multiverse  
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty-proposed main restricted universe multiverse
deb [arch=amd64] http://[host]:[port]/ubuntu/ trusty-backports main restricted universe multiverse

2、更新apt-get源

apt-update
要在内网中使用Apache2搭建Apt本地的服务端,可以按照以下步骤进行操作: 1. 安装Apache2和apt-mirror软件包: ``` sudo apt-get update sudo apt-get install apache2 apt-mirror ``` 2. 配置apt-mirror: 在/etc/apt/mirror.list文件中添加以下内容: ``` # 镜像的地址,可以根据需要修改 deb http://archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse deb http://archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse # 本地存储的路径,可以根据需要修改 clean http://localhost/apt-mirror ``` 3. 执行apt-mirror命令: ``` sudo apt-mirror ``` 这个命令会下载所需的软件包并将其存储在本地路径中。 4. 配置Apache2: 在/etc/apache2/sites-enabled/000-default.conf文件中添加以下内容: ``` Alias /apt-mirror /var/spool/apt-mirror/mirror/archive.ubuntu.com/ubuntu <Directory /var/spool/apt-mirror/mirror/archive.ubuntu.com/ubuntu> Options Indexes FollowSymLinks AllowOverride None Require all granted </Directory> ``` 5. 重启Apache2: ``` sudo systemctl restart apache2 ``` 现在,您的Apt本地服务端已经搭建完成了。您可以通过以下方式在内网中使用它: 在客户端的/etc/apt/sources.list文件中添加以下内容: ``` deb http://localhost/apt-mirror/archive.ubuntu.com/ubuntu/ bionic main restricted universe multiverse deb http://localhost/apt-mirror/archive.ubuntu.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://localhost/apt-mirror/archive.ubuntu.com/ubuntu/ bionic-backports main restricted universe multiverse deb http://localhost/apt-mirror/archive.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse ``` 然后执行以下命令更新软件包列表: ``` sudo apt-get update ``` 现在,您可以在内网中使用Apt本地服务端了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值