HCRM博客

如何在CentOS中配置与管理软件仓库

CentOS Repo是用于管理软件包和更新的关键组件,本文将详细解释CentOS的官方源、国内源以及第三方源的概念和使用,并提供相关操作示例。

CentOS Repo

CentOS Repo是存储和管理软件包的位置,类似于Windows系统中的软件管家或应用商店,在CentOS操作系统中,包管理器(如YUM)通过这些repo来安装、更新和删除软件包,默认情况下,CentOS系统自带官方源,但用户可以根据需求更换为国内源或第三方源以提高下载速度和稳定性。

如何在CentOS中配置与管理软件仓库-图1
(图片来源网络,侵权删除)

一、官方源

1. 官方源介绍

定义:官方源由红帽公司提供,包含CentOS系统的所有官方软件包。

路径:官方源的配置文件通常位于/etc/yum.repos.d/目录下,文件以.repo例如CentOSBase.repo

2. 官方源配置示例

  • [base]
  • name=CentOS$releasever Base
  • mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
  • #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
  • gpgcheck=1
  • gpgkey=file:///etc/pki/rpmgpg/RPMGPGKEYCentOS7
  • [updates]
  • name=CentOS$releasever Updates
  • mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
  • #baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
  • gpgcheck=1
  • gpgkey=file:///etc/pki/rpmgpg/RPMGPGKEYCentOS7
  • [extras]
  • name=CentOS$releasever Extras
  • mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
  • #baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
  • gpgcheck=1
  • gpgkey=file:///etc/pki/rpmgpg/RPMGPGKEYCentOS7
  • [centosplus]
  • name=CentOS$releasever Plus
  • mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
  • #baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
  • gpgcheck=1
  • enabled=0
  • gpgkey=file:///etc/pki/rpmgpg/RPMGPGKEYCentOS7

3. 使用官方源的步骤

1、备份现有repo文件

如何在CentOS中配置与管理软件仓库-图2
(图片来源网络,侵权删除)
  • mv /etc/yum.repos.d/CentOSBase.repo /etc/yum.repos.d/CentOSBase.repo.backup

2、下载并替换为官方源

  • curl o /etc/yum.repos.d/CentOSBase.repo http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra

3、清理缓存并生成新的缓存

  • yum clean all
  • yum makecache

二、国内源

1. 国内源介绍

定义:国内源是由国内公司或机构提供的镜像源,用于提高软件包下载速度和稳定性。

常用国内源:阿里云、清华大学、腾讯云、华为云等。

2. 国内源配置示例(以阿里云为例)

如何在CentOS中配置与管理软件仓库-图3
(图片来源网络,侵权删除)
  • [base]
  • name=CentOS$releasever Base mirrors.aliyun.com
  • failovermethod=priority
  • baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
  • http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
  • http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
  • gpgcheck=1
  • gpgkey=http://mirrors.aliyun.com/centos/RPMGPGKEYCentOS7
  • [updates]
  • name=CentOS$releasever Updates mirrors.aliyun.com
  • failovermethod=priority
  • baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
  • http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
  • http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
  • gpgcheck=1
  • gpgkey=http://mirrors.aliyun.com/centos/RPMGPGKEYCentOS7
  • [extras]
  • name=CentOS$releasever Extras mirrors.aliyun.com
  • failovermethod=priority
  • baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
  • http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
  • http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
  • gpgcheck=1
  • gpgkey=http://mirrors.aliyun.com/centos/RPMGPGKEYCentOS7
  • [centosplus]
  • name=CentOS$releasever Plus mirrors.aliyun.com
  • failovermethod=priority
  • baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
  • http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
  • http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
  • gpgcheck=1
  • enabled=0
  • gpgkey=http://mirrors.aliyun.com/centos/RPMGPGKEYCentOS7

3. 使用国内源的步骤(以阿里云为例)

1、备份现有的repo文件

  • mv /etc/yum.repos.d/CentOSBase.repo /etc/yum.repos.d/CentOSBase.repo.backup

2、下载并替换为阿里云源

  • curl o /etc/yum.repos.d/CentOSBase.repo http://mirrors.aliyun.com/repo/Centos7.repo

3、清理缓存并生成新的缓存

  • yum clean all
  • yum makecache

三、第三方源和EPEL源

1. 第三方源介绍

定义:第三方源是由非官方的组织或个人维护的源,通常包含一些官方源没有的软件包。

常用第三方源:EPEL(Extra Packages for Enterprise Linux)。

2. EPEL源配置示例

  • [epel]
  • name=Extra Packages for Enterprise Linux $releasever $basearch
  • baseurl=https://download.fedoraproject.org/pub/epel/$releasever/$basearch/
  • gpgcheck=1
  • gpgkey=file:///etc/pki/rpmgpg/RPMGPGKEYEPEL7

3. 使用EPEL源的步骤

1、安装EPEL源

  • yum install epelrelease

2、启用EPEL源

  • yum enablerepo=epel repolist all

3、清理缓存并生成新的缓存

  • yum clean all
  • yum makecache

1. 归纳

CentOS Repo是管理软件包和更新的核心组件,可以通过配置官方源、国内源和第三方源来优化下载速度和稳定性,本文详细介绍了每种源的配置方法和使用步骤,帮助用户更好地管理和使用CentOS系统。

2. FAQs

提问1:CentOSBase.repo这个源文件可以改名吗?可以改后缀吗?

答:名字可以随便改,不影响下载源里面的信息;而后缀必须以.repo才可以,系统只会读取.repo的文件认作源,其他的一概不认。

提问2:为什么之前备份的CentOSBase.repo.backup系统不会读取?CentOSBase.repo可以读取?

答:因为文件后缀不同,系统只会把.repo文件认作源,其他的一概不认。

本站部分图片及内容来源网络,版权归原作者所有,转载目的为传递知识,不代表本站立场。若侵权或违规联系Email:zjx77377423@163.com 核实后第一时间删除。 转载请注明出处:https://blog.huochengrm.cn/pc/20085.html

分享:
扫描分享到社交APP
上一篇
下一篇