龙空技术网

网友来稿:内网环境或网速差怎么破?一文带你搭建本地Yum源

不背锅运维 176

前言:

当前姐妹们对“centos7配置网络yum源http”大致比较看重,姐妹们都想要分析一些“centos7配置网络yum源http”的相关文章。那么小编也在网摘上搜集了一些有关“centos7配置网络yum源http””的相关资讯,希望朋友们能喜欢,小伙伴们快快来了解一下吧!

写在开篇yum是什么

是一个在 Fedora 和 RedHat 以及 CentOS 中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。

一、搭建本地yum源服务

查看linux内核 cat /etc/redhat-release 根据版本,可以去centos官网找到iso镜像文件下载;

注意:最好和线上安装的linux内核版本一致;centos和redhat。笔者这里的环境是:CentOS Linux release 7.5.1804 (Core)二、创建文件夹并备份linuxYUM源

以下是本地的原有yum源

[root@localhost ~]# cd /etc/yum.repos.d/[root@localhost yum.repos.d]# lsCentOS-Base.repo  CentOS-Debuginfo.repo  CentOS-Media.repo    CentOS-Vault.repo  epel-testing.repoCentOS-CR.repo    CentOS-fasttrack.repo  CentOS-Sources.repo  epel.repo[root@localhost yum.repos.d]# 

创建目录,我们需要把原有本地的yum源给移走

[root@localhost ~]#mkdir -p /etc/yum.repos.d/linux[root@localhost ~]#cd /etc/yum.repos.d[root@localhost ~]#mv *.repo linux
三、wget 阿里云的yum源
[root@localhost ~]# cd /etc/yum.repos.d[root@localhost yum.repos.d]# wget -O /etc/yum.repos.d/CentOS-Base.repo 

yum会将下载下来的包文件rpm和头文件header存盘在本地机器的硬盘缓存中, 这个将占用硬盘空间, 可以将这些内容清除掉, 以释放磁盘空间:

[root@localhost ~]#yum clean all #清除所有缓存[root@localhost ~]#yum  makecache #yum安装的时候会将安装包进行缓存,不过最好还是再执行一下yum makecache命
四、安装软件 yum-utils 工具包Yum-utils: 管理repository及扩展包的工具 (主要是针对repository)epel-release: EPEL是由 Fedora 社区打造,为 RHEL及衍生发行版如 RedHat 以及 CentOS中的Shell前端软件包管理器
[root@localhost ~]#yum -y install yum-utils[root@localhost ~]#yum -y install epel-release
五、下载相关的rpm包

Yumdownloader 命令行工具,它可以一次性下载任何 RPM 软件包及其所有依赖包。yum install yum-utils。一旦安装完成,运行如下命令去下载一个软件包,yumdownloader为了根据所有依赖性下载软件包,我们使用 --resolve参数:yumdownloader --resolve默认情况下,Yumdownloader 将会下载软件包到当前工作目录下。 为了将软件下载到一个特定的目录下,我们使用 --destdir 参数:yumdownloader --resolve --destdir=/tmp/all

[root@localhost ~]# yumdownloader --resolve --destdir=/tmp/all gcc sqlite-devel libpng  libpng-devel libjpeg libjpeg-devel freetype freetype-devel oniguruma oniguruma-devel libxml2-devel curl-devel mysql-devel libssh2-devel libxml2-devel libevent-devel OpenIPMI-devel libssh2-devel net-snmp-devel unixODBC-devel  libxml2 libxml2-devel gccpcre-devel openssl openssl-devel pcre pcre-devel zlib zlib-devel curses ncurses-devel bison  gcc-c++ make pcre pcre-devel curl-devel libaio autoconf automake  pcre* libaio xz-devel telnet net-tools
六、 安装creatrepo软件 并制作本地源

安装必要工具包:包拷贝完成之后需要构建yum使用的数据库,以xml文件形式存在,该数据库会对所有包进行分类建立索引,方便yum程序快速搜索安装包和检查包之间的依赖关系。但创建数据库要用到一个工具包createrepo-0.x.x-xx.el6.noarch.rpm,默认是没有的,先要对它进行安装。

说明:createrepo 是一个对rpm 文件进行索引建立的工具。大体功能就是对指定目录下的rpm文件进行检索,把每个rpm文件的信息存储到指定的索引文件中,这样方便远程yum命令在安装更新时进行检索

[root@localhost ~]#yum -y install createrepo[root@localhost ~]#createrepo /tmp/all
七、压缩打包本地rpm文件
[root@localhost ~]# tar -cvf all.tar /tmp/all[root@localhost ~]# lsall.tar              

压缩打包后,下载上传到需要操作使用的主机上,解压放到指定的位置

八、修改线上repo注意:编辑yum仓库指向文件(文件名必须以 .repo后缀)

[root@localhost ~]# vi /etc/yum.repos.d/local.repo[local]name=localbaseurl=  #这里填写你解压原来打包的文件的路径gpgcheck=0
写在最后

本地yum源仓库的搭建是经常需要用到的,可以在离线的情况下帮助我们安装所需要的软件搭建需要的环境。

本篇转载于:

标签: #centos7配置网络yum源http