10yum工具使用

yum工具的使用

1. rpm的弊端

当用rpm安装软件时,若遇到有依赖关系的软件,必须先安装依赖的软件才能继续安装我们要安装的软件,当依赖关系很复杂的情况下,这种安装方式就很让人头疼,所以我们需要另一种安装方式来解决这个问题,今天我们要来学习的就是这样一个工具–yum

2. yum的优劣势

yum最大的优势就是能够解决rpm的依赖问题,yum能够自动解决软件安装时的依赖关系。当然了,有优势就有劣势,人无完人嘛,软件也是一样的,yum的缺陷就是如果在未完成安装的情况下强行中止安装过程,下次再安装时将无法解决依赖关系,Fedora22+、redhat7和centos7等可以通过手动安装dnf工具来解决此问题。

dnf是redhat7上用来代替yum的一个工具,其存在的意义就是处理yum的缺陷,但其用法与yum是完全一样的,甚至连选项都是一样的,你可以理解为dnf就是yum,只是换了个名字而已。所以说只要学会了yum就自然会dnf,大家不用担心学了yum又要去学dnf之类的问题

3. 什么是yum及其作用

yum是yellowdog update manager的简称,它能够实现rpm管理的所有操作,并能够自动解决各rpm包之间的依赖关系。yum是rpm的前端工具,是基于rpm来实现软件的管理的一个工具。

你不能用yum去管理windows的exe程序包,也不能用yum去管理ubuntu的deb程序包,只能用yum来管理redhat系列的rpm包

4. 挂载光盘

  • 插入光盘
  • 执行以下命令
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# ls /mnt/
addons  EULA              GPL     isolinux  media.repo  repodata                 RPM-GPG-KEY-redhat-release
EFI     extra_files.json  images  LiveOS    Packages    RPM-GPG-KEY-redhat-beta  TRANS.TBL

5. yum的原理

yum的工作需要两部分来合作,一部分是yum服务器,另一部分就是client的yum工具。下面分别介绍两部分工作原理。

  • yum服务器端工作原理

所有要发行的rpm包都放在yum服务器上以提供别人来下载,rpm包根据kernel的版本号,cpu的版本号分别编译发布。yum服务器只要提供简单的下载就可以了,ftp或者http的形式都可以。yum服务器有一个最重要的环节就是整理出每个rpm包的基本信息,包括rpm包对应的版本号、conf文件、binary信息,以及很关键的依赖信息。在yum服务器上提供了createrepo工具,用于把rpm包的基本概要信息做成一张“清单”,这张“清单”就是描述每个rpm包的spec文件中信息。

  • client端工作原理

client每次调用yum install或者search的时候,都会去解析/etc/yum.repos.d下面所有以.repo结尾的配置文件,这些配置文件指定了yum服务器的地址。yum会定期去更新yum服务器上的rpm包清单,然后把清单下载保存到yum客户端自己的cache里面,根据/etc/yum.conf里配置(默认是/var/cache/yum下面),每次调用yum装包的时候都会去这个cache目录下去找清单,根据清单里的rpm包描述从而来确定安装包的名字、版本号、所需要的依赖包等,然后再去yum服务器下载rpm安装。(前提是不存在rpm包的cache)

6. yum的元数据

  • 存放位置(repodata目录)
  • 包含的文件及其对应的功能
    • primary.xml.gz
      • 当前仓库所有rpm包的列表;
      • 依赖关系;
      • 每个rpm包安装生成的文件列表
    • filelists.xml.gz
      • 当前仓库所有rpm包的所有文件列表
    • other.xml.gz 额外信息,rpm包的修改日志
    • repomd.xml
      • 记录的是primary.xml.gz、filelists.xml.gz、other.xml.gz这三个文件的时间戳和校验和
    • comps*.xml
      • rpm包分组信息

7. yum的配置文件

  • 配置文件有哪些:

    • /etc/yum.conf 作用:为所有仓库提供公共配置
    • /etc/yum.repos.d/*.repo 作用:为仓库的指向提供配置
  • yum的repo配置文件中可用的变量:

    • $releaseversion:当前OS的发行版的主版本号
    • $arch:平台类型
    • $basearch:基础平台
  • 为yum定义repo文件:

[Repo_Name]:仓库名称
name:描述信息
baseurl:仓库的具体路径,接受以下三种类型
    ftp://
    http://
    file:///
enabled:可选值{1|0},1为启用此仓库,0为禁用此仓库
gpgcheck:可选值{1|0},1为检查软件包来源合法性,0为不检查来源
    如果gpgcheck设为1,则必须用gpgkey定义密钥文件的具体路径
    gpgkey=/PATH/TO/KEY
vim /etc/yum.conf
cachedir=/var/cache/yum/$basearch/$releasever   //缓存目录
keepcache=0     //缓存软件包, 1启动 0 关闭
debuglevel=2    //调试级别
logfile=/var/log/yum.log    //日志记录位置
exactarch=1     //检查平台是否兼容
obsoletes=1     //检查包是否废弃
gpgcheck=1      //检查来源是否合法,需要有制作者的公钥信息
plugins=1       //是否启用插件
tolerant={1|0}  //容错功能,1为开启,0为关闭,当设为0时,如果用yum安装多个软件包且其中某个软件包已经安装过就会报错;当设为1时,当要安装的软件已经安装时自动忽略
installonly_limit=5
bugtracker_url
# metadata_expire=90m //每小时手动检查元数据
# in /etc/yum.repos.d   //包含repos.d目录 

8. yum仓库管理

8.1 yum本地仓库

  • 挂载光盘
[root@localhost ~]# mount /dev/sr0 /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# ls /mnt/
addons  EULA              GPL     isolinux  media.repo  repodata                 RPM-GPG-KEY-redhat-release
EFI     extra_files.json  images  LiveOS    Packages    RPM-GPG-KEY-redhat-beta  TRANS.TBL

  • 复制光盘内容到yum服务器
[root@localhost ~]# mkdir /opt/myrepo
[root@localhost ~]# cp -r /mnt/* /opt/myrepo
[root@localhost ~]# ls /opt/myrepo
addons  EULA              GPL     isolinux  media.repo  repodata                 RPM-GPG-KEY-redhat-release
EFI     extra_files.json  images  LiveOS    Packages    RPM-GPG-KEY-redhat-beta  TRANS.TBL

  • 配置repo文件
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# ls
[root@localhost yum.repos.d]# touch yum.repos.d
[root@localhost yum.repos.d]# ls
yum.repos.d
[root@localhost yum.repos.d]# vi /etc/yum.repos.d/myrepo.repo
[root@localhost yum.repos.d]# cat /etc/yum.repos.d/myrepo.repo
[xx]
name=x
baseurl=file:///opt/myrepo
gpgcheck=0
enabl=1

  • 清空yum本地缓存
[root@localhost ~]# yum clean all
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在清理软件源: xx
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos
[root@localhost ~]# 

  • 检验yum本地仓库
[root@localhost ~]# yum list all
...
yum-langpacks.noarch                                                   0.4.2-7.el7                                          xx           
yum-plugin-aliases.noarch                                              1.1.31-42.el7                                        xx           
yum-plugin-changelog.noarch                                            1.1.31-42.el7                                        xx           
yum-plugin-ovl.noarch                                                  1.1.31-42.el7                                        xx           
yum-plugin-tmprepo.noarch                                              1.1.31-42.el7                                        xx           
yum-plugin-verify.noarch                                               1.1.31-42.el7                                        xx           
yum-plugin-versionlock.noarch                                          1.1.31-42.el7                                        xx           
yum-utils.noarch                                                       1.1.31-42.el7                                        xx           
zenity.x86_64                                                          3.22.0-1.el7                                         xx           
zip.x86_64                                                             3.0-11.el7                                           xx           
zlib.i686                                                              1.2.7-17.el7                                         xx           
zlib-devel.i686                                                        1.2.7-17.el7                                         xx           
zlib-devel.x86_64                                                      1.2.7-17.el7                                         xx           
zsh.x86_64                                                             5.0.2-28.el7                                         xx           
zziplib.i686                                                           0.13.62-5.el7                                        xx           
zziplib.x86_64                                                         0.13.62-5.el7        
...

8.2 yum网络仓库

  • 官方网络yum仓库(国外)
  • 阿里云yum仓库
  • 163yum仓库
  • xx大学yum仓库
  • epel源
    • 实例
[root@localhost ~]# curl -o /etc/yum.repos.d/eprl.repo http://mirrors.aliyun.com/repo/epel-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   664  100   664    0     0   3796      0 --:--:-- --:--:-- --:--:--  3816
[root@localhost ~]# ls /etc/yum.repos.d/eprl.repo
/etc/yum.repos.d/eprl.repo
[root@localhost ~]# cat /etc/yum.repos.d/eprl.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
 
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0

8.3 软件官方仓库

[root@localhost yum.repos.d]# yum list all|grep nginx
pcp-pmda-nginx.x86_64                   3.11.8-7.el7               xx           
[root@localhost yum.repos.d]# vim ngnix.repo
[root@localhost yum.repos.d]# cat ngnix.repo 
[nginx]
name=nginx repo 
baseurl=http://nginx.org/packages/centos/7/$basearch/ 
gpgcheck=0
enabled=1
[root@localhost yum.repos.d]# yum list all|grep nginx

nginx.x86_64                            1:1.16.1-1.el7.ngx         nginx        
nginx-debug.x86_64                      1:1.8.0-1.el7.ngx          nginx        
nginx-debuginfo.x86_64                  1:1.16.1-1.el7.ngx         nginx        
nginx-module-geoip.x86_64               1:1.16.1-1.el7.ngx         nginx        
nginx-module-geoip-debuginfo.x86_64     1:1.16.1-1.el7.ngx         nginx        
nginx-module-image-filter.x86_64        1:1.16.1-1.el7.ngx         nginx        
nginx-module-image-filter-debuginfo.x86_64
                                        1:1.16.1-1.el7.ngx         nginx        
nginx-module-njs.x86_64                 1:1.16.1.0.3.5-1.el7.ngx   nginx        
nginx-module-njs-debuginfo.x86_64       1:1.16.1.0.3.5-1.el7.ngx   nginx        
nginx-module-perl.x86_64                1:1.16.1-1.el7.ngx         nginx        
nginx-module-perl-debuginfo.x86_64      1:1.16.1-1.el7.ngx         nginx        
nginx-module-xslt.x86_64                1:1.16.1-1.el7.ngx         nginx        
nginx-module-xslt-debuginfo.x86_64      1:1.16.1-1.el7.ngx         nginx        
nginx-nr-agent.noarch                   2.0.0-12.el7.ngx           nginx        
pcp-pmda-nginx.x86_64                   3.11.8-7.el7               xx           

8.4 redhat7使用centos7的yum源

1.卸载红帽yum源
[root@localhost ~]# cat /etc/redhat-release 
anaconda-ks.cfg  .bash_logout     .bash_profile    .bashrc          .cshrc           myrepo/          .tcshrc          .viminfo
[root@localhost ~]# cat /etc/redhat-release     //查看版本
Red Hat Enterprise Linux Server release 7.4 (Maipo)
[root@localhost ~]# rpm -e $(rpm -qa|grep yum) --nodeps        /干掉原来系统上的关于yum的文件
[root@localhost ~]# rpm -qa |grep yum
2.删除所有repo相关文件
[root@localhost ~]# rm -rf /etc/yum.conf
[root@localhost ~]# rm -rf /etc/yum.repos.d/
[root@localhost ~]# rm -rf /var/cache/yum/

9. yum管理软件

9.1 yum命令语法

  • 语法:yum [options] [command] [package …]
[root@localhost ~]# yum -y install wget
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在解决依赖关系
--> 正在检查事务
---> 软件包 wget.x86_64.0.1.14-15.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=========================================================================================================================================
 Package                       架构                            版本                                    源                           大小
=========================================================================================================================================
正在安装:
 wget                          x86_64                          1.14-15.el7                             xx                          547 k

事务概要
=========================================================================================================================================
安装  1 软件包

总下载量:547 k
安装大小:2.0 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : wget-1.14-15.el7.x86_64                                                                                              1/1 
xx/productid                                                                                                      | 1.6 kB  00:00:00     
  验证中      : wget-1.14-15.el7.x86_64                                                                                              1/1 

已安装:
  wget.x86_64 0:1.14-15.el7                                                                                                              

完毕!

9.2 常用的options

--nogpgcheck                //如果从网上下载包有时会检查gpgkey,此时可以使用此命令跳过gpgkey的检查
-y                          //自动回答为"yes"
-q                          //静默模式,安装时不输出信息至标准输出
--disablerepo=repoidglob    //临时禁用此处指定的repo
--enablerepo=repoidglob     //临时启用此处指定的repo
--noplugins                 //禁用所有插件

  • 实例:
[root@localhost ~]# yum -y remove wget
安装大小:2.0 M
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在删除    : wget-1.14-15.el7.x86_64                                                                                              1/1 
  验证中      : wget-1.14-15.el7.x86_64                                                                                              1/1 

删除:
  wget.x86_64 0:1.14-15.el7                                                                                                              

完毕!
[root@localhost ~]# yum -y -q install wget
[root@localhost ~]# rpm -qa|grep wget
wget-1.14-15.el7.x86_64


9.3 常用的command

list            //列表
    all         //默认项
    available   //列出仓库中有的,但尚未安装的所有可用的包
    installed   //列出已经安装的包
    updates     //可用的升级

实验:
[root@localhost ~]# yum list all | grep vim
vim-common.x86_64                       2:7.4.160-2.el7            @xx          
vim-enhanced.x86_64                     2:7.4.160-2.el7            @xx          
vim-filesystem.x86_64                   2:7.4.160-2.el7            @xx          
vim-minimal.x86_64                      2:7.4.160-2.el7            @anaconda/7.4
vim-X11.x86_64                          2:7.4.160-2.el7            xx           

[root@localhost ~]# yum list available |grep zip
bzip2.x86_64                              1.0.6-13.el7                        xx
bzip2-devel.i686                          1.0.6-13.el7                        xx
bzip2-devel.x86_64                        1.0.6-13.el7                        xx
bzip2-libs.i686                           1.0.6-13.el7                        xx
libzip.i686                               0.10.1-8.el7                        xx
libzip.x86_64                             0.10.1-8.el7                        xx
perl-Compress-Raw-Bzip2.x86_64            2.061-3.el7                         xx

[root@localhost ~]# yum list insralled
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
错误:没有匹配的软件包可以列出

[root@localhost ~]# yum list undata
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
错误:没有匹配的软件包可以列出




   
clean           //清理缓存
    packages
    headers
    metadata
    dbcache
    all
    
 实验:
 [root@localhost ~]# yum clean all
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在清理软件源: xx
Cleaning up everything
Maybe you want: rm -rf /var/cache/yum, to also free up space taken by orphaned data from disabled or removed repos

 

 
repolist        //显示repo列表及其简要信息
    all
    enabled     //默认项
    disabled
实例:
[root@localhost ~]# yum repolist all
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
源标识                                                           源名称                                                       状态
xx                                                               x                                                            启用: 4,986
repolist: 4,986
[root@localhost ~]# yum repolist enable
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
repolist: 0
[root@localhost ~]# yum repolist disable
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
repolist: 0


install         //安装
    yum install packages [...]
    
update          //升级
    yum update packages [...]
    
update_to       //升级为指定版本

downgrade package1 [package2 ...]   //降级

remove|erase    //卸载

实例:
[root@localhost ~]# yum update
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
No packages marked for update

[root@localhost ~]# yum remove wget 
安装大小:2.0 M
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在删除    : wget-1.14-15.el7.x86_64                                                                                              1/1 
  验证中      : wget-1.14-15.el7.x86_64                                                                                              1/1 

删除:
  wget.x86_64 0:1.14-15.el7                                                                                                              

完毕!
info    //显示rpm -qi package的结果
    yum info packages
[root@localhost ~]# yum info vsftpd
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
已安装的软件包
名称    :vsftpd
架构    :x86_64
版本    :3.0.2
发布    :22.el7
大小    :348 k
源    :installed
来自源:xx
简介    : Very Secure Ftp Daemon
网址    :https://security.appspot.com/vsftpd.html
协议    : GPLv2 with exceptions
描述    : vsftpd is a Very Secure FTP daemon. It was written completely from
         : scratch.
    
provides|whatprovides   //查看指定的文件或特性是由哪个包安装生成的

[root@localhost ~]# yum provides vsftpd
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
vsftpd-3.0.2-22.el7.x86_64 : Very Secure Ftp Daemon
源    :xx
vsftpd-3.0.2-22.el7.x86_64 : Very Secure Ftp Daemon
源    :@xx

[root@localhost ~]# yum provides *bin/vim       //查看命令
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
2:vim-enhanced-7.4.160-2.el7.x86_64 : A version of the VIM editor which includes recent enhancements
源    :xx
匹配来源:
文件名    :/usr/bin/vim


2:vim-enhanced-7.4.160-2.el7.x86_64 : A version of the VIM editor which includes recent enhancements
源    :@xx
匹配来源:
文件名    :/usr/bin/vim



search string1 [string2 ...]    //以指定的关键字搜索程序包名及summary信息
[root@localhost ~]# yum search httpd
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
========================================================== N/S matched: httpd ===========================================================
keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
python2-keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server

  名称和简介匹配 only,使用“search all”试试。


deplist package [package2 ...]  //显示指定包的依赖关系
[root@localhost ~]# yum deplist vsftpd
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包:vsftpd.x86_64 3.0.2-22.el7
   依赖:/bin/bash
   provider: bash.x86_64 4.2.46-28.el7
   依赖:/bin/sh
   provider: bash.x86_64 4.2.46-28.el7
   依赖:libc.so.6(GLIBC_2.15)(64bit)
   provider: glibc.x86_64 2.17-196.el7
   依赖:libcap.so.2()(64bit)
   provider: libcap.x86_64 2.22-9.el7
   依赖:libcrypto.so.10()(64bit)
   provider: openssl-libs.x86_64 1:1.0.2k-8.el7
    ......

history     //查看yum的历史事务信息
[root@localhost ~]# yum history
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ID     | 登录用户                 | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
    10 | root <root>              | 2019-09-28 19:09 | Install        |    1   
     9 | root <root>              | 2019-09-28 19:03 | Erase          |    1   
     8 | root <root>              | 2019-09-28 18:45 | Install        |    1   
     7 | root <root>              | 2019-09-28 18:39 | Install        |    1   
     6 | root <root>              | 2019-09-28 15:57 | Erase          |    1   
     5 | root <root>              | 2019-09-28 15:55 | Install        |    1   
     4 | root <root>              | 2019-09-28 15:55 | Erase          |    1   
     3 | root <root>              | 2019-09-28 15:50 | Install        |   31   
     2 | root <root>              | 2019-09-28 15:50 | Install        |    1   
     1 | 系统 <空>                | 2019-09-28 15:06 | Install        |  340   
history list


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

grouplist       //列出可用的组
[root@localhost ~]# yum grouplist
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
没有安装组信息文件
Maybe run: yum groups mark convert (see man yum)
可用的环境分组:
   最小安装
   基础设施服务器
   文件及打印服务器
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
可用组:
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   智能卡支持
   科学记数法支持
   系统管理
   系统管理工具
完成




groupinstall "group name"   //安装一组软件


        
createrepo命令    //创建yum仓库的元数据信息
[root@localhost ~]# yum install createrepo -y
[root@localhost ~]# createrepo [options] <directory>



[root@localhost ~]# yum makecache
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
xx                                                                                                                | 4.1 kB  00:00:00     
(1/4): xx/group_gz                                                                                                | 137 kB  00:00:00     
(2/4): xx/primary_db                                                                                              | 4.0 MB  00:00:00     
(3/4): xx/other_db                                                                                                | 1.5 MB  00:00:00     
(4/4): xx/filelists_db                                                                                            | 3.4 MB  00:00:00     
元数据缓存已建立

9.4 具体实例

9.4.1 搜索软件包
//列出软件仓库中可用的软件
[root@localhost ~]# yum list all


//进行模糊查找
[root@localhost ~]# yum list all|grep xz
xz.x86_64                               5.2.2-1.el7                @anaconda/7.4
xz-libs.x86_64                          5.2.2-1.el7                @anaconda/7.4
xz-devel.i686                           5.2.2-1.el7                xx           
xz-devel.x86_64                         5.2.2-1.el7                xx           
xz-libs.i686                            5.2.2-1.el7                xx     


//列出软件包详情
[root@localhost ~]# yum info vsftpd
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
已安装的软件包
名称    :vsftpd
架构    :x86_64
版本    :3.0.2
发布    :22.el7
大小    :348 k
源    :installed
来自源:xx
简介    : Very Secure Ftp Daemon
网址    :https://security.appspot.com/vsftpd.html
协议    : GPLv2 with exceptions
描述    : vsftpd is a Very Secure FTP daemon. It was written completely from
         : scratch.

9.4.2 安装软件包
//安装软件只需要给出软件名称
[root@localhost ~]# rpm -qa |grep wget
[root@localhost ~]# 
[root@localhost ~]# yum -q -y install wget
[root@localhost ~]# rpm -qa |grep wget
wget-1.14-15.el7.x86_64


//安装网络上面rpm的包
[root@localhost ~]# yum install http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
zabbix-release-3.4-2.el7.noarch.rpm                                                                               |  13 kB  00:00:17     
正在检查 /var/tmp/yum-root-bGfDyq/zabbix-release-3.4-2.el7.noarch.rpm: zabbix-release-3.4-2.el7.noarch
/var/tmp/yum-root-bGfDyq/zabbix-release-3.4-2.el7.noarch.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 zabbix-release.noarch.0.3.4-2.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

=========================================================================================================================================
 Package                        架构                   版本                       源                                                大小
=========================================================================================================================================
正在安装:
 zabbix-release                 noarch                 3.4-2.el7                  /zabbix-release-3.4-2.el7.noarch                  21 k

事务概要
=========================================================================================================================================
安装  1 软件包

总计:21 k
安装大小:21 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : zabbix-release-3.4-2.el7.noarch                                                                                      1/1 
  验证中      : zabbix-release-3.4-2.el7.noarch                                                                                      1/1 

已安装:
  zabbix-release.noarch 0:3.4-2.el7                                                                                                      

完毕!

9.4.3 重装软件包
[root@localhost ~]# rpm -q vsftpd
vsftpd-3.0.2-22.el7.x86_64
[root@localhost ~]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
[root@localhost ~]# rm -f /etc/logrotate.d/vsftpd 
[root@localhost ~]# yum reinstall vsftpd
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在解决依赖关系
--> 正在检查事务
---> 软件包 vsftpd.x86_64.0.3.0.2-22.el7 将被 已重新安装
--> 解决依赖关系完成

依赖关系解决

=========================================================================================================================================
 Package                         架构                            版本                                  源                           大小
=========================================================================================================================================
重新安装:
 vsftpd                          x86_64                          3.0.2-22.el7                          xx                          169 k

事务概要
=========================================================================================================================================
重新安装  1 软件包

总下载量:169 k
安装大小:348 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : vsftpd-3.0.2-22.el7.x86_64                                                                                           1/1 
  验证中      : vsftpd-3.0.2-22.el7.x86_64                                                                                           1/1 

已安装:
  vsftpd.x86_64 0:3.0.2-22.el7                                                                                                           

完毕!
[root@localhost ~]# rpm -qc vsftpd
/etc/logrotate.d/vsftpd
/etc/pam.d/vsftpd
/etc/vsftpd/ftpusers
/etc/vsftpd/user_list
/etc/vsftpd/vsftpd.conf
[root@localhost ~]# 

9.4.4 更新软件包
//对比Linux已安装的软件和yum仓库中的软件, 有哪些需要升级
[root@localhost ~]# yum check-update
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.

//不指定升级所有的包,指定升级对应的包
[root@localhost ~]# yum update
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
No packages marked for update

9.4.5 删除软件包
[root@localhost ~]# yum remove vsftpd
  验证中      : vsftpd-3.0.2-22.el7.x86_64                                                                                           1/1 

删除:
  vsftpd.x86_64 0:3.0.2-22.el7                                                                                                           

完毕!
[root@localhost ~]# rpm -q vsftpd
未安装软件包 vsftpd 

9.4.6 与仓库相关的命令
//列出yum源可用的软件仓库
[root@localhost ~]# yum repolist

//列出全部yum源可用和禁用的仓库
[root@localhost ~]# yum repolist all

//查看这个文件或命令属于哪个包
[root@localhost ~]# yum provides /etc/my.cnf
[root@localhost ~]# yum provides cd
[root@localhost ~]# yum provides *bin/pstree
9.4.7 与缓存相关的命令
//缓存yum源软件仓库, xml元数据文件
[root@localhost ~]# yum makecache

//缓存软件包, 修改yum全局配置文件
[root@localhost ~]# vim /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1 //启动缓存


//查看缓存的xml文件
[root@localhost ~]# ls /var/cache/yum/x86_64/7/base/

//查看缓存软件包路径
[root@localhost ~]# ls /var/cache/yum/x86_64/7/


#另一种缓存rpm包方式

//1.安装插件支持只下载软件包不安装
[root@localhost ~]# yum -y install yum-plugin-downloadonly
//2.将软件下载至指定目录
[root@localhost ~]# yum -y install --downloadonly --downloaddir=/tmp httpd


//清除所有yum缓存
[root@localhost ~]# yum clean all

//只清除缓存的软件包
[root@localhost ~]# yum clean packages
9.4.8 与包组相关的命令
//列出已经安装和所有可使用的软件组
[root@localhost ~]# yum groups list

//安装一整个组的软件
[root@localhost ~]# yum groups install Development tools \
Compatibility libraries \
Base Debugging Tools

//yum删除包组
[root@localhost ~]# yum groups remove  -y Base
9.4.9 与历史记录相关的命令
//查看历史执行yum命令
[root@localhost ~]# yum history

//查询历史执行yum命令ID详细信息
[root@localhost ~]# yum history info N

//撤销历史执行过的yum命令
[root@localhost ~]# yum history undo N
9.4.10 YUM签名检查机制
  • rpm软件提供组织redhat在构建rpm包时, 使用其私钥private key对 rpm进行签名

  • 客户端在使用rpm为了验证其合法性, 可以使用redhat提供的公钥public key进行签名检查

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值