ubuntu18本地镜像源_Ubuntu 18.04 搭建私有软件镜像源(支持 Ubuntu 和 CentOS)
系统环境为 Ubuntu 18.04,搭建支持 Ubuntu 系和 CentOS 系的双私有软件仓库。
Ubuntu 本地软件镜像源使用 apt-mirror 工具与远程仓库同步,CentOS 本地镜像源使用 reposync 工具与远程仓库同步。
上述两个工具都可以通过 Ubuntu 的包管理器 apt-get 命令直接安装使用。
一、环境准备
我这里搭建了 Ubuntu 18.04、Ubuntu 16.04 和 CentOS7 三个镜像源,从远程仓库拉取的软件包总共耗费了约 300G 硬盘空间,其中两个 Ubuntu 占用了约 261G,CentOS7(包含 epel 源)约 29G 。
创建镜像源前需保证本地有足够的存储空间。
建议给磁盘分区时使用 LVM(逻辑卷管理) 的方式,便于之后对存储空间进行扩容等操作。
关于 Linux 系统磁盘分区和 LVM 的介绍可以参考 Linux 磁盘设备和 LVM 管理命令详解。此处不作赘述。
安装同步工具:
$ sudo apt-get install apt-mirror reposync createrepo
安装 web 服务器(nginx):
$ sudo apt-get install nginx
二、Ubuntu 镜像源搭建
编辑 /etc/apt/mirror.list 配置文件,修改远程仓库的地址为国内的阿里镜像站,本地的 Ubuntu 软件仓库将定期从阿里源同步软件包。
set nthreads 20
set _tilde 0
set base_path /opt/mirrors/ubuntu
set defaultarch amd64
#Ubuntu 16.04
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
#Ubuntu 18.04
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
上述配置文件中 base_path 指定的目录,即本地仓库存放软件包的路径。
$ sudo mkdir -p /opt/mirrors/ubuntu
运行 apt-mirror 命令拉取软件包,同步完成花费的时间视网速而定:
$ sudo apt-mirror
配置 web 服务
镜像源同步完成之后,需配置 web 服务使得本地仓库可以被其他 Linux 机器使用。
编辑 /etc/nginx/sites-available/default 配置文件,开启目录浏览(auto_index)功能:
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;
}
}
创建软链接,将软件包存储路径指向到 web 目录下:
$ sudo ln -s /opt/mirrors/ubuntu/mirror/mirrors.aliyun.com/ubuntu /var/www/html/ubuntu
重新载入 nginx 服务:$ sudo service nginx reload
此时访问 http://127.0.0.1/ubuntu ,应该可以在 web 界面中浏览本地仓库中的软件包。
ubuntu
使用本地镜像源
前面的配置完成后,即可进入任意一台 Ubuntu 主机,配置其镜像源为刚刚创建的本地软件仓库。
编辑 /etc/apt/sources.list 文件,修改镜像源(Ubuntu 18.04):
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
运行 sudo apt-get update 命令更新索引文件,之后即可使用 sudo apt-get install 命令从本地仓库中安装软件包了。
效果如下:
$ sudo apt-get update
Hit:1 http://127.0.0.1/ubuntu bionic InRelease
Hit:2 http://127.0.0.1/ubuntu bionic-updates InRelease
Hit:3 http://127.0.0.1/ubuntu bionic-backports InRelease
Hit:4 http://127.0.0.1/ubuntu bionic-security InRelease
Hit:5 http://127.0.0.1/ubuntu bionic-proposed InRelease
Reading package lists... Done
$ sudo apt-get install nmap
...
Get:1 http://127.0.0.1/ubuntu bionic/main amd64 libblas3 amd64 3.7.1-4ubuntu1 [140 kB]
Get:2 http://127.0.0.1/ubuntu bionic/main amd64 liblinear3 amd64 2.1.0+dfsg-2 [39.3 kB]
Get:3 http://127.0.0.1/ubuntu bionic-updates/main amd64 liblua5.3-0 amd64 5.3.3-1ubuntu0.18.04.1 [115 kB]
Get:4 http://127.0.0.1/ubuntu bionic/main amd64 nmap amd64 7.60-1ubuntu5 [5174 kB]
Fetched 5467 kB in 1s (9200 kB/s)
...
三、CentOS 镜像源搭建
创建 /opt/mirrors/CentOS-7.repo 配置文件,添加远程软件仓库的地址。这里使用清华大学开源软件镜像站。
[base]
name=CentOS-7 - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-7 - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/updates/x86_64/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/extras/x86_64/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/7/centosplus/x86_64/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=0
enabled=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[epel]
name=Extra Packages for Enterprise Linux 7
baseurl=https://mirrors.tuna.tsinghua.edu.cn/epel/7/x86_64
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0
# gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
此处为了简单起见,gpgcheck 都设置为 0 关闭了 GPG KEY 检查。
创建软件仓库本地路径:$ sudo mkdir -p /opt/mirrors/centos
拉取远程仓库到本地:$ sudo reposync -np /opt/mirrors/centos -c /opt/mirrors/CentOS-7.repo
同步完成后,/opt/mirrors/centos 路径下会生成如下 4 个文件夹:
$ ls /opt/mirrors/centos
base epel extras updates
切换到 root 用户,使用 createrepo 命令在上述 4 个文件夹中分别创建私有仓库的索引文件:
$ cd /opt/mirrors/centos
$ for i in base extras updates epel; do
createrepo $i
done
索引创建完成后,上述四个路径中都会多出 repodata 和 .repodata 两个文件夹:
$ ls -a base
. .. Packages repodata .repodata
配置 web 服务
创建软链接,将 CentOS 软件包存储路径指向到 web 目录下:
$ sudo ln -s /opt/mirrors/centos /var/www/html/centos
重新载入 nginx 服务:$ sudo service nginx reload
此时访问 http://127.0.0.1/centos ,应该可以在 web 界面中浏览本地 CentOS 仓库中的软件包。
centos
使用本地镜像源
登录任意一台 CentOS 主机,备份 /etc/yum.repos.d 目录下的所有 .repo 配置文件到其他位置。
创建软件仓库配置文件 /etc/yum.repos.d/CentOS-7.repo,编辑远程仓库地址(baseurl)为前面搭建的私有仓库:
[base]
name=CentOS-7 - Base
baseurl=http://127.0.0.1/centos/base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#released updates
[updates]
name=CentOS-7 - Updates
baseurl=http://127.0.0.1/centos/updates
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that may be useful
[extras]
name=CentOS-7 - Extras
baseurl=http://127.0.0.1/centos/extras
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-7 - Plus
baseurl=http://127.0.0.1/centos/centosplus
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=0
enabled=0
#gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[epel]
name=Extra Packages for Enterprise Linux 7
baseurl=http://127.0.0.1/centos/epel
#mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled=1
gpgcheck=0
# gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
运行 sudo yum clean all && yum makecache 命令重建软件包索引。
之后即可通过 sudo yum install 命令从本地的私有仓库中安装软件了。
四、crontab
创建 crontab 计划任务,让本地仓库定期从远程仓库拉取有更新的软件包:
$ sudo crontab -e
参考配置:
0 3 * * 0 reposync -np /opt/mirrors/centos -c /opt/mirrors/CentOS-7.repo
0 22 * * 6 apt-mirror
每周日凌晨 3 点运行 reposync 命令同步 CentOS 仓库。
每周六晚上 10 点运行 apt-mirror 命令同步 Ubuntu 仓库。
参考文章
ubuntu18本地镜像源_Ubuntu 18.04 搭建私有软件镜像源(支持 Ubuntu 和 CentOS)相关推荐
- ubuntu 20.04 阿里源_Ubuntu 18.04 安装CUDA 更新内核源出错解决方案
若有同学安装Ubuntu 18.04 系统后,在安装cuda过程更新内核报错时可以尝试修改源地址来解决. 修改阿里源为Ubuntu 18.04默认的源 备份/etc/apt/sources.list ...
- 20 ubuntu 中科大源_Ubuntu 18.04换国内源 中科大源 阿里源 163源 清华源
有很多Ubuntu的镜像源,包括阿里的.网易的,还有很多教育网的源,比如:清华源.中科大源. 我们这里以中科大的源为例讲解如何修改Ubuntu 18.04里面默认的源. 编辑/etc/apt/sour ...
- centos redis make 报错_ubuntu 18.04 搭建 redis 实验环境
本文只介绍在 Ubuntu 上搭建 redis 环境. 1. 安装构建工具 && sudo apt install make gcc python-dev 2. 下载 redis 源码 ...
- Ubuntu 18.04 配置 国内 apt-get 换源
文章目录 Ubuntu 18.04 配置 国内 apt-get 换源 1 备份文件 2 用vim进入并编辑文件 3 进入网站 https://mirrors.tuna.tsinghua.edu.cn/ ...
- ubuntu 18.04更换为国内更新源
ubuntu 18.04更换为国内更新源 在执行ubuntu安装开发环境命令sudo apt update, sudo apt install build-essential时,发现安装速度过慢,可以 ...
- ubuntu 18.04 搭建python selenium 环境
ubuntu 18.04 搭建python selenium 环境 1 背景 2 环境 3 搭建 3.1 安装selenium 3.2 安装geckodriver 3.2.1 下载 3.2.2 解压 ...
- Ubuntu 18.04安装FreeSurfer软件
Ubuntu 18.04安装FreeSurfer软件 本文是在VM虚拟机里添加Ubuntu18.04并安装Freesurfer软件.以下是所有安装流程. 下载Freesurfer,该软件提供两种下载方 ...
- ubuntu 18.04安装社交软件(微信/钉钉)
ubuntu 18.04安装社交软件 背景 环境 安装 安装wine 安装微信 安装dingtalk 使用 卸载 背景 本篇是<电脑操作系统环境的转变[win]–>[linux]>和 ...
- ubuntu18安装python3.6.8_ubuntu 18.04 + Python 3.6.8 更换软件安装源
国外的开源项目开展的是如火如荼,我们国内的当然也不甘落后.为了更好的玩转 Python,我使用了 ubuntu Linux 来作为开发环境.但是由于国内网络的限制,访问国外的一些软件源的时候,速度比较 ...
最新文章
- JavaScript判断对象是否为空对象或空数组
- android api 中文 (73)—— AdapterView
- 新版pycharm,亮瞎我的狗眼
- C语言中前面有四个空格,在C语言编程中什么叫前导空格,什么叫尾随空 – 手机爱问...
- 从Vue.js源码中我学到的几个实用函数
- redis.conf配置文件详解
- jquery 判断控件css样式,jQuery获取并设置CSS类
- HTTP 协议中 Vary 的一些研究
- Python学习笔记:序列之字符串
- java绘画imo,搞死帮忙看下这个:需要为class interface或enum imort java.ut
- full gc 次数_32. GC 是怎样工作的?
- 我是真的傻,她被超市安保罚了100元,我居然给她50元
- 在线数据分析4大常用功能
- php中exec的用法,php exec用法详解
- php 开源 采集,poscms火车采集教程
- IOS手机长按图片无法弹出识别二维码
- SAP_FI_FI包含哪些部分
- PHP与FLASH之间的交互
- MyZip Pro for Mac(专业解压缩工具)
- 足球赛积分管理系统c语言,足球赛计时计分器课程设计报告.doc
热门文章
- 什么是应用宝统一链接服务器,applink
- 车牌归属地 API数据接口
- Contest3121 - 2021级新生个人训练赛第26场_问题 F: 乐乐的数字
- 面试阿里P6,过关斩将直通2面,结果3面找了个架构师来吊打我
- springboot毕设项目东莞汉庭酒店的酒店管理系统的设计与实现4ccnv(java+VUE+Mybatis+Maven+Mysql)
- 任何人都有值得学习的地方,横瓜向[水牛党](4618415)请教问题
- cpu和内存占用过高,但是任务管理器中的进程占用的内存和cpu看不出来
- tao.opengl + C#
- python中的in和out是什么意思
- 打新股和打新债有什么区别?