yum工具的使用

1. rpm的弊端

rpm的弊端:对于有依赖关系的软件,必须先安装依赖的软件才能继续安装所需要的安装软件。当依赖关系复杂的情况下,rpm这种安装方式就解决不了这种复杂的依赖关系。所以,就需要用到安装管理工具----yum

2. yum的优劣势

  • 优势 :能够解决rpm的依赖问题,yum能够自动解决软件安装时的依赖关系。
  • 劣势 :如果在未完成安装的情况下强行终止安装过程,下次再安装时将无法解决依赖关系,Fedora22+、Redhat7和centos7等可以通过手动安装dnf工具来解决问题。
  • dnf : 是Redhat7上用来代替yum的一个工具,其存在的意义就是处理yum的缺陷,但其用法与yum完全相同,并且连选项都是一样的。

3. yum介绍及其作用

  • yum:yellowdog update manage,能够实现rpm管理的所有操作,并能够自动解决各rpm包之间的依赖关系。
  • yum的作用:yum是rpm的前端工具,是基于rpm来实现软件的管理的一个工具,并且yum只能用来管理Redhat系列的rpm包

4. 挂载光盘

  • 插入光盘
  • 执行以下命令
//df命令查看文件系统磁盘空间使用情况,主要查看挂载点
[root@lishan ~]# df -l
文件系统                 1K-块   已用     可用 已用% 挂载点
/dev/mapper/rhel-root 17811456 986748 16824708    6% /
devtmpfs                922444      0   922444    0% /dev
tmpfs                   933512      0   933512    0% /dev/shm
tmpfs                   933512   8796   924716    1% /run
tmpfs                   933512      0   933512    0% /sys/fs/cgroup
/dev/sda1              1038336 145856   892480   15% /boot
tmpfs                   186704      0   186704    0% /run/user/0
//挂载光盘
[root@lishan ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@lishan ~]# df -l
文件系统                 1K-块    已用     可用 已用% 挂载点
/dev/mapper/rhel-root 17811456  986748 16824708    6% /
devtmpfs                922444       0   922444    0% /dev
tmpfs                   933512       0   933512    0% /dev/shm
tmpfs                   933512    8796   924716    1% /run
tmpfs                   933512       0   933512    0% /sys/fs/cgroup
/dev/sda1              1038336  145856   892480   15% /boot
tmpfs                   186704       0   186704    0% /run/user/0
/dev/sr0               3963760 3963760        0  100% /mnt

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目录)
[root@lishan ~]# ls /mnt/
addons            images      repodata
EFI               isolinux    RPM-GPG-KEY-redhat-beta
EULA              LiveOS      RPM-GPG-KEY-redhat-release
extra_files.json  media.repo  TRANS.TBL
GPL               Packages
[root@lishan ~]# ls /mnt/repodata/
1b9191ed6b5ecb203c1389ea4f4600b7193181d6df34dab911c5a5346a984c1a-filelists.sqlite.bz2
35b2bd4d785b1be1a4aa6ac9a2c89903f20a6e4fc428af1fdac6e4df3bd75048-primary.sqlite.bz2
3f31bf72f167013b227a85cb62a1f3eee9dea359a555a021a01168756107bfc1-other.xml.gz
764ce0e938d43b3e9cb1bcca13cf71630aac0c44149f4a61548f642df3c70858-comps-Server.x86_64.xml
9c36ffa7133f0a1d973e3f4a323fae9cdf9463d5a7eec37fbf3e3824ffd9c78c-comps-Server.x86_64.xml.gz
9fb5a96fb9a423077885ddc5a3eb1e426fe7f4db94e2f3374273ce4267f4a05b-other.sqlite.bz2
a5d74c9954ba24288d9b7e80c6124b7d7f57f760de81763c25022384078d290e-primary.xml.gz
bc7372b8befa9b51b26a8a998ca89b5be3e5636e30546b1e3f11d198d7bed64d-productid.gz
ede8785c6e153158d875d159c7c82b08198939d9ac28caeed6c194b7119a250b-filelists.xml.gz
productid
repomd.xml
TRANS.TBL
  • 包含的文件及其对应的功能
    • primary.xml.gz
      • 当前仓库所有rpm包的列表
      • 依赖关系
      • 每个rpm包安装生成的文件列表
    • filelists.xml.gz
      • 当前仓库所有rpm包的所有文件列表
    • other.xml.gz
      • 额外信息,rpm包的修改日志
    • repond.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 : 基础平台
//查看版本号
[root@lishan ~]# cat /etc/redhat-release 
Red Hat Enterprise Linux Server release 7.4 (Maipo)

为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本地仓库

  • 挂在光盘
  • 复制光盘内容到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 ~]# ls /etc/yum.repos.d/
redhat.repo
[root@localhost ~]# vim /etc/yum.repos.d/myrepo.repo
[root@localhost ~]# cat /etc/yum.repos.d/myrepo.repo
[myrepo]
name=myrepo
baseurl=file:///opt/myrepo
gpgcheck=0
enabled=1
[root@localhost ~]#
  • 清空本地缓存
[root@localhost ~]# yum clean all
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Cleaning repos: myrepo
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
  • 检验yum本地仓库
[root@localhost ~]# yum list all
......
plymouth-core-libs.i686                                                      0.8.9-0.28.20140113.el7                                     myrepo
plymouth-graphics-libs.i686                                                  0.8.9-0.28.20140113.el7                                     myrepo
policycoreutils-devel.i686                                                   2.5-17.1.el7                                                myrepo
policycoreutils-devel.x86_64                                                 2.5-17.1.el7                                                myrepo
policycoreutils-gui.x86_64                                                   2.5-17.1.el7                                                myrepo
policycoreutils-newrole.x86_64                                               2.5-17.1.el7                                                myrepo
policycoreutils-sandbox.x86_64                                               2.5-17.1.el7                                                myrepo
polkit.i686                                                                  0.112-12.el7_3                                              myrepo
polkit-devel.i686                                                            0.112-12.el7_3                                              myrepo
polkit-devel.x86_64                                                          0.112-12.el7_3                                              myrepo
polkit-docs.noarch                                                           0.112-12.el7_3                                              myrepo

8.2 yum网络仓库

  • 官方网络yum仓库(国外)
  • 阿里云yum仓库
  • 163yum仓库
  • epel源
// Base/Extras/Updates: 默认国外官方源
[root@localhost ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo \
http://mirrors.aliyun.com/repo/Centos-7.repo

//国外epel源
[root@localhost ~]# yum -y install epel-release

//阿里云epel源
[root@localhost ~]# curl -o /etc/yum.repos.d/epel.repo \
http://mirrors.aliyun.com/repo/epel-7.repo
//安装网络仓库
[root@lishan ~]# curl -o /etc/yum.repos.d/epel.repo \
> http://mirrors.aliyun.com/repo/epel-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--  100   664  100   664    0     0   4771      0 --:--:-- --:--:-- --:--:--  4811
[root@lishan ~]# ls /etc/yum.repos.d
epel.repo  redhat.repo  wlck.repo

8.3 软件官方仓库

// 源查找方式基本一致,zabbix,mysql,saltstack,openstack等等,上官网找
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo 
baseurl=http://nginx.org/packages/centos/7/$basearch/ 
gpgcheck=0
enabled=1

8.4 Redhat7使用centos7的yum源

1.卸载红帽yum源
[root@localhost ~]# rpm -e $(rpm -qa|grep yum) --nodeps

2.删除所有repo相关文件
[root@localhost ~]# rm -f /etc/yum.conf
[root@localhost ~]# rm -rf /etc/yum.repos.d/
[root@localhost ~]# rm -rf /var/cache/yum

3.下载centos相关yum组件
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-50.el7.noarch.rpm
[root@localhost ~]# wget http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm

//如果没有wget命令则使用curl命令
[root@localhost ~]# curl -o yum-utils-1.1.31-50.el7.noarch.rpm  http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-utils-1.1.31-50.el7.noarch.rpm
[root@localhost ~]# curl -o yum-3.4.3-161.el7.centos.noarch.rpm  http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-3.4.3-161.el7.centos.noarch.rpm
[root@localhost ~]# curl -o yum-metadata-parser-1.1.4-10.el7.x86_64.rpm  http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost ~]# curl -o yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm   http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm
[root@localhost ~]# curl -o yum-updateonboot-1.1.31-50.el7.noarch.rpm http://mirror.centos.org/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-50.el7.noarch.rpm

4安装所有相关组件
[root@localhost ~]# rpm -ivh yum-* --nodeps

5.下载base和epel仓库
[root@localhost ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@localhost ~]# sed -i 's#\$releasever#7#g' /etc/yum.repos.d/CentOS-Base.repo

[root@localhost ~]# wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

9. yum管理软件

9.1 yum命令语法:

yum [options] [command] [package ...](package包可省略)

9.2 常用的options:

--nogpgcheck                //如果从网上下载包有时会检查gpgkey,此时可以使用此命令跳过gpgkey的检查
-y                          //自动回答为"yes"
Is this ok [y/d/N]: 
//在下载安装包是不加-y会出现上诉选择(n是取消,d是download:下载下来但是不安装,并且指定路径才会下载)
     -q                //静默模式,安装时不输出信息至标准输出
//加-q不输出任何信息安装
[root@lishan ~]# yum -q -y install vsftpd 
警告:/var/cache/yum/x86_64/$releasever/base/packages/vsftpd-3.0.2-25.el7.x86_64.rpm: 头V3 RSA/SHA256 Signature, 密钥 ID f4a80eb5: NOKEY
vsftpd-3.0.2-25.el7.x86_64.rpm 的公钥尚未安装
导入 GPG key 0xF4A80EB5:
 用户ID     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 指纹       : 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 来自       : http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[root@lishan ~]# rpm -qa|grep vsftpd 
vsftpd-3.0.2-25.el7.x86_64

--disablerepo=repoidglob    //临时禁用此处指定的repo
--enablerepo=repoidglob     //临时启用此处指定的repo
--noplugins                 //禁用所有插件

9.3 常用的command:

1. list            //列表
		all         //默认项
  	available   //列出仓库中有的,但尚未安装的所有可用的包
		installed   //列出已经安装的包
		updates     //可用的升级
//列出可用,还没有安装的包
[root@lishan ~]# rpm -qa | grep nginx
[root@lishan ~]# yum list available | grep nginx
collectd-nginx.x86_64                    5.8.1-1.el7                     epel   
munin-nginx.noarch                       2.0.49-3.el7                    epel   
nextcloud-nginx.noarch                   10.0.4-2.el7                    epel   
nginx.x86_64                             1:1.12.2-3.el7                  epel   
nginx-all-modules.noarch                 1:1.12.2-3.el7                  epel   
nginx-filesystem.noarch                  1:1.12.2-3.el7                  epel   
nginx-mod-http-geoip.x86_64              1:1.12.2-3.el7                  epel   
nginx-mod-http-image-filter.x86_64       1:1.12.2-3.el7                  epel   
nginx-mod-http-perl.x86_64               1:1.12.2-3.el7                  epel   
nginx-mod-http-xslt-filter.x86_64        1:1.12.2-3.el7                  epel   
nginx-mod-mail.x86_64                    1:1.12.2-3.el7                  epel   
nginx-mod-stream.x86_64                  1:1.12.2-3.el7                  epel   
owncloud-nginx.noarch                    9.1.5-1.el7                     epel   
pcp-pmda-nginx.x86_64                    4.3.2-2.el7                     base   
python2-certbot-nginx.noarch             0.38.0-1.el7                    epel   
sympa-nginx.x86_64                       6.2.44-3.el7                    epel   
//显示已经安装的包
[root@lishan ~]# yum list installed | grep vim 
vim-common.x86_64                       2:7.4.629-6.el7            @wlck        
vim-enhanced.x86_64                     2:7.4.629-6.el7            @wlck        
vim-filesystem.x86_64                   2:7.4.629-6.el7            @wlck        
vim-minimal.x86_64                      2:7.4.160-2.el7            @anaconda/7.4
//列出可以更新的包
[root@lishan ~]# yum list updates
2. clean           //清理缓存
		packages       //包
		headers         //头文件
		metadata      //元数据
		dbcache        //数据库的缓存
	 all
[root@lishan ~]# yum clean packages
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-
          : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在清理软件源: base epel extras updates wlck
0 package 文件已移除
3. repolist        //显示repo列表及其简要信息
		all
		enabled     //默认项(处于活跃状态的仓库)
		disabled    (处于不活跃状态的仓库)
//列出所有的仓库
[root@lishan ~]# yum repolist all
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-
          : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识                源名称                                  状态
base/x86_64           CentOS-7 - Base - mirrors.aliyun.com    启用: 10,097
centosplus/x86_64     CentOS-7 - Plus - mirrors.aliyun.com    禁用
contrib/x86_64        CentOS-7 - Contrib - mirrors.aliyun.com 禁用
epel/x86_64           Extra Packages for Enterprise Linux 7 - 启用: 13,415
epel-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - 禁用
epel-source           Extra Packages for Enterprise Linux 7 - 禁用
extras/x86_64         CentOS-7 - Extras - mirrors.aliyun.com  启用:    304
updates/x86_64        CentOS-7 - Updates - mirrors.aliyun.com 启用:    319
wlck                  wlck.repo                               启用: 10,097
repolist: 34,232
4. install         //安装(可同时安装多个包,每个包之间加空格)
		yum install packages [...]

5. update          //升级
		yum update packages [...](指定安装那个包,如果不指定,则升级所有的包)
	update_to       //升级为指定版本

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

7. remove|erase    //卸载

8. info    //显示rpm -qi package的结果(查看某个包的详细信息)
		yum info packages
//查看某个安装好的包的信息
[root@lishan ~]# yum info vsftpd 
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-
          : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装的软件包
名称    :vsftpd
架构    :x86_64
版本    :3.0.2
发布    :25.el7
大小    :353 k
源    :installed
来自源:base
简介    : 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. provides|whatprovides   //查看指定的文件或特性是由哪个包安装生成的
//查看ls命令是由那个包安装生成的
[root@lishan ~]# yum provides *bin/ls(查看命令包含的sbin/bin等)

源    :base
匹配来源:
文件名    :/usr/bin/ls
coreutils-8.22-24.el7.x86_64 : A set of basic GNU tools commonly used in
                             : shell scripts
源    :wlck
匹配来源:
文件名    :/usr/bin/ls
coreutils-8.22-18.el7.x86_64 : A set of basic GNU tools commonly used in
                             : shell scripts
源    :@anaconda/7.4
匹配来源:
文件名    :/usr/bin/ls
//查看配置文件有什么包生成的
yum provides /etc/passwd
10. search string1 [string2 ...]    //以指定的关键字搜索程序包名及summary信息
//用search查找搜索http的包及概要信息
[root@lishan ~]# yum search httpd
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-
          : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
=========================== N/S matched: httpd ===========================
dmlite-apache-httpd.x86_64 : Apache HTTPD frontend for dmlite
iipsrv-httpd-fcgi.noarch : Apache HTTPD files for iipsrv
keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as
                                     : Keycloak client
libmicrohttpd-devel.i686 : Development files for libmicrohttpd
libmicrohttpd-devel.x86_64 : Development files for libmicrohttpd
libmicrohttpd-doc.noarch : Documentation for libmicrohttpd
lighttpd-fastcgi.x86_64 : FastCGI module and spawning helper for lighttpd
                        : and PHP configuration
lighttpd-mod_authn_gssapi.x86_64 : Authentication module for lighttpd that
                                 : uses GSSAPI
lighttpd-mod_authn_mysql.x86_64 : Authentication module for lighttpd that
                                : uses a MySQL database
lighttpd-mod_authn_pam.x86_64 : Authentication module for lighttpd that
                              : uses PAM
lighttpd-mod_geoip.x86_64 : GeoIP module for lighttpd to use for location
                          : lookups
lighttpd-mod_mysql_vhost.x86_64 : Virtual host module for lighttpd that
                                : uses a MySQL database
nextcloud-httpd.noarch : Httpd integration for NextCloud
owncloud-httpd.noarch : Httpd integration for ownCloud
python2-keycloak-httpd-client-install.noarch : Tools to configure Apache
                                             : HTTPD as Keycloak client
radicale-httpd.noarch : httpd config for Radicale
sympa-lighttpd.x86_64 : Sympa with lighttpd
darkhttpd.x86_64 : A secure, lightweight, fast, single-threaded HTTP/1.1
                 : server
httpd.x86_64 : Apache HTTP Server
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-itk.x86_64 : MPM Itk for 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
lighttpd.x86_64 : Lightning fast webserver with light system requirements
mirmon-httpd.noarch : Apache configuration for mirmon
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
opensips-httpd.x86_64 : HTTP transport layer implementation
perl-Test-Fake-HTTPD.noarch : Fake HTTP server module for testing
python2-sphinxcontrib-httpdomain.noarch : Sphinx domain for documenting
                                        : HTTP APIs
sympa-httpd.x86_64 : Sympa with Apache HTTP Server
sysusage-httpd.noarch : Apache configuration for sysusage
thttpd.x86_64 : A tiny, turbo, throttleable lightweight HTTP server
viewvc-httpd-fcgi.noarch : ViewVC configuration for Apache/mod_fcgid
viewvc-httpd-wsgi.noarch : ViewVC configuration for Apache/mod_wsgi
web-assets-httpd.noarch : Web Assets aliases for the Apache HTTP daemon
11. deplist package [package2 ...]  //显示指定包的依赖关系
//查看指定包的依赖关系
[root@lishan ~]# yum deplist vsftpd 
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-
          : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
软件包:vsftpd.x86_64 3.0.2-25.el7
   依赖:/bin/bash
   provider: bash.x86_64 4.2.46-33.el7
   依赖:/bin/sh
   provider: bash.x86_64 4.2.46-33.el7
   依赖:libc.so.6(GLIBC_2.15)(64bit)
   provider: glibc.x86_64 2.17-292.el7
12. history     //查看yum的历史事务信息
//查看操作信息 
[root@lishan ~]# yum history
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-
          : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ID     | 登录用户                 | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
     9 | root <root>              | 2019-09-28 19:47 | Erase          |    8   
     8 | root <root>              | 2019-09-28 19:46 | I, U           |   23   
     7 | root <root>              | 2019-09-28 19:29 | Install        |    1   
     6 | root <root>              | 2019-09-28 19:13 | Erase          |    1   
     5 | root <root>              | 2019-09-28 19:13 | Install        |    1   
     4 | root <root>              | 2019-09-28 18:48 | Erase          |    1   
     3 | root <root>              | 2019-09-28 18:45 | Install        |    1   
     2 | root <root>              | 2019-09-28 18:09 | Install        |   31 P<
     1 | 系统 <空>                | 2019-09-04 00:48 | Install        |  340 > 
history list
13. localinstall    //安装本地rpm包,自动解决依赖关系
	[root@lishan ~]# yum -y localinstall *.rpm
14. grouplist       //列出可用的组
[root@lishan ~]# yum grouplist
已加载插件:fastestmirror, 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)
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
可用的环境分组:
   最小安装
   基础设施服务器
   计算节点
   文件及打印服务器
   Cinnamon 桌面环境
   MATE 桌面环境
   基本网页服务器
   虚拟化主机
   带 GUI 的服务器
   GNOME 桌面
   KDE Plasma Workspaces
   开发及生成工作站
可用组:
   Cinnamon
   Fedora Packager
   Haskell
   MATE
   Milkymist
   TurboGears 应用程序构架
   Xfce
   传统 UNIX 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   教育软件
   智能卡支持
   电子实验室
   科学记数法支持
   系统管理
   系统管理工具
   通用桌面
完成
15. groupinstall "group name"   //安装一组软件(包组里面有空格必须加 “ ” )
  	
16. createrepo命令    //创建yum仓库的元数据信息
17.groups mark install ”组名“ 标记安装(快速安装)

 [root@lishan ~]# yum groups mark install "组名"
18. groups mark remove    //删除安装
//自己搭仓库时,创建仓库的元数据信息
[root@localhost ~]# yum install createrepo -y
[root@localhost ~]# createrepo [options] <directory>
//建立缓存,此时再下载包时就会节约很多时间
[root@lishan ~]# yum makecache
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-
          : manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
、、、、、
http://mirrors.aliyuncs.com/centos/7/updates/x86_64/repodata/6662722d347f4048636e6fe49c2f044bcc5d23f2a8588a721d6d8c54b1346478-other.sqlite.bz2: [Errno 14] curl#7 - "Failed connect to mirrors.aliyuncs.com:80; Connection refused"
正在尝试其它镜像。
(21/21): updates/x86_64/other_db                     | 124 kB   00:00     
元数据缓存已建立

9.4 具体实例

9.4.1 搜索软件包

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

//进行模糊查找
[root@localhost ~]# yum list|grep ftp

//列出软件包详情
[root@localhost ~]# yum info ftp

9.4.2 安装软件包

//安装软件只需要给出软件名称
[root@localhost ~]# yum install traceroute

//安装过程中分析依赖关系后, 直接安装, 无需交互
[root@localhost ~]# yum -y install php

//安装本地的rpm包, 如果有依赖关系, 会自动从软件仓库中下载所需依赖(非来自.repo定义的软件仓库)
[root@localhost ~]# yum localinstall /mnt/Packages/bind-9.9.4-50.el7.x86_64.rpm

//安装网络上rpm包
[root@localhost ~]# yum install http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-release-3.4-2.el7.noarch.rpm

9.4.3 重装软件包

//检查软件是否存在
[root@localhost ~]# rpm -q vsftpd
vsftpd-2.2.2-24.el6.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

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

9.4.4 更新软件包

//对比Linux已安装的软件和yum仓库中的软件, 有哪些需要升级
[root@localhost ~]# yum check-update

//更新软件
[root@localhost ~]#  yum update acl -y

9.4.5 删除软件包

//先安装一个samba软件
[root@localhost ~]# yum -y install samba

//删除该软件包,不会删除依赖, 但是我们尽可能不要使用删除软件操作
[root@localhost ~]# yum -y erase samba
[root@localhost ~]# yum -y remove samba

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进行签名检查
    方式一:指定公钥位置
[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra #baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

方式二:提前导入公钥

[root@localhost ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
[root@localhost ~]# vim /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base 
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1

方式三:不进行签名验证

//不检查软件包的签名
[root@localhost ~]# yum install httpd --nogpgcheck

作业

  1. 如何配置本地光盘yum仓库以及网络yum仓库
    ①在虚拟机设置里加载光盘
    ②挂载光盘
    ③挂载完后在/mnt目录下,有一个packages和repodate目录(packages下是光盘中所有可以安装的rpm包,repodate下是这些rpm包的元数据信息)
    ④vi /etc/yum.repos.d/CentOS-Base.repo
[wlck]
name=wlck.repo
baseurl=http://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
enabled=1

⑤清空缓存(yum clean all)
⑥加载新yum源缓存(yum makecache)
⑦验证是否配置成功 (yum repolist)

配置网络仓库

[root@lishan ~]# curl -o /etc/yum.repos.d/epel.repo \
> http://mirrors.aliyun.com/repo/epel-7.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--  100   664  100   664    0     0   4771      0 --:--:-- --:--:-- --:--:--  4811
[root@lishan ~]# ls /etc/yum.repos.d
epel.repo  redhat.repo  wlck.repo
  1. 如何使用yum安装 httpd php nginx

yum -y install httpd php nginx

  1. 如何配置yum缓存rpm包(至少阐述两种方式)
//缓存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
  1. 如何使用yum安装本地缓存好的rpm包
  2. 如何使用yum删除httpd软件包
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值