当前位置: 代码迷 >> 综合 >> apt-mirror deploy local source 16.04 and 18.04
  详细解决方案

apt-mirror deploy local source 16.04 and 18.04

热度:124   发布时间:2023-09-07 08:33:54.0

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
 
 
环境

System Edition Hostname IP
Ubuntu18.04 repository 192.168.16.130
Ubuntu16.04 cli16 192.168.16.133
Ubuntu16.04 cli18 192.168.16.134

文章导航

  • 一、Create repository directory
  • 二:Install and Deploy apt-mirror
  • 三、Install Apache2
  • 四:Install nginx
  • 五:Download source
  • 六:Client update test

 

一、Create repository directory

root@repository:~# mkdir /data
root@repository:~# mkdir -p /data/{18.04,16.04}
root@repository:~# mkdir -p /data/16.04/{mirror,var,skel}
root@repository:~# mkdir -p /data/18.04/{mirror,var,skel}

apt-mirror deploy local source 16.04 and 18.04

二:Install and Deploy apt-mirror

1、Install pack

root@repository:~# apt install apt-mirror
root@repository:/etc/apt# cp mirror.list mirror.list.16.04
root@repository:/etc/apt# cp mirror.list mirror.list.18.04
root@repository:/etc/apt# mv mirror.list mirror.list.bak

2、Configure source
PS:每一种架构(amd64/i386)都需要有5行的内容

root@repository:/etc/apt# vim mirror.list.16.04    # configure 16.04
############# config ##################
#
# set base_path    /var/spool/apt-mirror
set base_path    /data/16.04  #设置下载指定路径
set defaltarch amd64          #指定版本
#
# 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>
# 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/ 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
root@repository:/etc/apt# vim mirror.list.18.04   # configure 18.04
############# config ##################
#
# set base_path    /var/spool/apt-mirror
set base_path    /data/18.04  #设置下载指定路径
set defaltarch amd64          #指定版本
#
# 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>
# 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-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security 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

3、编写定时同步源脚本

root@repository:/etc/apt# mkdir /usr/local/script
root@repository:/etc/apt# vim /usr/local/script/apt-mirror.sh
#!/bin/bash/bin/cp -rf /etc/apt/mirror.list.16.04 /etc/apt/mirror.list && \
/usr/bin/apt-mirror && /bin/sh /data/16.04/var/clean.sh && \
/bin/cp -rf /etc/apt/mirror.list.18.04 /etc/apt/mirror.list && \
/usr/bin/apt-mirror && /bin/sh /data/18.04/var/clean.sh
root@repository:/etc/apt#
root@repository:/etc/apt# chmod +x /usr/local/script/apt-mirror.sh

4、加入定时任务

# update apt source
0 1 * * * /bin/sh /usr/local/script/apt-mirror.sh > /var/log/apt-mirror.log 2>&1 &

三、Install Apache2

root@repository:/etc/apt# apt -y install apache2
root@repository:~# cd /etc/apache2/

Modify default port

root@repository:/etc/apache2# cp ports.conf ports.conf.bak
root@repository:/etc/apache2# vim ports.conf

apt-mirror deploy local source 16.04 and 18.04Modify data directory

root@repository:/etc/apache2# cp apache2.conf apache2.conf.bak
root@repository:/etc/apache2# vim apache2.conf

apt-mirror deploy local source 16.04 and 18.04
Configure virtual host

root@repository:/etc/apache2# vim /etc/apache2/sites-available/000-default.conf

apt-mirror deploy local source 16.04 and 18.04
Add index directory

root@repository:/etc/apache2# vim mods-available/dir.conf
<IfModule mod_dir.c>DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm /data
</IfModule>
apt-mirror deploy local source 16.04 and 18.04

Hide apache2 edition

root@repository:/etc/apache2# vim conf-enabled/security.conf

apt-mirror deploy local source 16.04 and 18.04

root@repository:/etc/apache2# source /etc/apache2/envvars		# 重新导入环境变量
root@repository:/etc/apache2# systemctl start apache2
root@repository:/etc/apache2# systemctl enable apache2
root@repository:/etc/apache2# ufw enable
root@repository:/etc/apache2# ufw allow 8080/tcp
root@repository:/etc/apache2# netstat -nltup |grep 8080

至此,可以通过ip:8080访问
apt-mirror deploy local source 16.04 and 18.04

四:Install nginx

root@repository:~# apt install nginx
root@repository:~# cd /etc/nginx/
root@repository:/etc/nginx# vim nginx.conf
server_tokens off;		# 隐藏版本upstream apt_yum {server 192.168.16.130:8080 weight=10 max_fails=120 fail_timeout=1200s;}server {listen 80;server_name 192.168.16.130;location /ubuntu/16.04/ {proxy_pass  http://apt_yum/16.04/mirror/mirrors.aliyun.com/ubuntu/;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;}location /ubuntu/18.04/ {proxy_pass  http://apt_yum/18.04/mirror/mirrors.aliyun.com/ubuntu/;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr;proxy_set_header x-forwarded-for $proxy_add_x_forwarded_for;}}
}

apt-mirror deploy local source 16.04 and 18.04

root@repository:/etc/nginx# systemctl start nginx
root@repository:/etc/nginx# systemctl enable nginx
root@repository:/etc/nginx# ufw delete allow 8080/tcp	# 禁止apache2 8080对外
root@repository:/etc/nginx# ufw allow http
root@repository:/etc/nginx# ufw verbose

 
至此可以通过 http://192.168.16.130/ubuntu/16.04/ 访问
apt-mirror deploy local source 16.04 and 18.04

五:Download source

Download 16.04 source,18.04操作相同,这里忽略

root@repository:/etc/apt# cp -rf mirror.list.16.04 mirror.list
root@repository:/etc/apt# apt-mirror

apt-mirror deploy local source 16.04 and 18.04
apt-mirror deploy local source 16.04 and 18.04

六:Client update test

1、Ubuntu16.04 test

root@cli16:/etc/apt# cp -a sources.list sources.list.bak
root@cli16:/etc/apt# >sources.list
root@cli16:/etc/apt# vim sources.list
deb [arch=amd64] http://192.168.16.130/ubuntu/16.04 xenial main restricted universe multiverse
deb [arch=amd64] http://192.168.16.130/ubuntu/16.04 xenial-security main restricted universe multiverse
deb [arch=amd64] http://192.168.16.130/ubuntu/16.04 xenial-updates main restricted universe multiverse
deb [arch=amd64] http://192.168.16.130/ubuntu/16.04 xenial-proposed main restricted universe multiverse
deb [arch=amd64] http://192.168.16.130/ubuntu/16.04 xenial-backports main restricted universe multiverse
root@cli16:/etc/apt#
root@cli16:/etc/apt# apt update

apt-mirror deploy local source 16.04 and 18.04
2、Ubuntu18.04 test

root@cli18:/etc/apt# cp -a sources.list sources.list.bak
root@cli18:/etc/apt# > sources.list
root@cli18:/etc/apt# vim sources.list
deb [arch=amd64] http://192.168.16.130/ubuntu/18.04 bionic main restricted universe multiverse
deb [arch=amd64] http://192.168.16.130/ubuntu/18.04 bionic-updates main restricted universe multiverse
deb [arch=amd64] http://192.168.16.130/ubuntu/18.04 bionic-security main restricted universe multiverse
deb [arch=amd64] http://192.168.16.130/ubuntu/18.04 bionic-proposed main restricted universe multiverse
deb [arch=amd64] http://192.168.16.130/ubuntu/18.04 bionic-backports main restricted universe multiverse
root@cli18:/etc/apt#
root@cli18:/etc/apt# apt update

apt-mirror deploy local source 16.04 and 18.04
Complete!
 
 
 
 
 
参考链接:https://blog.csdn.net/fanwanli04/article/details/79622726

  相关解决方案