Ubuntu使用nginx搭建本地镜像源,局域网部署

因内网搭建开发环境,需要做一个Ubuntu的本地镜像源。

一、镜像获取

1、先确认需要的镜像源的名称,可从https://help.ubuntu.com/ 查询

 2、在Ubuntu下安装apt-mirror

sudo apt-get install apt-mirror

3、修改apt-mirror配置文件

sudo vi /etc/apt/mirror.list

我的配置文件如下:

############# config ##################
# 以下注释的内容都是默认配置,如果需要自定义,取消注释修改即可
# set base_path    /var/spool/apt-mirror
set base_path  /opt/mirror/ubuntu # #
set mirror_path $base_path/mirror # set skel_path $base_path/skel # set var_path $base_path/var # set cleanscript $var_path/clean.sh # 架构配置,i386/amd64,默认下载与本机相同的架构 # set defaultarch amd64 # set defaultarch <running host architecture> # set postmirror_script $var_path/postmirror.sh # set run_postmirror 0 set nthreads 20 set _tilde 0 # ############# end config ############## # 下载18.04版本的镜像源bionic,如果需要其他版本,将bionic替换成对应版本的英文名称即可。名称从https://help.ubuntu.com/查询 deb-i386 http://mirrors.aliyun.com/ubuntu bionic main restricted universe multiverse deb-i386 http://mirrors.aliyun.com/ubuntu bionic-security main restricted universe multiverse deb-i386 http://mirrors.aliyun.com/ubuntu bionic-updates main restricted universe multiverse deb-i386 http://mirrors.aliyun.com/ubuntu bionic-proposed main restricted universe multiverse deb-i386 http://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse
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
#deb-src http://mirrors.aliyun.com/ubuntu bionic main restricted universe multiverse 
#deb-src http://mirrors.aliyun.com/ubuntu bionic-security main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu bionic-updates main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu bionic-proposed main restricted universe multiverse
#deb-src http://mirrors.aliyun.com/ubuntu bionic-backports main restricted universe multiverse

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

4、创建镜像的本地目录

sudo mkdir -p /opt/mirrors/ubuntu

5、开始拉取镜像

sudo apt-mirror

二、本地镜像源的部署

1、安装web服务器(nginx)

sudo apt-get install nginx

2、配置web服务

sudo vi /etc/nginx/sites-available/default

我的配置如下:

server {
        listen 80 default_server;
        listen [::]:80 default_server;
        root /var/www/html;
        index index.html index.htm index.nginx-debian.html;
        server_name _;

        location / {
                try_files $uri $uri/ =404;
                autoindex on;
                autoindex_exact_size off;
                autoindex_localtime on;
        }
}

3、镜像服务挂载

sudo ln -s /opt/mirrors/ubuntu/mirror/mirrors.aliyun.com/ubuntu /var/www/html/ubuntu

4、重新载入 nginx 服务

sudo service nginx reload

此时使用浏览器访问 http://127.0.0.1/ubuntu ,应该可以在 web 界面中浏览本地仓库中的软件包

三、局域网机器使用本地镜像源

1、修改更新源

sudo vi /etc/apt/sources.list

参考配置如下(127.0.0.1替换成前面部署的机器ip):

deb http://127.0.0.1/ubuntu/ bionic main restricted universe multiverse
deb http://127.0.0.1/ubuntu/ bionic-updates main restricted universe multiverse
deb http://127.0.0.1/ubuntu/ bionic-backports main restricted universe multiverse
deb http://127.0.0.1/ubuntu/ bionic-security main restricted universe multiverse
deb http://127.0.0.1/ubuntu/ bionic-proposed main restricted universe multiverse

2、更新系统

sudo apt-get upgrade

3、更新软件索引

sudo apt-get update

4、软件安装

sudo apt-get install

 

posted on 2020-07-31 14:29  修身  阅读(3284)  评论(2编辑  收藏  举报

导航