ubuntu搭建apt内网本地源

1.安装apt-mirror

$ sudo apt-get install apt-mirror

2.修改apt-mirror配置文件

2.1确定系统版本

在修改配置文件之前,首先要确定服务器系统的版本(在内网中不能联网的那台机器),命令:

$ sudo lsb_release -a		#方法1
-->

No LSB modules are available.
 Distributor ID: Ubuntu
 Description: Ubuntu 18.04.4 LTS
 Release: 18.04
 Codename: bionic		#Codename表示代号
 # 14.04代号trusty,16.04代号xenial,18.04代号bionic
 
 
 $ uname -a		#方法2
-->

Linux 123 5.3.0-42-generic #34~18.04.1-Ubuntu SMP Fri Feb 28 13:42:26 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux


$ cat /proc/version		#方法3
-->

Linux version 5.3.0-42-generic (buildd@lcy01-amd64-019) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #34~18.04.1-Ubuntu SMP Fri Feb 28 13:42:26 UTC 2020

2.2修改软件源配置

修改可联网机器的软件源文件,使软件源版本与内网不能联网机器的版本对应

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

更改配置文件:

$ sudo vim /etc/apt/mirror.list

配置文件:

# 以下注释的内容都是默认配置,如果需要自定义,取消注释修改即可
set base_path /home/test/ubuntu   ----下载路径
#
# 镜像文件下载地址
# 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 ##############
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
 
clean http://mirrors.aliyun.com/ubuntu

3、同步软件源

$ sudo apt-miiror			#执行此命令,将会下载软件源内所有的文件。

会出现类似倒计时一样 20 19 18
下载大约135G左右,所以下载目录空间要够。

4、安装web服务

$ sudo apt-get install apache2		#安装apache2服务

Apache2的默认网页文件目录位于/var/www/html,可以做个软链接

$ ln -s /home/test/ubuntu/mirror/mirrors.aliyun.com/ubuntu /var/www/html/ubuntu

通过浏览器访问:http://192.168.20.6

ip是上述配置web服务,作为更新源的机器。 port:端口默认80

5.内网机器配置

编辑/etc/apt/source.list,参考以下内容(以下是64位机,ubuntu18.04),修改相应的代号,硬件架构arch,加入文件

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

更新apt-get源

sudo apt-get update
sudo apt-get upgrade

发表评论

后才能评论