Linux【8】-软件管理-2-3-安装(yum)

一、用yum管理软件包

YUM 是 Yellow dog Updater, Modified 的缩写,是由 Duke University 所发起的计划,目的就是为了解决 RPM 的依赖关系的问题,方便使用者进行软件的安装、升级等等工作。

yum 只是 为了解决 RPM 的依赖关系的问题,而不是一种其它的软件封装模式。RPM 仍然是 RHEL 和 CenOS 中的默认软件管理器。yum 可以视为 RPM 的一个前台工具。

其实 YUM 的工作原理并不复杂,每一个 RPM 软件包的头(header)里面 都会纪录该软件的依赖关系,那么如果可以将该头的内容纪录下来并且进行分析, 可以知道每个软件在安装之前需要额外安装哪些基础软件。也就是说,在服务器 上面先以分析工具将所有的 RPM 软件包进行分析,然后将该分析结果记录下来, 只要在进行安装或升级时先查询该记录文件,就可以知道所有依赖的软件。所以 YUM 的基本工作流程如下:

  • 服务器端:在服务器上面存放了所有的 RPM 软件包,然后以相关的功能去 分析每个 RPM 文件的依赖性关系,将这些数据记录成文件存放在服务器的某特 定目录内。

  • 客户端:如果需要安装某个软件时,先下载服务器上面记录的依赖性关系文 件(可通过 WWW 或 FTP 方式),通过对服务器端下载的纪录数据进行分析,然 后取得所有相关的软件,一次全部下载下来进行安装。

二、yum 的安装

如果没有安装 yum,就必须去下载,我们可以选择一个最快的 CentOS 官方 源(对于国内用户来说,一般是网易源,我们这里使用的就是是网易源),用下 载工具进行下载,我们需要下载这些包:

[root@localhost ~]# rpm –qa yum*
yum-plugin-security-1.1.30-14.el6.noarch # yum 安全插件包
yum-plugin-fastestmirror-1.1.30-14.el6.noarch# yum 最快镜像自选动择插件包
yum-metadata-parser-1.1.2-16.el6.x86_64 # yum 的元数据解析器
yum-utils-1.1.30-14.el6.noarch # yum 操作软件仓库和管理扩展包的工具集合
yum-3.2.29-30.el6.centos.noarch # yum 软件包
[root@localhost ~]#

用 wget 命令下载:

[root@localhost ~]# wget
http://mirrors.163.com/centos/6.3/os/x86_64/Packages/yum-3.2.29-
30.el6.centos.noarch.rpm
[root@localhost ~]# wget http://mirrors.163.com/centos/6.3/os/x86_64/Packages/yummetadata-parser-1.1.2-16.el6.x86_64.rpm

[root@localhost ~]# wget http://mirrors.163.com/centos/6.3/os/x86_64/Packages/yumutils-1.1.30-14.el6.noarch.rpm
[root@localhost ~]# wget http://mirrors.163.com/centos/6.3/os/x86_64/Packages/yumplugin-fastestmirror-1.1.30-14.el6.noarch.rpm

在下载完成后,用 rpm 进行安装:

[root@localhost ~]# rpm -ivh python-iniparse-0.3.1-2.1.el6.noarch.rpm
[root@localhost ~]# rpm -ivh yum-metadata-parser-1.1.2-16.el6.x86_64.rpm
[root@localhost ~]# rpm -ivh yum-3.2.29-30.el6.centos.noarch.rpm yum-pluginfastestmirror-1.1.30-14.el6.noarch.rpm
# 这两个软件包必须同时安装,否则会发生互依赖性问题
[root@localhost ~]# rpm -ivh yum-utils-1.1.30-14.el6.noarch.rpm

测试 yum

# yum clean all # 清除 yum 所有软件包缓存信息
# yum makecache #将服务器上的软件包信息缓存到本地,以提高搜索安装软件的速度
# yum install finger #安装一个名为“finger”命令,测试 yum 是否可用

当第一次使用 yum 或 yum 源有更新时,yum 会自动下载所有所需的 headers 放置于/var/cache/yum 目录下,所需时间可能较长。

三、yum常用功能

命令 含义
yum clean all 清除缓存中旧的 rpm 头文件和包文件
yum makecache 建立新的缓存
yum list 列出所有升级源上的包
yum list available 列出资源库中所有可以安装或更新的 rpm 包
yum list updates 列出所有升级源上的可以更新包
yum list installed 列出已经安装的包
yum search <关键字> 搜索匹配特定字符的 rpm 包
yum info <软件包名> 列出资源库中特定的可以安装或更新以及已经安装的 rpm 包的信息
yum install <软件包名> 安装 rpm 包
yum update <软件包名> 更新 rpm 包
yum remove <软件包名> 卸载 rpm 包

3.1 查询功能:yum [list|info|search|provides|whatprovides] 参数

如果想要查询利用yum 来查询原版distribution 所提供的软体,或已知某软体的名称,想知道该软体的功能, 可以利用yum 相关的参数为:

[root@study ~]# yum [option] [查询工作项目] [相关参数] 
选项与参数:
[option]:主要的选项,包括有:
  -y :当yum 要等待使用者输入时,这个选项可以自动提供yes 的回应;
  --installroot=/some/path :将该软体安装在/some/path 而不使用预设路径

[查询工作项目] [相关参数]:这方面的参数有:
  search :搜寻某个软体名称或者是描述(description) 的重要关键字;
  list :列出目前yum 所管理的所有的软体名称与版本,有点类似rpm -qa;
  info :同上,不过有点类似rpm -qai 的执行结果;
  provides:从档案去搜寻软体!类似rpm -qf 的功能!

范例一:搜寻磁碟阵列(raid)相关的软体有哪些?
[root@study ~]# yum search raid 
Loaded plugins: fastestmirror, langpacks       # yum系统自己找出最近的yum server 
Loading mirror speeds from cached hostfile     #找出速度最快的那一部yum server 
 * base: ftp.twaren .net                        #底下三个软体库,且来源为该伺服器!
 * extras: ftp.twaren.net
 * updates: ftp.twaren.net
....(前面省略)....
dmraid-events-logwatch.x86_64 : dmraid logwatch-based email reporting
dmraid-events.x86_64 : dmevent_tool (Device-mapper event tool) and DSO
iprutils.x86_64 : Utilities for the IBM Power Linux RAID adapters
mdadm.x86_64 : The mdadm program controls Linux md devices (software RAID arrays)
....(后面省略)....
# 在冒号(:) 左边的是软体名称,右边的​​则是在RPM 内的name 设定(软体名)
# 瞧!上面的结果,这不就是与RAID 有关的软体吗?如果想了解mdadm 的软体内容呢?

范例二:找出mdadm这个软体的功能为何 
[root@study ~]# yum info mdadm 
Installed Packages        <==这说明该软体是已经安装的了 
Name : mdadm       <==这个软体的名称 
Arch : x86_64      <= =这个软体的编译架构 
Version : 3.3.2       <==此软体的版本 
Release : 2.el7       <==释出的版本 
Size : 920 k       <==此软体的档案总容量 
Repo : installed   <==软体库回报说已安装的
From repo : anaconda
Summary : The mdadm program controls Linux md devices (software RAID arrays)
URL : http://www.kernel.org/pub/linux/utils/raid/mdadm/
License : GPLv2+
Description : The mdadm program is used to create, manage, and monitor Linux MD (software
            : RAID) devices. As such, it provides similar functionality to the raidtools
            : package. However, mdadm is a single program, and it can perform
            : almost all functions without a configuration file, though a configuration
            : file can be used to help with some common tasks.
# 不要跟我说,上面说些啥?自己找字典翻一翻吧!拜托拜托!

范例三:列出yum伺服器上面提供的所有软体名称 
[root@study ~]# yum list 
Installed Packages    <==已安装软体
GConf2.x86_64 3.2.6-8.el7 @anaconda
LibRaw.x86_64 0.14.8-5.el7.20120830git98d925 @base
ModemManager.x86_64 1.1.0-6.git20130913.el7 @anaconda
....(中间省略).... 
Available Packages    <==还可以安装的其他软体
389-ds-base.x86_64 1.3.3.1-20.el7_1 updates
389-ds-base-devel.x86_64 1.3.3.1-20.el7_1 updates
389-ds-base-libs.x86_64 1.3.3.1-20.el7_1 updates
....(底下省略)....
# 上面提供的意义为:『 软体名称版本在那个软体库内』

范例四:列出目前伺服器上可供本机进行升级的软体有哪些?
[root@study ~]# yum list updates   <==一定要是update s喔!
Updated Packages
NetworkManager.x86_64 1:1.0.0-16.git20150121.b4ea599c.el7_1 updates
NetworkManager-adsl.x86_64 1:1.0.0-16.git20150121.b4ea599c.el7_1 updates
....(底下省略)....
# 上面就列出在那个软体库内可以提供升级的软体与版本!

范例五:列出提供passwd这个档案的软体有哪些 
[root@study ~]# yum provides passwd
passwd-0.79-4.el7.x86_64 : An utility for setting or changing passwords using PAM
Repo : base

passwd-0.79-4.el7.x86_64 : An utility for setting or changing passwords using PAM
Repo : @anaconda
# 找到啦!就是上面的这个软体提供了passwd 这个程式!
例题:

利用yum 的功能,找出以pam 为开头的软体名称有哪些?而其中尚未安装的又有哪些?

答:

可以透过如下的方法来查询:

[root@study ~]# yum list pam*
Installed Packages
pam.x86_64 1.1.8-12.el7 @anaconda
pam_krb5.x86_64 2.4.8-4.el7 @base
Available Packages <==底下则是『可升级』的或『未安装』的
pam.i686 1.1.8-12.el7_1.1 updates
pam.x86_64 1.1.8-12.el7_1.1 updates
pam-devel.i686 1.1.8-12.el7_1.1 updates
pam-devel.x86_64 1.1.8-12.el7_1.1 updates
pam_krb5.i686 2.4.8-4.el7 base
pam_pkcs11.i686 0.6.2-18.el7 base
pam_pkcs11.x86_64 0.6.2-18.el7 base

如上所示,所以可升级者有pam 这两个软体,完全没有安装的则是pam-devel 等其他几个软体啰!

3.2 安装/升级功能:yum [install|update] 软体

既然可以查询,那么安装与升级呢?很简单啦!就利用install 与update 这两项工作来处理即可喔!

[root@study ~]# yum [option] [安装与升级的工作项目] [相关参数] 
选项与参数:
  install :后面接要安装的软体!
  update :后面接要升级的软体,若要整个系统都升级,就直接update 即可

范例一:将前一个练习找到的未安装的pam-devel安装起来 
[root@study ~]# yum install pam-devel 
Loaded plugins: fastestmirror, langpacks     #首先的5行在找出最快的yum server
Loading mirror speeds from cached hostfile
 * base: ftp.twaren.net
 * extras: ftp.twaren.net
 * updates: ftp.twaren.net
Resolving Dependencies                       #接下来先处理『属性相依』的软体问题
--> Running transaction check
---> Package pam-devel.x86_64 0:1.1.8-12.el7_1.1 will be installed
--> Processing Dependency: pam(x86-64) = 1.1.8-12.el7_1.1 for package: pam-devel-
       1.1.8-12.el7_1.1.x86_64
--> Running transaction check
---> Package pam.x86_64 0:1.1.8-12.el7 will be updated 
---> Package pam.x86_64 0:1.1.8-12.el7_1.1 will be an update
--> Finished Dependency Resolution
Dependencies Resolved

# 由上面的检查发现到pam 这个软体也需要同步升级,这样才能够安装新版pam-devel 喔!
# 至于底下则是一个总结的表格显示!
================================================== ========================================
 Package Arch Version Repository Size
================================================== ========================================
Installing:
 pam-devel x86_64 1.1.8-12.el7_1.1 updates 183 k
Updating for dependencies:
 pam x86_64 1.1.8-12.el7_1.1 updates 714 k

Transaction Summary
================================================== ========================================
Install 1 Package                           #要安装的是一个软体 
Upgrade ( 1 Dependent package)   #因为相依属性问题,需要额外加装一个软体!

Total size: 897 k
Total download size: 183 k                   #总共需要下载的容量!
Is this ok [y/d/N]: y    #你得要自己决定是否要下载与安装!当然是y啊!
Downloading packages:                        #开始下载啰!
warning: /var/cache/yum/x86_64/7/updates/packages/pam-devel-1.1.8-12.el7_1.1.x86_64.rpm:
         Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for pam-devel-1.1.8-12.el7_1.1.x86_64.rpm is not installed
pam-devel-1.1.8-12.el7_1.1.x86_64.rpm | 183 kB 00:00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package : centos-release-7-1.1503.el7.centos.2.8.x86_64 (@anaconda)
 From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: y   #只有在第一次安装才会出现这个项目『确定要安装数位签章』才能继续!
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.
  Updating : pam-1.1.8-12.el7_1.1.x86_64 1/3
  Installing : pam-devel-1.1.8-12.el7_1.1.x86_64 2/3
  Cleanup : pam-1.1.8-12.el7.x86_64 3/3
  Verifying : pam-1.1.8-12.el7_1.1.x86_64 1/3
  Verifying : pam-devel-1.1.8-12.el7_1.1.x86_64 2/3
  Verifying : pam-1.1.8-12.el7.x86_64 3/3

Installed:
  pam-devel.x86_64 0:1.1.8-12.el7_1.1

Dependency Updated:
  pam.x86_64 0:1.1.8-12.el7_1.1

Complete!

有没有很高兴啊!你不必知道软体在哪里,你不必手动下载软体,你也不必拿出原版光碟出来mount 之后查询再安装!全部不需要,只要有了yum 这个家伙,你的安装、升级再也不是什么难事!而且还能主动的进行软体的属性相依处理流程,如上所示,一口气帮我们处理好了所有事情!是不是很过瘾啊!而且整个动作完全免费!够酷吧!

3.3 移除功能:yum [remove] 软体

那能不能用yum 移除软体呢?将刚刚的软体移除看看,会出现啥状况啊?

[root@study ~]# yum remove pam-devel
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies    <==同样的,先解决属性相依的问题
--> Running transaction check
---> Package pam-devel.x86_64 0:1.1.8-12.el7_1.1 will be erased
--> Finished Dependency Resolution

Dependencies Resolved

================================================== ========================================
 Package Arch Version Repository Size
================================================== ========================================
Removing:
 pam-devel x86_64 1.1.8-12.el7_1.1 @updates 528 k

Transaction Summary
================================================== ========================================
Remove 1 Package        #还好!没有相依属性的问题,仅移除一个软体!

Installed size: 528 k
Is this ok [y/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Erasing : pam-devel-1.1.8-12.el7_1.1.x86_64 1/1
  Verifying : pam-devel-1.1.8-12.el7_1.1.x86_64 1/1

Removed:
  pam-devel.x86_64 0:1.1.8-12.el7_1.1

Complete!

连移除也这么简单!看来,似乎不需要rpm 这个指令也能够快乐的安装所有的软体了!虽然是如此,但是yum 毕竟是架构在rpm 上面所发展起来的,所以,鸟哥认为你还是得需要了解rpm 才行!不要学了yum 之后就将rpm 的功能忘记了呢!切记切记!

四、yum 软件源

RPM 软件源(Repositories)是一个目录,或是一个网站,包含了许多 RPM 软件包及其索引文件。类似 yum 之类的软件包管理工具可以在仓库中自动地定 位并获取正确的 RPM 软件包。这样,用户就不必手动搜索和安装新应用程序和 升级补丁了。只用一个命令,您就可以更新系统中所有软件,也可以根据指定搜 索目标来查找安装新软件。

有许多公司和社区提供 CentOS rpm 官方源,国内比较常用的有:

网易源:http://mirrors.163.com
搜狐源:http://mirrors.sohu.com/
中科大源:http://centos.ustc.edu.cn/
CentOS 源:http://mirror.centos.org

我们随时可以到 CentOS 或者 Fedora 的 Public Mirror List 中去查找最快 的 CentOS 或者 Fedora rpm 官方源:

CentOS:http://www.centos.org/modules/tinycontent/index.php?id=13

Fedora: http://mirrors.fedoraproject.org/publiclist/

最重要的特色就是那个『 repodata 』的目录!该目录就是分析RPM软体后所产生的软体属性相依资料放置处

一个软件源(Repositories)中可能会配置多个软件仓库(Repository)。 CentOS 默认自带 CentOS-Base.repo 源已经预先配置五个仓库(其中三个默认 启用,两个配置但未启用):

库名 内容
base 构成 CentOS 基本软件包,和光盘上内容相同,默认启用
updates Base 仓库中软件包的更新版本,默认启用
extras 一大批附加的软件包,默认启用
centosplus 针对 base 及 updates 软件库内的组件的更新。这些更新组件并不属于正式的发行,所以在扩展 CentOS 的功能同时牺牲了与先前版本兼容性。启用这个软件库会导致 CentOS 与正式版本有差别。默认情况下是不启用这个库的,用户应该明白这样做的后果才启用 centosplus。
contrib 这个软件库包含了 CentOS 用户贡献的组件,它们并不会与核心发行版本的组件重叠。这些组件并没有经过 CentOS 的开发者测试,亦未必会同步跟随 CentOS 正式版本的发行。默认情况下是不启用这个库的,用户应该明白这样做的后果才启用contrib。

官方源中去除了很多有版权争议的软件,而且安装的软件也不是最新的稳定 版。CentOS 自带的源中也找不到很多多媒体软件(如 mplayer)和开发软件(如 Eclipse),如果需要安装,必需先添加其他源,如 EPEL、RPMFusion 和 RepoForge 等第三方软件源。

有许多公司和社区为兼容 RHEL 的 Linux 发行版本提供第三方源,比较常用的有:

  • EPEL 源:https://fedoraproject.org/wiki/EPEL/zh-cn
  • RepoForge 源:http://repoforge.org/
  • RPMFusion 源:http://rpmfusion.org/
  • Remi 源:http://rpms.famillecollet.com/

具体例子:

[root@study ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
#仓库名字
name=CentOS-$releasever – Base
#这个可以理解为仓库的描述,这个可以不写这一行
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
#库的地址
enable =1
# 是否启用这个库,1 是启用,0 是不启用,如果 enable 参数缺失,默认为启用
gpgcheck=1
#是否检查软件的 KEY,1 是启用,0 是不启用。还记得RPM 的数位签章吗?这就是指定是否需要查阅RPM 档案内的数位签章
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
#KEY 文件路径。就是数位签章的公钥档所在位置!使用预设值即可

我们试着去配置一个第三方源,首先确认系统是否安装了 yum-priorities 这个 yum 的插件,这个插件是用来保证安装软件时候软件仓库先后次序,一般是默认 先从官方源安装,然后从第三方软件仓库中安装:

[root@localhost ~]# yum install yum-priorities
Loaded plugins: fastestmirror, refresh-packagekit, security
Loading mirror speeds from cached hostfile
* base: mirrors.163.com
* extras: mirrors.163.com
* updates: mirrors.163.com
base | 3.7 kB 00:00
extras | 3.5 kB 00:00
google-chrome | 951 B 00:00
updates | 3.5 kB 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package yum-plugin-priorities.noarch 0:1.1.30-14.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
===================================================================
Package Arch Version Repository Size
===================================================================
Installing:
yum-plugin-priorities noarch 1.1.30-14.el6 base 22 k

Transaction Summary
===================================================================
=============
Install 1 Package(s)
Total download size: 22 k
Installed size: 28 k
Is this ok [y/N]: y
Downloading Packages:
yum-plugin-priorities-1.1.30-14.el6.noarch.rpm | 22 kB 00:00
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
 Installing : yum-plugin-priorities-1.1.30-14.el6.noarch 1/1
 Verifying : yum-plugin-priorities-1.1.30-14.el6.noarch 1/1
Installed:
 yum-plugin-priorities.noarch 0:1.1.30-14.el6
Complete!

安装完以后查看 /etc/yum/pluginconf.d/priorities.conf 文件,确认文件中有 这三行:

[main]
enabled=1 #启用本插件
check_obsoletes=1 #防止一些已经废弃(obsoletes)的包的出现

来到 RepoForge 官方网站 http://repoforge.org/use/ ,根据所使用的 Linux 发行版本选择适合的 rpmforge 发行包,如果不知道你所使用的 CentOS 具体版 本可以通过如下命令查看:

[root@localhost ~]# cat /etc/centos-release #查看发行版本号
CentOS release 6.3 (Final)
[root@localhost ~]# uname –r #查看内核版本号和机器架构
2.6.32-279.19.1.el6.x86_64
[root@localhost ~]#

我们可以知道我们所使用的 Linux 发行版本为 CentOS 6.3(Final),内核版本 为 kernel 2.6.32-279.19.1.el6.x86_64,与 RHEL 6.3 兼容,因此我们选择 EL 6.0 x86_64 版本下载并安装。

[root@localhost ~]# wget http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-
0.5.2-2.el6.rf.x86_64.rpm、
[root@localhost ~]# rpm -ivh rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm
warning: rpmforge-release-0.5.2-2.el6.rf.x86_64.rpm: Header V3 DSA/SHA1 Signature,
key ID 6b8d79e6: NOKEY
Preparing... ########################################### [100%]
 1:rpmforge-release ########################################### [100%]
[root@localhost ~]#

[root@localhost yum.repos.d]# ls -l /etc/yum.repos.d/
总用量 36
-rw-r--r--. 1 root root 1926 12 月 26 23:13 CentOS-Base.repo
-rw-r--r--. 1 root root 637 6 月 26 2012 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 626 12 月 26 22:54 CentOS-Media.repo
-rw-r--r--. 1 root root 2593 12 月 26 22:54 CentOS-Vault.repo
-rw-r--r--. 1 root root 116 12 月 26 22:54 google-chrome.repo
-rw-r--r--. 1 root root 739 11 月 13 2010 mirrors-rpmforge
-rw-r--r--. 1 root root 717 11 月 13 2010 mirrors-rpmforge-extras
-rw-r--r--. 1 root root 728 11 月 13 2010 mirrors-rpmforge-testing
-rw-r--r--. 1 root root 1113 11 月 13 2010 rpmforge.repo

用文本编辑器打开/etc/yum.repos.d/rpmforge.repo,找到如下 rpmforge 仓库配 置部分,并在此部分最后添加“priority = 10”,表示该源的优先级较低:

### Name: RPMforge RPM Repository for RHEL 6 - dag
### URL: http://rpmforge.net/
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el6/en/$basearch/rpmforge
mirrorlist = http://apt.sw.be/redhat/el6/en/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge

enabled = 1
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1
priority = 10

优先级由 1 ~ 99 的 99 个数表示,1 的优先级最高。优先级小的源即使有 某软件的较新版本,如果优先级高的源中没有,在启用该插件的情况下,系统也 无法安装/升级到该较新版本。图形界面的 YUM 工具一般默认就已经包含了优 先级插件。

用 vim 打开 CentOS-Base.repo,找到如 base、updates 和 extra 仓库配置部分, 并在分别这些部分最后添加“priority = 1”:

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority = 1
#released updates
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updat
es
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority = 1

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras

#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
priority = 1

然后来安装mplayer 这个软件来测试RepoForge这个第三方源是否配置好了:

[root@localhost ~]#yum install mplayer mplayer-gui mplayer-doc mplayer-skins mplayertools

查看都安装了哪些源

yum repolist

或者

ls /etc/yum.repos.d/

具体例子:

范例一:列出目前yum server所使用的软体库有哪些?
[root@study ~]# yum repolist all 
repo id repo name status
C7.0.1406-base/x86_64 CentOS-7.0.1406 - Base disabled
C7.0.1406-centosplus/x86_64 CentOS-7.0.1406 - CentOSPlus disabled
C7.0.1406-extras/x86_64 CentOS-7.0.1406 - Extras disabled
C7.0.1406-fasttrack/x86_64 CentOS-7.0.1406 - CentOSPlus disabled
C7.0.1406-updates/x86_64 CentOS-7.0.1406 - Updates disabled
base CentOS-7 - Base enabled: 8,652
base-debuginfo/x86_64 CentOS-7 - Debuginfo disabled
base-source/7 CentOS-7 - Base Sources disabled
centosplus/7/x86_64 CentOS-7 - Plus disabled
centosplus-source/7 CentOS-7 - Plus Sources disabled
cr/7/x86_64 CentOS-7 - cr disabled
extras CentOS-7 - Extras enabled: 181
extras-source/7 CentOS-7 - Extras Sources disabled
fasttrack/7/x86_64 CentOS-7 - fasttrack disabled
updates CentOS-7 - Updates enabled: 1,302
updates-source/7 CentOS-7 - Updates Sources disabled
repolist: 10,135
# 上面最右边有写enabled 才是有启动的!由于/etc/yum.repos.d/
# 有多个设定档,所以你会发现还有其他的软体库存在。

修改软体库产生的问题与解决之道

由于我们是修改系统预设的设定档,事实上,我们应该要在/etc/yum.repos.d/ 底下新建一个档案, 该副档名必须是.repo 才行!但因为我们使用的是指定特定的映射站台,而不是其他软体开发商提供的软体库, 因此才修改系统预设设定档。但是可能由于使用的软体库版本有新旧之分,你得要知道, yum 会先下载软体库的清单到本机的/var/cache/yum 里面去!那我们修改了网址却没有修改软体库名称(中括号内的文字), 可能就会造成本机的清单与yum 伺服器的清单不同步,此时就会出现无法更新的问题了!

那怎么办啊?很简单,就清除掉本机上面的旧资料即可!需要手动处理吗?不需要的, 透过yum 的clean 项目来处理即可!

[root@study ~]# yum clean [packages|headers|all] 
选项与参数:
 packages:将已下载的软体档案删除
 headers :将下载的软体档头删除
 all :将所有软体库资料都删除!

范例一:删除已下载过的所有软体库的相关资料(含软体本身与清单) 
[root@study ~]# yum clean all

EPEL/ELRepo 外挂软体以及自订设定档

鸟哥因为工作的关系,在Linux 上面经常需要安装第三方协力软体,这包括NetCDF 以及MPICH 等等的软体。现在由于平行处理的函式库需求大增, 所以MPICH 已经纳入预设的CentOS 7 软体库中。但是NetCDF 这个软体就没有包含在里头了~同时,Linux 上面还有个很棒的统计软体,这个软体名称为『 R 』!预设也是不在CentOS 的软体库内~唉~那怎办?要使用前一章介绍的Tarball 去编译与安装吗?这倒不需要~因为有很多我们好棒的网友提供预先编译版本了!

在Fedora 基金会里面发展了一个外加软体计画(Extra Packages for Enterprise Linux, EPEL),这个计画主要是针对Red Hat Enterprise Linux 的版本来开发的, 刚刚好CentOS 也是针对RHEL 的版本来处理的嘛!所以也就能够支援该软体库的相关软体相依环境了。这个计画的主网站在底下网页:

https://fedoraproject.org/wiki/EPEL

而我们的CentOS 7 主要可以使用的软体仓库网址为:

https://dl.fedoraproject.org/pub/epel/7/x86_64/

除了上述的Fedora 计画所提供的额外软体库之外,其实社群里面也有朋友针对CentOS 与EPEL 的不足而提供的许多软体仓库喔!底下鸟哥是列出当初鸟哥为了要处理PCI passthrough 虚拟化而使用到的ELRepo 这个软体仓库,若有其他的需求,你就得要自己搜寻了!这个ELRepo 软体仓库与提供给CentOS 7.x 的网址如下:

这个ELRepo 的软体库跟其他软体库比较不同的地方在于这个软体库提供的资料大多是与核心、核心模组与虚拟化相关软体有关,例如NVidia 的驱动程式也在里面咧!尤其提供了最新的核心(取名为kernel-ml 的软体名称,其实就是最新的Linux 核心啊!),如果你的系统像鸟哥的某些发展伺服器一样,那就有可能会使用到这个软体库喔!

好了!根据上面的说明,来玩一玩底下这个模拟案例看看:

问:

我的系统上面想要透过上述的CentOS 7 的EPEL 计画来安装netcdf 以及R 这两套软体,该如何处理?

答:

  • 首先,你的系统应该要针对epel 进行yum 的设定档处理,处理方式如下:

    [root@study ~]# vim /etc/yum.repos.d/epel.repo [epel] name = epel packages baseurl = https://dl.fedoraproject.org/pub/epel/7/x86_64/ gpgcheck = 0 enabled = 0

鸟哥故意不要启动这个软体仓库,只是未来有需要的时候才进行安装,预设不要去找这个软体库!

接下来使用这个软体库来进行安装netcdf 与R 的行为喔!

[root@study ~]# yum --enablerepo=epel install netcdf R

这样就可以安装起来了!未来你没有加上–enablerepo=epel 时,这个EPEL 的软体并不会更新喔!

使用本机的原版光碟

万一你的主机并没有网路,但是你却有很多软体安装的需求~假设你的系统也都还没有任何升级的动作过, 这个时候我能不能用本机的光碟来作为主要的软体来源呢?答案当然是可以啊!那要怎么做呢?很简单,将你的光碟挂载到某个目录,我们这里还是继续假设在/mnt 好了,然后设定如下的yum 设定档:

[root@study ~]# vim /etc/yum.repos.d/cdrom.repo
[mycdrom]
name = mycdrom 
baseurl = file:///mnt
gpgcheck = 0
enabled = 0

[root@study ~]# yum --enablerepo=mycdrom install software_name

五、讨论

5.1 安装32或64位版本

假如你要安装libjpeg的32位版本

1、查询具体的32位版本,然后安装

yum search libjpeg.i686
yum -y install libjpeg.i386

2、一劳永逸的方法,这么做会同时安装32和64位版本。

echo 'multilib_policy=all' >> /etc/yum.conf

5.2 更新CentOS 镜像

首先备份 CentOS-Base.repo

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

将清华的centos镜像内容写入/etc/yum.repos.d/CentOS-Base.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates
[updates]
name=CentOS-$releasever - Updates
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/updates/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/extras/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
baseurl=https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/centosplus/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

运行以下命令生成缓存

yum clean all
yum makecache

5.3 yum history 卸载软件及其依赖

yum带有历史记录功能,可以查看过往的事务,重做或回滚这些事务

最重要的是可以连带依赖一并删除

yum history

root@localhost ~]# yum history
已加载插件:fastestmirror
ID     | 登录用户                 | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
     3 | root <root>              | 2018-08-17 00:02 | Install        |   30   
     2 | root <root>              | 2018-08-17 00:01 | Install        |    4   
     1 | 系统 <空>                | 2018-08-17 07:39 | Install        |  299   
history list
=============================================================================

在历史中搜索某个软件包是

yum history list Name/ ID

[root@localhost ~]# yum history list nxlog-ce
已加载插件:fastestmirror
ID     | 命令行                   | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
     3 | localinstall nxlog-ce-2. | 2018-08-17 00:02 | Install        |   30   
history list
[root@localhost ~]# yum history list 5
已加载插件:fastestmirror
ID     | 命令行                   | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
     5 | install vim              | 2018-08-17 00:43 | Install        |   31   
=============================================================================

回滚是

yum history undo ID

[root@localhost ~]# yum history undo 5
已加载插件:fastestmirror
Undoing transaction 5, from Fri Aug 17 00:43:45 2018
*
*
*
事务概要
===========================================================================================
移除  31 软件包
 
安装大小:60 M
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
*
*
*
删除:
  gpm-libs.x86_64 0:1.20.7-5.el7                      perl.x86_64 4:5.16.3-292.el7                 perl-Carp.noarch 0:1.26-244.el7              
  perl-Encode.x86_64 0:2.51-7.el7                     perl-Exporter.noarch 0:5.68-3.el7            perl-File-Path.noarch 0:2.09-2.el7           
  。。
  perl-threads.x86_64 0:1.87-4.el7             
  perl-threads-shared.x86_64 0:1.43-6.el7             vim-common.x86_64 2:7.4.160-4.el7            vim-enhanced.x86_64 2:7.4.160-4.el7          
  vim-filesystem.x86_64 2:7.4.160-4.el7              

5.4 一次性安装开发工具:yum groupinstall Development tools

[root@study ~]# yum [群组功能] [软体群组]

选项与参数:

grouplist :列出所有可使用的『软体群组组』,例如Development Tools 之类的;
groupinfo :后面接group_name,则可了解该group 内含的所有软体名;
groupinstall:这个好用!可以安装一整组的软体群组,相当的不错用!
groupremove :移除某个软体群组;

查看都有哪些group tools

[spark@sparksinglenode ~]$ yum grouplist | more
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Determining fastest mirrors
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.zju.edu.cn
Installed Groups:
Additional Development
Base
Debugging Tools
...

查看都有哪些group tools 哪些包含development

[spark@sparksinglenode ~]$ yum grouplist | grep Development
Additional Development
Desktop Platform Development
Development tools
Server Platform Development

了解Development tools详情

[spark@sparksinglenode ~]$ yum groupinfo Development tools
Loaded plugins: fastestmirror, refresh-packagekit, security
Setting up Group Process
Loading mirror speeds from cached hostfile
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.tuna.tsinghua.edu.cn
* updates: mirrors.zju.edu.cn

Group: Development tools
Description: A basic development environment.
Mandatory Packages:
autoconf
automake
binutils
bison

安装Development tools

yum -y groupinstall Development tools   
或者  yum  groupinstall Development tools

5.8 全系统自动升级

我们可以手动选择是否需要升级,那能不能让系统自动升级,让我们的系统随时保持在最新的状态呢?当然可以啊!透过『 yum -y update 』来自动升级,那个-y 很重要,因为可以自动回答yes 来开始下载与安装!然后再透过crontab 的功能来处理即可!假设我每天在台湾时间3:00am 网路频宽比较轻松的时候进行升级, 你可以这样做的:

[root@study ~]# echo '10 1 * * * root /usr/bin/yum -y --enablerepo=epel update' > /etc/cron.d/yumupdate 
[root@study ~]# vim /etc/ crontab

从此你的系统就会自动升级啦!很棒吧!此外,你还是得要分析登录档与收集root 的信件的, 因为如果升级的是核心软体(kernel),那么你还是得要重新开机才会让安装的软体顺利运作的!所以还是得分析登录档,若有新核心安装,就重新开机,否则就让系统自动维持在最新较安全的环境吧!真是轻松愉快的管理啊!

5.9 安装到指定位置:

yum -c /etc/yum.conf --installroot=/usr/local --releasever=/  install love

5.10 使用yum更新不自动升级Linux内核的方法

方法一、修改yum的配置文件

vim /etc/yum.conf 在[main]的最后添加

exclude=kernel*  
exclude=centos-release*  

方法二、直接在yum的命令后面加上如下的参数

yum --exclude=kernel* update  

六、报错

5.1 centos yum安装nginx 提示 No package nginx available问题解决方法

问题原因:

nginx位于第三方的yum源里面,而不在centos官方yum源里面

解决方法:

安装epel(Extra Packages for Enterprise Linux)

a、去epel网站 http://fedoraproject.org/wiki/EPEL下载

b、我的系统是centos5.7,cpu是x86_64,所以我下载的是wget http://dl.fedoraproject.org/pub/epel/5/x86_64/epel-release-5-4.noarch.rpm
       如果是centos6, 则应该下载 wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

c、安装epel
 
   rpm -ivh epel-release-5-4.noarch.rpm

再次执行 yum install nginx,则会提示安装成功了 注:

epel的安装跟centos的系统版本、cpu硬件架构有关,

查看系统版本(lsb-release -a),
查看cpu硬件架构(arch)

epel它是RHEL 的 Fedora 软件仓库,为 RHEL 及衍生发行版如 CentOS、Scientific Linux 等提供高质量软件包的项目。装上了 EPEL,就像在 Fedora 上一样,可以通过 yum install package-name,随意安装软件。

5.2 yum安装出现No package vim available解决办法

我一般习惯性先去更新一下yum仓库:

yum -y update

再次运行安装,发现错误依旧,看来这种猜包名的方法不适用;所以接下来可以通过yum的查找参数来列出vim相关的包名:

yum search cuda-9-0

注:这里我犯了一个错误,用的是cuda-9.0怎么都没有搜索到

5.3 yum更换python,以及libcurl报错的解决

今天 yum install ruby的时候,报错 pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (nss)

这个错误一出来,大体上有两个地方值得怀疑:

  1. pycurl包的冲突
  2. yum中对应的python的冲突

考虑到现在默认的python已经替换到anaconda里面,所以决定先替换yum中对应的python

vi /usr/libexec/urlgrabber-ext-down 
将
#!/usr/bin/python 
改为
#!/mnt/nfs/data/software/anaconda2/bin/python2.7

vim /usr/bin/yum

将
#!/usr/bin/python 
改为
#!/mnt/nfs/data/software/anaconda2/bin/python2.7

这个时候,会提示各种 “No module named **”,然后找到以前的python中包含该库的路径

ls /usr/lib/python2.7/site-packages/ | **
ls /usr/lib64/python2.7/site-packages/ |grep **

找到以后,cp到指定的python对应的包的位置

cp -fr /usr/lib/python2.7/site-packages/yum* /data/software/anaconda2/lib/python2.7/site-packages/
cp -fr /usr/lib64/python2.7/site-packages/rpm /data/software/anaconda2/lib/python2.7/site-packages/

接着报错:

/mnt/nfs/data/software/anaconda2/bin/../lib/liblzma.so.5: version `XZ_5.1.2alpha' not found (required by /usr/lib64/librpmio.so.3)

这个报错,是因为liblzma.so.5.2.4版本太高

cd /mnt/nfs/data/software/anaconda2/lib

(base) [root@c01 lib]# ll |grep liblzma
-rw-rw-r--  2 root root   299380 May 17  2018 liblzma.a
-rwxrwxr-x  1 root root      989 Oct 29 10:43 liblzma.la
lrwxrwxrwx  1 root root       16 Oct 29 10:46 liblzma.so -> liblzma.so.5.2.4
lrwxrwxrwx  1 root root       16 Oct 29 10:46 liblzma.so.5 -> liblzma.so.5.2.4
-rwxrwxr-x  2 root root   173408 May 17  2018 liblzma.so.5.2.4

(base) [root@c01 lib]# ll /usr/lib64 |grep liblz
lrwxrwxrwx.  1 root root       15 Aug 27  2018 liblz4.so.1 -> liblz4.so.1.7.5
-rwxr-xr-x.  1 root root    85952 Apr 11  2018 liblz4.so.1.7.5
lrwxrwxrwx.  1 root root       16 Mar 14  2018 liblzma.so -> liblzma.so.5.2.2
lrwxrwxrwx.  1 root root       16 Mar  8  2018 liblzma.so.5 -> liblzma.so.5.2.2
-rwxr-xr-x.  1 root root   157424 Nov  5  2016 liblzma.so.5.2.2
lrwxrwxrwx.  1 root root       16 Mar  8  2018 liblzo2.so.2 -> liblzo2.so.2.0.0
-rwxr-xr-x.  1 root root   135112 Nov 20  2015 liblzo2.so.2.0.0

将liblzma.so.5连接到liblzma.so.5.2.2

(base) [root@c01 lib]# cp /usr/lib64/liblzma.so.5.2.2 /mnt/nfs/data/software/anaconda2/lib/
(base) [root@c01 lib]# ln -s -f liblzma.so.5.2.2 liblzma.so.5
(base) [root@c01 lib]# ll |grep liblzma
-rw-rw-r--  2 root root   299380 May 17  2018 liblzma.a
-rwxrwxr-x  1 root root      989 Oct 29 10:43 liblzma.la
lrwxrwxrwx  1 root root       16 Oct 29 10:46 liblzma.so -> liblzma.so.5.2.4
lrwxrwxrwx  1 root root       16 Apr 18 16:50 liblzma.so.5 -> liblzma.so.5.2.2
-rwxr-xr-x  1 root root   157424 Apr 18 16:50 liblzma.so.5.2.2
-rwxrwxr-x  2 root root   173408 May 17  2018 liblzma.so.5.2.4

接着提示:“No module named urlgrabber”

cp -fr /usr/lib/python2.7/site-packages/urlgrabber* /data/software/anaconda2/lib/python2.7/site-packages/

接着报错:

pycurl: libcurl link-time ssl backend (openssl) is different from compile-time ssl backend (nss)

总算回归到最开始的问题了

# upgrade pip if necessary
pip install --upgrade pip

# remove current pycurl
pip uninstall pycurl

# set PYCURL_SSL_LIBRARY
export PYCURL_SSL_LIBRARY=openssl  ##OpenSSL是一个开放源代码的软件库包,应用程序可以使用这个包来进行安全通信,避免窃听,同时确认另一端连接者的身份。有的可能不是openssl,而是ssl。可以通过终端上运行openssl或ssl 来确定自己安装的是ssl还是openssl

# recompile and install pycurl
easy_install pycurl   # 需要注意的是之前用pip安装的,然后卸载掉以后,一定要用easy_install安装才可以导入成功

注意,在pip uninstall pycurl的时候,报错

PIP: “Cannot uninstall 'pycurl'. It is a distutils installed project and thus we cannot accurately determine…”

我直接在site_packages中,把他们删除。

rm -fr /usr/lib/python2.7/site-packages/pycurl*
rm  -fr /data/software/anaconda2/lib/python2.7/site-packages/pycurl*

报错:

No module named rpmUtils.transaction
No module named sqlitecachec
No module named _sqlitecache

添加包

cp -fr /usr/lib/python2.7/site-packages/rpmUtils /data/software/anaconda2/lib/python2.7/site-packages/
cp -fr /usr/lib64/python2.7/site-packages/sqlitecachec.py /data/software/anaconda2/lib/python2.7/site-packages/
cp -fr /usr/lib64/python2.7/site-packages/_sqlitecache.so /data/software/anaconda2/lib/python2.7/site-packages/

最后,yum install ruby总算成功了。。

5.4 找不到源的各种报错

1. Could not resolve host

报错

failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
https://mirrors.tuna.tsinghua.edu.cn/centos/7/os/x86_64/repodata/repomd.xml: [Errno 14] curl#6 - "Could not resolve host: mirrors.tuna.tsinghua.edu.cn; Unknown error"

先检查是否能Ping得通这个网站

[root@pp yum.repos.d]# ping mirrors.tuna.tsinghua.edu.cn
ping: mirrors.tuna.tsinghua.edu.cn: Name or service not known

完蛋了,其他电脑能Ping通,我这个电脑ping不通,网络问题咯。

2. CentOS7用yum安装软件显示错误:cannot find a valid baseurl for repo: base/7/x86_64

CentOS-Base.repo的问题,解决办法

mv     /etc/yum.repos.d/CentOS-Base.repo    /etc/yum.repos.d/CentOS-Base.repo.bak

3. 报错:

failure: repodata/repomd.xml from base: [Errno 256] No more mirrors to try.
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/x86_64/repodata/repomd.xml: [Errno 14] HTTPS Error 404 - Not Found

这个报错很简单,根据网址,找不到这个repomd.xml文件。首先查看一下自己centos的版本

cat /etc/redhat-release

可以看到我的版本是7.7.1908。然后进入到 https://mirrors.tuna.tsinghua.edu.cn/centos/7.7.1908 ,可以看到README,写着

This directory (and version of CentOS) is deprecated.  For normal users,
you should use /7/ and not /7.7.1908/ in your path. Please see this FAQ
concerning the CentOS release scheme:

https://wiki.centos.org/FAQ/General

If you know what you are doing, and absolutely want to remain at the 7.7.1908
level, go to http://vault.centos.org/ for packages. 

Please keep in mind that 7.7.1908 no longer gets any updates, nor
any security fix's.

那就是说,这个地址不在提供下载源了,统一从7下载,那就将$releasever统一改成7吧。

vim CentOS-Base.repo , 将$releasever都替换成7

然后重新生成缓存

yum makecache
yum clean all

5.5 在 CentOS 8 中安装软件出现 “错误:为仓库 ‘appstream’ 下载元数据失败” 的解决办法

在 CentOS 8 中使用 yum 命令安装软件时会出现 “错误:为仓库 ‘appstream’ 下载元数据失败 : Cannot prepare internal mirrorlist: No URLs in mirrorlist“,如下图所示:

出现这个错误提示的原因是在2022年1月31日,CentOS 团队从官方镜像中移除 CentOS 8 的所有包。因为 CentOS 8 已于2021年12月31日停止官方服务了,但软件包仍在官方镜像上保留了一段时间。现在他们被转移到 https://vault.centos.org。如果你仍然需要运行 CentOS 8,你可以在 /etc/yum.repos.d 中更新一下源。使用 http://vault.centos.org 代替 http://mirror.centos.org 即可。

打开终端,输入 su 命令切换 root 用户登录,然后使用下面的命令更新源:

sed -i -e "s|mirrorlist=|#mirrorlist=|g" /etc/yum.repos.d/CentOS-*
sed -i -e "s|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g" /etc/yum.repos.d/CentOS-*

参考资料

药企,独角兽,苏州。团队长期招人,感兴趣的都可以发邮件聊聊:tiehan@sina.cn
个人公众号,比较懒,很少更新,可以在上面提问题,如果回复不及时,可发邮件给我: tiehan@sina.cn