Linux-yum工具的使用

Linux-yum工具的使用

什么是yum

Yum(全称为 Yellowdog Updater Modified)是一个在Fedora和RedHat以及CentOS中的Shell前端软件包管理器。基于RPM包管理,能够从指定的服务器自动下载RPM包并且安装,可以自动处理依赖性关系,并且一次安装所有依赖的软件包,无须繁琐地一次次下载、安装。yum提供了查找、安装、删除某一个、一组甚至全部软件包的命令,而且命令简洁而又好记。

查看内核版本号

[root@localhost ~]# uname -r
4.18.0-193.el8.x86_64

挂载光盘

当我们使用本地配置yum时,需要挂载光盘

[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@localhost ~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               883M     0  883M   0% /dev
tmpfs                  901M     0  901M   0% /dev/shm
tmpfs                  901M  8.6M  892M   1% /run
tmpfs                  901M     0  901M   0% /sys/fs/cgroup
/dev/mapper/rhel-root   50G  1.7G   49G   4% /
/dev/nvme0n1p1        1014M  179M  836M  18% /boot
/dev/mapper/rhel-home   47G  368M   47G   1% /home
tmpfs                  181M     0  181M   0% /run/user/0
/dev/sr0               7.9G  7.9G     0 100% /mnt

yum的配置文件

  • 配置文件有哪些:
    • /etc/yum.conf 作用:为所有仓库提供公共配置
    • /etc/yum.repos.d/*.repo 作用:为仓库的指向提供配置
  • yum的repo配置文件中可用的变量:
    • $releaseversion:当前OS的发行版的主版本号
    • $arch:平台类型
    • $basearch:基础平台
[root@localhost ~]# vi /etc/yum.conf 
[main]
gpgcheck=1							//检查软件包合法性
installonly_limit=3					        //只能同时安装3个软件包
clean_requirements_on_remove=True	                        //卸载后清理所需要的软件包
best=True
skip_if_unavailable=False			                //如果软件包不可用也不跳过
[root@localhost ~]# vi /etc/yum.repos.d/redhat.repo
[BaseOS]							//仓库名称
name=baseos							//描述信息
baseurl=file:///mnt/BaseOS/			                //仓库的具体路径,有三种:ftp,http,file,这里用的是本地file
gpgcheck=0							//1为检查软件包来源合法性,0为不检查来源
enabled=1							//1为启用此仓库,0为禁用此仓库
[AppStream]
name=appstream
baseurl=file:///mnt/AppStream/
gpgcheck=0
enabled=1

yum仓库管理

如何配置yum本地仓库

//第一步:挂载光盘
[root@localhost ~]# mount /dev/cdrom /mnt/
mount: /mnt: WARNING: device write-protected, mounted read-only.

//第二步:复制光盘内容到本地
[root@localhost ~]# mkdir /opt/yum_local
[root@localhost ~]# cp -r /mnt/* /opt/yum_local/
[root@localhost ~]# uname -r
4.18.0-193.el8.x86_64
[root@localhost ~]# ls /opt/yum_local/
AppStream  EFI   extra_files.json  images    media.repo               RPM-GPG-KEY-redhat-release
BaseOS     EULA  GPL               isolinux  RPM-GPG-KEY-redhat-beta  TRANS.TBL

//第三步:配置repo文件
[root@localhost ~]# ls /etc/yum.repos.d/
redhat.repo
[root@localhost ~]# vi /etc/yum.repos.d/redhat.repo 
[root@localhost ~]# cat /etc/yum.repos.d/redhat.repo 
[BaseOS]
name=baseos
baseurl=file:///opt/yum_local/BaseOS/
gpgcheck=0
enabled=1
[AppStream]
name=appstream
baseurl=file:///opt/yum_local/AppStream/
gpgcheck=0
enabled=1

//第四步:清空yum本地缓存
[root@localhost ~]# yum clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
12 files removed

//第五步:检验yum本地仓库
[root@localhost ~]# yum list all
yum list | head
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:07:09 ago on Wed 02 Dec 2020 02:02:09 PM CST.
Installed Packages
NetworkManager.x86_64                                1:1.22.8-4.el8                                   @anaconda 
NetworkManager-libnm.x86_64                          1:1.22.8-4.el8                                   @anaconda 
NetworkManager-team.x86_64                           1:1.22.8-4.el8                                   @anaconda 
NetworkManager-tui.x86_64                            1:1.22.8-4.el8                                   @anaconda 
acl.x86_64                                           2.2.53-1.el8                                     @anaconda 
......
zsh-html.noarch                                    5.5.1-6.el8_1.2                           AppStream 
zstd.x86_64                                        1.4.2-2.el8                               AppStream 
zziplib.i686                                       0.13.68-8.el8                             AppStream 
zziplib.x86_64                                     0.13.68-8.el8                             AppStream 
zziplib-utils.x86_64                               0.13.68-8.el8                             AppStream

如何配置yum网络仓库

  • 官方网络yum仓库(国外)
  • 阿里云yum仓库
  • 163yum仓库
  • xx大学yum仓库
  • epel源

本次演示使用的是阿里云yum仓库http://mirrors.aliyun.com

//第一步:下载新的 CentOS-Base.repo 到 /etc/yum.repos.d/
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2595  100  2595    0     0   2826      0 --:--:-- --:--:-- --:--:--  2823
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Base.repo  redhat.repo

//第二步:删除不需要的配置
[root@localhost ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

//第三步:修改配置文件将$releasever改为对应自己系统的版本号
[root@localhost ~]# vi /etc/yum.repos.d/CentOS-Base.repo 
:%s/$releasever/8/g

//第四步:清空yum本地缓存
[root@localhost ~]# yum clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
12 files removed

//第五步:检验yum本地仓库
[root@localhost ~]# yum list all
......
zlib.i686                                         1.2.11-16.el8_2                            base      
zlib.x86_64                                       1.2.11-16.el8_2                            base      
zlib-devel.i686                                   1.2.11-16.el8_2                            base      
zlib-devel.x86_64                                 1.2.11-16.el8_2                            base      
zsh.x86_64                                        5.5.1-6.el8_1.2                            base      
zsh-html.noarch                                   5.5.1-6.el8_1.2                            AppStream 
zstd.x86_64                                       1.4.2-2.el8                                AppStream 
zziplib.i686                                      0.13.68-8.el8                              AppStream 
zziplib.x86_64                                    0.13.68-8.el8                              AppStream 
zziplib-utils.x86_64                              0.13.68-8.el8                              AppStream

yum管理软件

小拓展:为什么用yum安装时,不用指定软件包的位置和版本号?

答:因为yum仓库有清单,使用yum它会自己去查清单。

安装软件包常用选项

//-y 自动回答yes
[root@localhost ~]# yum -y install zsh
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:03:54 ago on Tue 01 Dec 2020 12:52:13 PM CST.

Dependencies resolved.
=======================================================================================================

 Package            Architecture          Version                          Repository             Size
=======================================================================================================

Installing:
 zsh                x86_64                5.5.1-6.el8_1.2                  BaseOS                2.9 M

Transaction Summary
=======================================================================================================

Install  1 Package

Total size: 2.9 M
Installed size: 7.2 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1 
  Installing       : zsh-5.5.1-6.el8_1.2.x86_64                                                    1/1 
  Running scriptlet: zsh-5.5.1-6.el8_1.2.x86_64                                                    1/1 
  Verifying        : zsh-5.5.1-6.el8_1.2.x86_64                                                    1/1 
Installed products updated.

Installed:
  zsh-5.5.1-6.el8_1.2.x86_64                                                                           

Complete!
//-q 静默安装不输出信息
[root@localhost ~]# yum -q install zsh
Is this ok [y/N]: y
[root@localhost ~]# echo $?				//如果为0说明执行成功,如果非0说明执行失败
0
[root@localhost ~]# rpm -qa | grep zsh
zsh-5.5.1-6.el8_1.2.x86_64

yum常用命令

list 列表

//list installed	列出已经安装的包
[root@localhost ~]# yum list installed | grep zsh
zsh.x86_64                                    5.5.1-6.el8_1.2                        @BaseOS   

//list available	列出可用未安装的包
[root@localhost ~]# yum list available | grep zsh
zsh-html.noarch                                      5.5.1-6.el8_1.2                                   AppStream

//list updates	列出可升级的包
[root@localhost ~]# yum list updates
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:29:23 ago on Tue 01 Dec 2020 12:52:13 PM CST.

clean 清理缓存

//clean all	清理所有缓存
[root@localhost ~]# yum clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
12 files removed

repolist 仓库列表

//repolist all	列出所有仓库
[root@localhost ~]# yum repolist all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repo id                                        repo name                                       status
AppStream                                      appstream                                       enabled
BaseOS                                         baseos                                          enabled
yqh                                            yqh                                             disable

//repolist enabled 列出可用的仓库(默认是enabled)
[root@localhost ~]# yum repolist enabled
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repo id                                             repo name
AppStream                                           appstream
BaseOS                                              baseos

//repolist disabled	列出不可用的仓库
[root@localhost ~]# yum repolist disabled
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
repo id                                               repo name
yqh                                                   yqh

install 安装

//一次性安装zsh,wget,vim
[root@localhost ~]# yum -y install zsh wget vim
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
baseos                                                                 141 MB/s | 2.3 MB     00:00    
appstream                                                              148 MB/s | 5.8 MB     00:00    
Last metadata expiration check: 0:00:01 ago on Tue 01 Dec 2020 01:31:22 PM CST.
Dependencies resolved.
=======================================================================================================
 Package                   Architecture      Version                        Repository            Size
=======================================================================================================
Installing:
 vim-enhanced              x86_64            2:8.0.1763-13.el8              AppStream            1.4 M
 wget                      x86_64            1.19.5-8.el8_1.1               AppStream            735 k
 zsh                       x86_64            5.5.1-6.el8_1.2                BaseOS               2.9 M
Installing dependencies:
 gpm-libs                  x86_64            1.20.7-15.el8                  AppStream             39 k
 vim-common                x86_64            2:8.0.1763-13.el8              AppStream            6.3 M
 vim-filesystem            noarch            2:8.0.1763-13.el8              AppStream             48 k

Transaction Summary
=======================================================================================================
Install  6 Packages

Total size: 11 M
Installed size: 41 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1 
  Installing       : vim-filesystem-2:8.0.1763-13.el8.noarch                                       1/6 
  Installing       : vim-common-2:8.0.1763-13.el8.x86_64                                           2/6 
  Installing       : gpm-libs-1.20.7-15.el8.x86_64                                                 3/6 
  Running scriptlet: gpm-libs-1.20.7-15.el8.x86_64                                                 3/6 
  Installing       : vim-enhanced-2:8.0.1763-13.el8.x86_64                                         4/6 
  Installing       : wget-1.19.5-8.el8_1.1.x86_64                                                  5/6 
  Running scriptlet: wget-1.19.5-8.el8_1.1.x86_64                                                  5/6 
  Installing       : zsh-5.5.1-6.el8_1.2.x86_64                                                    6/6 
  Running scriptlet: zsh-5.5.1-6.el8_1.2.x86_64                                                    6/6 
  Running scriptlet: vim-common-2:8.0.1763-13.el8.x86_64                                           6/6 
  Verifying        : zsh-5.5.1-6.el8_1.2.x86_64                                                    1/6 
  Verifying        : gpm-libs-1.20.7-15.el8.x86_64                                                 2/6 
  Verifying        : vim-common-2:8.0.1763-13.el8.x86_64                                           3/6 
  Verifying        : vim-enhanced-2:8.0.1763-13.el8.x86_64                                         4/6 
  Verifying        : vim-filesystem-2:8.0.1763-13.el8.noarch                                       5/6 
  Verifying        : wget-1.19.5-8.el8_1.1.x86_64                                                  6/6 
Installed products updated.

Installed:
  gpm-libs-1.20.7-15.el8.x86_64                     vim-common-2:8.0.1763-13.el8.x86_64                
  vim-enhanced-2:8.0.1763-13.el8.x86_64             vim-filesystem-2:8.0.1763-13.el8.noarch            
  wget-1.19.5-8.el8_1.1.x86_64                      zsh-5.5.1-6.el8_1.2.x86_64                         

Complete!

update 更新

//更新所有包
[root@localhost ~]# yum update
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:01:49 ago on Tue 01 Dec 2020 01:31:22 PM CST.
Dependencies resolved.
Nothing to do.
Complete!

//只更新wget
[root@localhost ~]# yum list updates
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:51:21 ago on Tue 01 Dec 2020 01:46:39 PM CST.
Available Upgrades
wget.x86_64                                 1.19.5-8.el8_1.1                                  AppStream
[root@localhost ~]# yum -y update wget
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:52:39 ago on Tue 01 Dec 2020 01:46:39 PM CST.
Dependencies resolved.
=======================================================================================================
 Package            Architecture         Version                         Repository               Size
=======================================================================================================
Upgrading:
 wget               x86_64               1.19.5-8.el8_1.1                AppStream               735 k

Transaction Summary
=======================================================================================================
Upgrade  1 Package

Total size: 735 k
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1 
  Upgrading        : wget-1.19.5-8.el8_1.1.x86_64                                                  1/2 
  Running scriptlet: wget-1.19.5-8.el8_1.1.x86_64                                                  1/2 
  Running scriptlet: wget-1.14-18.el7_6.1.x86_64                                                   2/2 
  Cleanup          : wget-1.14-18.el7_6.1.x86_64                                                   2/2 
  Running scriptlet: wget-1.14-18.el7_6.1.x86_64                                                   2/2 
  Verifying        : wget-1.19.5-8.el8_1.1.x86_64                                                  1/2 
  Verifying        : wget-1.14-18.el7_6.1.x86_64                                                   2/2 
Installed products updated.

Upgraded:
  wget-1.19.5-8.el8_1.1.x86_64                                                                         

Complete!

remove|erase 卸载

//卸载zsh
[root@localhost ~]# yum -y remove zsh			//这里的remove可以换成erase
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Dependencies resolved.
=======================================================================================================
 Package            Architecture          Version                         Repository              Size
=======================================================================================================
Removing:
 zsh                x86_64                5.5.1-6.el8_1.2                 @BaseOS                7.2 M

Transaction Summary
=======================================================================================================
Remove  1 Package

Freed space: 7.2 M
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1 
  Running scriptlet: zsh-5.5.1-6.el8_1.2.x86_64                                                    1/1 
  Erasing          : zsh-5.5.1-6.el8_1.2.x86_64                                                    1/1 
  Running scriptlet: zsh-5.5.1-6.el8_1.2.x86_64                                                    1/1 
  Verifying        : zsh-5.5.1-6.el8_1.2.x86_64                                                    1/1 
Installed products updated.

Removed:
  zsh-5.5.1-6.el8_1.2.x86_64                                                                           

Complete!

info 查询软件包的相关信息

//查询wget的相关信息
[root@localhost ~]# yum info wget
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:06:48 ago on Tue 01 Dec 2020 01:31:22 PM CST.
Installed Packages
Name         : wget
Version      : 1.19.5
Release      : 8.el8_1.1
Architecture : x86_64
Size         : 2.9 M
Source       : wget-1.19.5-8.el8_1.1.src.rpm
Repository   : @System
From repo    : AppStream
Summary      : A utility for retrieving files using the HTTP or FTP protocols
URL          : http://www.gnu.org/software/wget/
License      : GPLv3+
Description  : GNU Wget is a file retrieval utility which can use either the HTTP or
             : FTP protocols. Wget features include the ability to work in the
             : background while you are logged out, recursive retrieval of
             : directories, file name wildcard matching, remote file timestamp
             : storage and comparison, use of Rest with FTP servers and Range with
             : HTTP servers to retrieve files over slow or unstable connections,
             : support for Proxy servers, and configurability.

provides 查看指定的文件或特性是由哪个包安装生成的

//查看wget是由哪个包安装生成的
[root@localhost ~]# yum provides wget
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:10:52 ago on Tue 01 Dec 2020 01:31:22 PM CST.
wget-1.19.5-8.el8_1.1.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
Repo        : @System
Matched from:
Provide    : wget = 1.19.5-8.el8_1.1

wget-1.19.5-8.el8_1.1.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
Repo        : AppStream
Matched from:
Provide    : wget = 1.19.5-8.el8_1.1

search 指定的关键字搜索软件包

//查询跟zsh相关的软件包
[root@localhost ~]# yum search zsh
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:02:20 ago on Tue 01 Dec 2020 01:46:39 PM CST.
====================================== Name Exactly Matched: zsh ======================================
zsh.x86_64 : Powerful interactive shell
===================================== Name & Summary Matched: zsh =====================================
zsh-html.noarch : Zsh shell manual in html format

deplist 显示指定包的依赖关系

//查看vim的依赖包
[root@localhost ~]# yum deplist vim-enhanced
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:05:29 ago on Tue 01 Dec 2020 01:46:39 PM CST.
package: vim-enhanced-2:8.0.1763-13.el8.x86_64
  dependency: /bin/sh
   provider: bash-4.4.19-10.el8.x86_64
  dependency: libacl.so.1()(64bit)
   provider: libacl-2.2.53-1.el8.x86_64
  dependency: libacl.so.1(ACL_1.0)(64bit)
   provider: libacl-2.2.53-1.el8.x86_64
  dependency: libc.so.6(GLIBC_2.28)(64bit)
   provider: glibc-2.28-101.el8.x86_64
  dependency: libdl.so.2()(64bit)
   provider: glibc-2.28-101.el8.x86_64
  dependency: libdl.so.2(GLIBC_2.2.5)(64bit)
   provider: glibc-2.28-101.el8.x86_64
  dependency: libgpm.so.2()(64bit)
   provider: gpm-libs-1.20.7-15.el8.x86_64
  dependency: libm.so.6()(64bit)
   provider: glibc-2.28-101.el8.x86_64
  dependency: libm.so.6(GLIBC_2.2.5)(64bit)
   provider: glibc-2.28-101.el8.x86_64
  dependency: libpthread.so.0()(64bit)
   provider: glibc-2.28-101.el8.x86_64
  dependency: libpthread.so.0(GLIBC_2.2.5)(64bit)
   provider: glibc-2.28-101.el8.x86_64
  dependency: libselinux.so.1()(64bit)
   provider: libselinux-2.9-3.el8.x86_64
  dependency: libtinfo.so.6()(64bit)
   provider: ncurses-libs-6.1-7.20180224.el8.x86_64
  dependency: rtld(GNU_HASH)
   provider: glibc-2.28-101.el8.i686
   provider: glibc-2.28-101.el8.x86_64
  dependency: vim-common = 2:8.0.1763-13.el8
   provider: vim-common-2:8.0.1763-13.el8.x86_64
  dependency: which
   provider: which-2.21-12.el8.x86_64

history 查看yum的历史事务信息

[root@localhost ~]# yum history
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
ID     | Command line             | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
     5 | -y remove zsh            | 2020-12-01 13:35 | Removed        |    1   
     4 | -y install zsh wget vim  | 2020-12-01 13:31 | Install        |    6  <
     3 | -q install zsh           | 2020-12-01 12:59 | Install        |    1 ><
     2 | -y install zsh           | 2020-12-01 12:56 | Install        |    1 > 
     1 |                          | 2020-11-16 18:43 | Install        |  420 EE
     
//查看历史记录第四行的详细信息
[root@localhost ~]# yum history info 4
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Transaction ID : 4
Begin time     : Tue 01 Dec 2020 01:31:26 PM CST
Begin rpmdb    : 417:3d3b11ecfb8c229d0915cef350b906880c4b8bbb
End time       : Tue 01 Dec 2020 01:31:37 PM CST (11 seconds)
End rpmdb      : 423:15f529b46ad1dc8cd0ed944f727c8a0e03f259ce
User           : root <root>
Return-Code    : Success
Releasever     : 8
Command Line   : -y install zsh wget vim
Packages Altered:
    Install zsh-5.5.1-6.el8_1.2.x86_64              @BaseOS
    Install gpm-libs-1.20.7-15.el8.x86_64           @AppStream
    Install vim-common-2:8.0.1763-13.el8.x86_64     @AppStream
    Install vim-enhanced-2:8.0.1763-13.el8.x86_64   @AppStream
    Install vim-filesystem-2:8.0.1763-13.el8.noarch @AppStream
    Install wget-1.19.5-8.el8_1.1.x86_64            @AppStream


//撤销历史执行过的第四条命令
[root@localhost ~]# yum history undo 4
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:08:41 ago on Tue 01 Dec 2020 03:00:31 PM CST.
Undoing transaction 4, from Tue 01 Dec 2020 01:31:26 PM CST
    Install zsh-5.5.1-6.el8_1.2.x86_64              @BaseOS
    Install gpm-libs-1.20.7-15.el8.x86_64           @AppStream
    Install vim-common-2:8.0.1763-13.el8.x86_64     @AppStream
    Install vim-enhanced-2:8.0.1763-13.el8.x86_64   @AppStream
    Install vim-filesystem-2:8.0.1763-13.el8.noarch @AppStream
    Install wget-1.19.5-8.el8_1.1.x86_64            @AppStream
No package wget-1.19.5-8.el8_1.1.x86_64 installed.
No package zsh-5.5.1-6.el8_1.2.x86_64 installed.
Error: no package matched

localinstall 安装本地rpm包,自动解决依赖关系

//我们先下载一个wget软件包
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm
--2020-12-01 14:04:37--  http://mirror.centos.org/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm
Resolving mirror.centos.org (mirror.centos.org)... 111.90.139.14, 2604:1380:3000:2800::1
Connecting to mirror.centos.org (mirror.centos.org)|111.90.139.14|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 560272 (547K) [application/x-rpm]
Saving to: ‘wget-1.14-18.el7_6.1.x86_64.rpm.1’

wget-1.14-18.el7_6.1.x86_ 100%[====================================>] 547.14K  5.76KB/s    in 59s     

2020-12-01 14:05:37 (9.28 KB/s) - ‘wget-1.14-18.el7_6.1.x86_64.rpm.1’ saved [560272/560272]
[root@localhost ~]# ls
anaconda-ks.cfg  wget-1.14-18.el7_6.1.x86_64.rpm

//下载完毕后卸载wget,用rpm安装下载好的软件包
[root@localhost ~]# yum -y -q remove wget
[root@localhost ~]# rpm -ivh wget-1.14-18.el7_6.1.x86_64.rpm 
warning: wget-1.14-18.el7_6.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
error: Failed dependencies:
	libcrypto.so.10()(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libcrypto.so.10(libcrypto.so.10)(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libidn.so.11()(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libidn.so.11(LIBIDN_1.0)(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libssl.so.10()(64bit) is needed by wget-1.14-18.el7_6.1.x86_64
	libssl.so.10(libssl.so.10)(64bit) is needed by wget-1.14-18.el7_6.1.x86_64

//发现有很多依赖包,用rpm安装不上,但是我们能用yum localinstall安装它
[root@localhost ~]# yum -y localinstall wget-1.14-18.el7_6.1.x86_64.rpm 
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:26:09 ago on Tue 01 Dec 2020 01:46:39 PM CST.
Dependencies resolved.
=======================================================================================================
 Package                    Architecture     Version                      Repository              Size
=======================================================================================================
Installing:
 wget                       x86_64           1.14-18.el7_6.1              @commandline           547 k
Installing dependencies:
 compat-openssl10           x86_64           1:1.0.2o-3.el8               AppStream              1.1 M
 emacs-filesystem           noarch           1:26.1-5.el8                 BaseOS                  69 k
 libidn                     x86_64           1.34-5.el8                   AppStream              239 k
 make                       x86_64           1:4.2.1-10.el8               BaseOS                 498 k

Transaction Summary
=======================================================================================================
Install  5 Packages

Total size: 2.5 M
Installed size: 7.1 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1 
  Installing       : make-1:4.2.1-10.el8.x86_64                                                    1/5 
  Running scriptlet: make-1:4.2.1-10.el8.x86_64                                                    1/5 
  Installing       : compat-openssl10-1:1.0.2o-3.el8.x86_64                                        2/5 
  Running scriptlet: compat-openssl10-1:1.0.2o-3.el8.x86_64                                        2/5 
  Installing       : emacs-filesystem-1:26.1-5.el8.noarch                                          3/5 
  Installing       : libidn-1.34-5.el8.x86_64                                                      4/5 
  Running scriptlet: libidn-1.34-5.el8.x86_64                                                      4/5 
  Installing       : wget-1.14-18.el7_6.1.x86_64                                                   5/5 
  Running scriptlet: wget-1.14-18.el7_6.1.x86_64                                                   5/5 
  Verifying        : emacs-filesystem-1:26.1-5.el8.noarch                                          1/5 
  Verifying        : make-1:4.2.1-10.el8.x86_64                                                    2/5 
  Verifying        : compat-openssl10-1:1.0.2o-3.el8.x86_64                                        3/5 
  Verifying        : libidn-1.34-5.el8.x86_64                                                      4/5 
  Verifying        : wget-1.14-18.el7_6.1.x86_64                                                   5/5 
Installed products updated.

Installed:
  compat-openssl10-1:1.0.2o-3.el8.x86_64 emacs-filesystem-1:26.1-5.el8.noarch libidn-1.34-5.el8.x86_64
  make-1:4.2.1-10.el8.x86_64             wget-1.14-18.el7_6.1.x86_64         

Complete!

安装网络上rpm包

//安装网络上的wget包
[root@localhost ~]# yum -y install http://mirror.centos.org/centos/7/os/x86_64/Packages/wget-1.14-18.el7_6.1.x86_64.rpm
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:04:14 ago on Tue 01 Dec 2020 01:46:39 PM CST.
wget-1.14-18.el7_6.1.x86_64.rpm                                        134 kB/s | 547 kB     00:04    
Dependencies resolved.
=======================================================================================================
 Package           Architecture        Version                         Repository                 Size
=======================================================================================================
Installing:
 wget              x86_64              1.14-18.el7_6.1                 @commandline              547 k

Transaction Summary
=======================================================================================================
Install  1 Package

Total size: 547 k
Installed size: 2.0 M
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1 
  Installing       : wget-1.14-18.el7_6.1.x86_64                                                   1/1 
  Running scriptlet: wget-1.14-18.el7_6.1.x86_64                                                   1/1 
  Verifying        : wget-1.14-18.el7_6.1.x86_64                                                   1/1 
Installed products updated.

Installed:
  wget-1.14-18.el7_6.1.x86_64                                                                          

Complete!

grouplist 列出可用的组

[root@localhost ~]# yum grouplist
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:34:28 ago on Tue 01 Dec 2020 01:46:39 PM CST.
Available Environment Groups:
   Server with GUI
   Server
   Workstation
   Custom Operating System
   Virtualization Host
Installed Environment Groups:
   Minimal Install
Available Groups:
   Legacy UNIX Compatibility
   Container Management
   Development Tools
   .NET Core Development
   Graphical Administration Tools
   Headless Management
   Network Servers
   RPM Development Tools
   Scientific Support
   Security Tools
   Smart Card Support
   System Tools

groups mark install 安装包组

[root@localhost ~]# yum -y groups mark install "Development Tools"
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:40:18 ago on Tue 01 Dec 2020 01:46:39 PM CST.
Dependencies resolved.
=======================================================================================================
 Package                 Architecture           Version                  Repository               Size
=======================================================================================================
Installing Groups:
 Development Tools                                                                                    

Transaction Summary
=======================================================================================================

Complete!

groups mark remove 卸载包组

[root@localhost ~]# yum -y groups mark install "Development Tools"
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:40:18 ago on Tue 01 Dec 2020 01:46:39 PM CST.
Dependencies resolved.
=======================================================================================================
 Package                 Architecture           Version                  Repository               Size
=======================================================================================================
Installing Groups:
 Development Tools                                                                                    

Transaction Summary
=======================================================================================================

Complete!
[root@localhost ~]# yum -y groups mark remove "Development Tools"
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:41:34 ago on Tue 01 Dec 2020 01:46:39 PM CST.
Dependencies resolved.
=======================================================================================================
 Package                 Architecture           Version                  Repository               Size
=======================================================================================================
Removing Groups:
 Development Tools                                                                                    

Transaction Summary
=======================================================================================================

Complete!

createrepo 创建yum源(软件仓库),即为存放于本地特定位置的众多rpm包建立索引,描述各包所需依赖信息,并形成元数据

重装软件包

//检查软件是否存在
[root@localhost ~]# rpm -q vsftpd
vsftpd-3.0.3-31.el8.x86_64

//检查vsftpd软件配置文件
[root@localhost ~]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf

//假装不小心删除vsftpd配置文件
[root@localhost ~]# rm -f /etc/vsftpd/vsftpd.conf 

//重新安装软件
[root@localhost ~]# yum reinstall vsftpd
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 1:08:23 ago on Tue 01 Dec 2020 01:46:39 PM CST.
Dependencies resolved.
=======================================================================================================
 Package              Architecture         Version                       Repository               Size
=======================================================================================================
Reinstalling:
 vsftpd               x86_64               3.0.3-31.el8                  AppStream               180 k

Transaction Summary
=======================================================================================================

Total size: 180 k
Installed size: 343 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                               1/1 
  Running scriptlet: vsftpd-3.0.3-31.el8.x86_64                                                    1/1 
  Reinstalling     : vsftpd-3.0.3-31.el8.x86_64                                                    1/2 
  Running scriptlet: vsftpd-3.0.3-31.el8.x86_64                                                    1/2 
  Running scriptlet: vsftpd-3.0.3-31.el8.x86_64                                                    2/2 
  Cleanup          : vsftpd-3.0.3-31.el8.x86_64                                                    2/2 
  Running scriptlet: vsftpd-3.0.3-31.el8.x86_64                                                    2/2 
  Verifying        : vsftpd-3.0.3-31.el8.x86_64                                                    1/2 
  Verifying        : vsftpd-3.0.3-31.el8.x86_64                                                    2/2 
Installed products updated.

Reinstalled:
  vsftpd-3.0.3-31.el8.x86_64                                                                           

Complete!

//再次检查
[root@localhost ~]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf

与缓存相关的命令

makecache

存yum源软件仓库, xml元数据文件

//本次演示yum源为阿里云yum源
[root@localhost ~]# yum makecache
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
CentOS-8 - Base - mirrors.aliyun.com                                   119 kB/s | 2.2 MB     00:19    
CentOS-8 - Extras - mirrors.aliyun.com                                 296  B/s | 8.6 kB     00:29    
CentOS-8 - AppStream - mirrors.aliyun.com                              385 kB/s | 5.8 MB     00:15    
Metadata cache created.

另一种缓存rpm包方式

将软件下载至指定目录

[root@localhost ~]# yum -y install --downloadonly --downloaddir=/tmp/ wget
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:03:46 ago on Tue 01 Dec 2020 03:00:31 PM CST.
Dependencies resolved.
=======================================================================================================
 Package            Architecture         Version                         Repository               Size
=======================================================================================================
Installing:
 wget               x86_64               1.19.5-8.el8_1.1                AppStream               735 k

Transaction Summary
=======================================================================================================
Install  1 Package

Total download size: 735 k
Installed size: 2.9 M
YUM will only download packages for the transaction.
Downloading Packages:
wget-1.19.5-8.el8_1.1.x86_64.rpm                                       120 kB/s | 735 kB     00:06    
-------------------------------------------------------------------------------------------------------
Total                                                                  120 kB/s | 735 kB     00:06     
warning: /tmp/wget-1.19.5-8.el8_1.1.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID 8483c65d: NOKEY
CentOS-8 - AppStream - mirrors.aliyun.com                              2.8 kB/s | 1.6 kB     00:00    
Importing GPG key 0x8483C65D:
 Userid     : "CentOS (CentOS Official Signing Key) <security@centos.org>"
 Fingerprint: 99DB 70FA E1D7 CE22 7FB6 4882 05B5 55B3 8483 C65D
 From       : https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
Key imported successfully
Complete!
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
[root@localhost ~]# ls /tmp/
wget-1.19.5-8.el8_1.1.x86_64.rpm

YUM签名检查机制

  • rpm软件提供组织redhat在构建rpm包时, 使用其私钥private key对 rpm进行签名
  • 客户端在使用rpm为了验证其合法性, 可以使用redhat提供的公钥public key进行签名检查

方式1:指定公钥位置

[root@localhost ~]# vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-8 - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/8/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

方式2:不进行签名验证

//不检查软件包的签名
[root@localhost ~]# yum --nogpgcheck install wget
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:14:34 ago on Tue 01 Dec 2020 03:00:31 PM CST.
Dependencies resolved.
==========================================================================================================
 Package             Architecture          Version                         Repository                Size
==========================================================================================================
Installing:
 wget                x86_64                1.19.5-8.el8_1.1                AppStream                735 k

Transaction Summary
==========================================================================================================
Install  1 Package

Total download size: 735 k
Installed size: 2.9 M
Is this ok [y/N]: y
Downloading Packages:
wget-1.19.5-8.el8_1.1.x86_64.rpm                                          1.1 MB/s | 735 kB     00:00    
----------------------------------------------------------------------------------------------------------
Total                                                                     1.1 MB/s | 735 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                  1/1 
  Installing       : wget-1.19.5-8.el8_1.1.x86_64                                                     1/1 
  Running scriptlet: wget-1.19.5-8.el8_1.1.x86_64                                                     1/1 
  Verifying        : wget-1.19.5-8.el8_1.1.x86_64                                                     1/1 
Installed products updated.

Installed:
  wget-1.19.5-8.el8_1.1.x86_64                                                                            

Complete!
原文地址:https://www.cnblogs.com/yuqinghao/p/14073446.html