yum工具的使用

文章目录

  • 本章节目标
  • rpm的弊端
  • yum的优劣势
  • 什么是yum及其作用
  • 挂载光盘
  • yum的原理
    • yum服务器端工作原理
    • client端工作原理
  • yum的元数据
  • yum的配置文件
  • yum仓库管理
    • yum本地仓库
    • 配置yum网络仓库
    • 软件官方仓库
    • redhat7使用centos7的yum源
  • yum管理软件
    • yum命令语法:
  • 作业
    • 如何配置本地光盘yum仓库以及网络yum仓库
    • 如何使用yum安装 httpd php nginx{nginx源不能下载}
    • 如何配置yum缓存rpm包(至少阐述两种方式)
    • 如何使用yum安装本地缓存好的rpm包
    • 如何使用yum删除httpd软件包
    • 如何构建企业内部yum仓库服务(请写出详细步骤,至少准备两台虚拟机,使用http方式)

本章节目标

  • rpm的弊端
  • yum的优劣势
  • 什么是yum及其作用
  • 挂载光盘
  • yum的原理
  • yum的元数据
  • yum的配置文件
  • yum仓库管理
  • yum管理软件
  • 作业

rpm的弊端

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

yum的优劣势

yum有什么优势呢?yum最大的优势就是能够解决rpm的依赖问题,yum能够自动解决软件安装时的依赖关系。

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

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

什么是yum及其作用

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

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

挂载光盘

  • 插入光盘
  • 执行以下命令
[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# 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

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)

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包分组信息

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目录

yum仓库管理

yum本地仓库

  • 挂载光盘参照本章第四部分
  • 复制光盘内容到yum服务器
  • 配置repo文件
  • 清空yum本地缓存
  • 验证yum本地缓存
[root@localhost ~]# cat /etc/yum.repos.d/wang.repo 
[wang]
name=wang
baseurl=file:///mnt
gpgcheck=0
enabled=1

[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.
正在清理软件源: wang
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 list all
yum-utils.noarch                      1.1.31-42.el7           wang         
zenity.x86_64                         3.22.0-1.el7            wang         
zip.x86_64                            3.0-11.el7              wang         
zlib.i686                             1.2.7-17.el7            wang         
zlib-devel.i686                       1.2.7-17.el7            wang         
zsh.x86_64                            5.0.2-28.el7            wang         
zziplib.i686                          0.13.62-5.el7           wang         
zziplib.x86_64                        0.13.62-5.el7           wang         
[root@localhost ~]# 

配置yum网络仓库

  • 官方网络yum仓库(国外)
  • 阿里云yum仓库
  • 163yum仓库
  • xx大学yum仓库
  • 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@localhost ~]# cat /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo 
baseurl=http://nginx.org/packages/centos/7/$basearch/ 
gpgcheck=0
enabled=1
[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.
正在清理软件源: nginx
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

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

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

4.下载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

yum管理软件

yum命令语法:

yum [options] [command] [package …]

常用的options:

--nogpgcheck     //如果从网上下载包有时会检查gpgkey,此时可以使用此命令跳过gpgkey的检查
-y                          //自动回答为"yes"
-q                          //静默模式,安装时不输出信息至标准输出
--disablerepo=repoidglob    //临时禁用此处指定的repo
--enablerepo=repoidglob     //临时启用此处指定的repo
--noplugins                 //禁用所有插件
[root@localhost ~]# yum install vsftpd
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 ~]# yum -y remove vsftpd
移除  1 软件包

安装大小:348 k
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 ~]# yum -y -q install vsftpd
[root@localhost ~]# rpm -q vsftpd
vsftpd-3.0.2-22.el7.x86_64

常用的command

list            //列表
all         //默认项
available   //列出仓库中有的,但尚未安装的所有可用的包
installed   //列出已经安装的包
updates     //可用的升级 
zenity.x86_64                         3.22.0-1.el7            wang         
zip.x86_64                            3.0-11.el7              wang         
zlib.i686                             1.2.7-17.el7            wang         
zlib-devel.i686                       1.2.7-17.el7            wang         
zsh.x86_64                            5.0.2-28.el7            wang         
zziplib.i686                          0.13.62-5.el7           wang         
zziplib.x86_64                        0.13.62-5.el7           wang 
  269  yum list all
  270  history 
zenity.x86_64                              3.22.0-1.el7                wang
zip.x86_64                                 3.0-11.el7                  wang
zlib.i686                                  1.2.7-17.el7                wang
zlib-devel.i686                            1.2.7-17.el7                wang
zsh.x86_64                                 5.0.2-28.el7                wang
zziplib.i686                               0.13.62-5.el7               wang
zziplib.x86_64                             0.13.62-5.el7               wang
271  yum list available
  272  history 
yum.noarch                          3.4.3-154.el7              @anaconda/7.4
yum-metadata-parser.x86_64          1.1.4-10.el7               @anaconda/7.4
yum-rhn-plugin.noarch               2.0.1-9.el7                @anaconda/7.4
zlib.x86_64                         1.2.7-17.el7               @anaconda/7.4
zlib-devel.x86_64                   1.2.7-17.el7               @wang         
273  yum list installed
  274  history 
[root@localhost ~]# yum list updates
已加载插件: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 ~]#
clean  //清理缓存
packages
headers
metadata
dbcache
all   
[root@localhost ~]# yum clean packages
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在清理软件源: wang
0 package 文件已移除
[root@localhost ~]# yum clean headers
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在清理软件源: wang
0 header 文件已移除
[root@localhost ~]# yum clean metadata
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在清理软件源: wang
3 metadata 文件已移除
2 sqlite 文件已移除
0 metadata 文件已移除
[root@localhost ~]# yum clean dbcache
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在清理软件源: wang
0 sqlite 文件已移除
[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.
正在清理软件源: wang
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.
wang                                                 | 4.1 kB     00:00     
(1/2): wang/group_gz                                   | 137 kB   00:00     
(2/2): wang/primary_db                                 | 4.0 MB   00:00     
源标识                           源名称                          状态
nginx/x86_64                     nginx repo                      禁用
wang                             wang                            启用: 4,986
repolist: 4,986
[root@localhost ~]# 
[root@localhost ~]# yum repolist disabled
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
源标识                                 源名称                               
nginx/x86_64                           nginx repo                           
repolist: 0
install         //安装
    yum install packages [...]
[root@localhost ~]# yum -y install tree
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 tree-1.6.0-10.el7.x86_64 已安装并且是最新版本
无须任何处理
update          //升级
    yum update packages [...]
[root@localhost ~]# yum update tree
已加载插件: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
update_to       //升级为指定版本
downgrade package1 [package2 ...]   //降级
remove|erase    //卸载
[root@localhost ~]# yum remove tree
安装大小:87 k
是否继续?[y/N]:y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在删除    : tree-1.6.0-10.el7.x86_64                                1/1 
  验证中      : tree-1.6.0-10.el7.x86_64                                1/1 

删除:
  tree.x86_64 0:1.6.0-10.el7                                                

完毕!
[root@localhost ~]# rpm -q tree
未安装软件包 tree
info    //显示rpm -qi package的结果
    yum info packages  
[root@localhost ~]# yum info tree
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
可安装的软件包
名称    :tree
架构    :x86_64
版本    :1.6.0
发布    :10.el7
大小    :46 k
源    :wang
简介    : File system tree viewer
网址    :http://mama.indstate.edu/users/ice/tree/
协议    : GPLv2+
描述    : The tree utility recursively displays the contents of directories
         : in a tree-like format.  Tree is basically a UNIX port of the DOS
         : tree utility.
provides|whatprovides   //查看指定的文件或特性是由哪个包安装生成的
[root@localhost ~]# yum provides tree
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
tree-1.6.0-10.el7.x86_64 : File system tree viewer
源    :wang
search string1 [string2 ...]    //以指定的关键字搜索程序包名及summary信息
[root@localhost ~]# yum search ftp
已加载插件: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: ftp =============================
ftp.x86_64 : The standard UNIX FTP (File Transfer Protocol) client
tftp.x86_64 : The client for the Trivial File Transfer Protocol (TFTP)
tftp-server.x86_64 : The server for the Trivial File Transfer Protocol
                   : (TFTP)
vsftpd.x86_64 : Very Secure Ftp Daemon
curl.x86_64 : A utility for getting files from remote servers (FTP, HTTP,
            : and others)
lftp.i686 : A sophisticated file transfer program
lftp.x86_64 : A sophisticated file transfer program
wget.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
  名称和简介匹配 only,使用“search all”试试。
deplist package [package2 ...]  //显示指定包的依赖关系
[root@localhost ~]# yum deplist tree
    已加载插件:product-id, search-disabled-repos, subscription-manager
    This system is not registered with an entitlement server. You can use subscription-manager to register.
    软件包:tree.x86_64 1.6.0-10.el7
       依赖:libc.so.6(GLIBC_2.14)(64bit)
       provider: glibc.x86_64 2.17-196.el7
       依赖:rtld(GNU_HASH)
       provider: glibc.x86_64 2.17-196.el7
       provider: glibc.i686 2.17-196.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     | 登录用户                 | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
    15 | root               | 2019-06-11 23:10 | Erase          |    1   
    14 | root               | 2019-06-11 22:59 | Install        |    1   
    13 | root               | 2019-06-11 22:58 | Erase          |    1   
    12 | root               | 2019-06-11 22:58 | Install        |    1   
    11 | root               | 2019-06-11 22:57 | Erase          |    1
localinstall    //安装本地rpm包,自动解决依赖关系
[root@localhost ~]# yum localinstall /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm 
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
正在检查 /mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm: tree-1.6.0-10.el7.x86_64
/mnt/Packages/tree-1.6.0-10.el7.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 tree.x86_64.0.1.6.0-10.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决
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"   //安装一组软件
列出软件仓库中可用的软件
zlib-devel.i686                        1.2.7-17.el7            wang         
zsh.x86_64                             5.0.2-28.el7            wang         
zziplib.i686                           0.13.62-5.el7           wang         
zziplib.x86_64                         0.13.62-5.el7           wang         
[root@localhost ~]# yum list all
进行模糊查找
[root@localhost ~]# yum list | grep samba
samba.x86_64                            4.6.2-8.el7                wang         
samba-client.x86_64                     4.6.2-8.el7                wang         
samba-client-libs.i686                  4.6.2-8.el7                wang         
samba-client-libs.x86_64                4.6.2-8.el7                wang         
samba-common.noarch                     4.6.2-8.el7                wang         
samba-common-libs.x86_64                4.6.2-8.el7                wang         
samba-common-tools.x86_64               4.6.2-8.el7                wang         
samba-krb5-printing.x86_64              4.6.2-8.el7                wang         
samba-libs.i686                         4.6.2-8.el7                wang         
samba-libs.x86_64                       4.6.2-8.el7                wang         
samba-python.x86_64                     4.6.2-8.el7                wang         
samba-winbind.x86_64                    4.6.2-8.el7                wang         
samba-winbind-clients.x86_64            4.6.2-8.el7                wang         
samba-winbind-modules.i686              4.6.2-8.el7                wang         
samba-winbind-modules.x86_64            4.6.2-8.el7                wang
列出软件包详情
[root@localhost ~]# yum info ftp
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
可安装的软件包
名称    :ftp
架构    :x86_64
版本    :0.17
发布    :67.el7
大小    :61 k
源    :wang
简介    : The standard UNIX FTP (File Transfer Protocol) client
网址    :ftp://ftp.linux.org.uk/pub/linux/Networking/netkit
协议    : BSD with advertising
描述    : The ftp package provides the standard UNIX command-line FTP (File
         : Transfer Protocol) client.  FTP is a widely used protocol for
         : transferring files over the Internet and for archiving files.
         : 
         : If your system is on a network, you should install ftp in order
         : to do file transfers.
重装软件包
[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 -rf /etc/vsftpd/vsftpd.conf 
[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 将被 已重新安装
--> 解决依赖关系完成

依赖关系解决
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 ~]# 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 acl -y
已加载插件: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 ~]# rpm -q vsftpd
vsftpd-3.0.2-22.el7.x86_64
[root@localhost ~]# yum remove vsftpd
[root@localhost ~]# rpm -q vsftpd
未安装软件包 vsftpd
与仓库相关的命令
[root@localhost ~]# yum repolist
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
源标识                              源名称                             状态
wang                                wang                               4,986
repolist: 4,986
[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.
源标识                           源名称                          状态
nginx/x86_64                     nginx repo                      禁用
wang                             wang                            启用: 4,986
repolist: 4,986
[root@localhost ~]# yum repolist /etc/my.cnf
已加载插件: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 cd
已加载插件: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 *bin/pstree
已加载插件: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 makecache
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
wang                                                 | 4.1 kB     00:00     
(1/2): wang/filelists_db                               | 3.4 MB   00:00     
(2/2): wang/other_db                                   | 1.5 MB   00:00     
元数据缓存已建立
[root@localhost ~]# vim /etc/yum.conf 
[root@localhost ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
[root@localhost ~]# ls /var/cache/yum/x86_64/7Server/wang/
1b9191ed6b5ecb203c1389ea4f4600b7193181d6df34dab911c5a5346a984c1a-filelists.sqlite.bz2
35b2bd4d785b1be1a4aa6ac9a2c89903f20a6e4fc428af1fdac6e4df3bd75048-primary.sqlite.bz2
9c36ffa7133f0a1d973e3f4a323fae9cdf9463d5a7eec37fbf3e3824ffd9c78c-comps-Server.x86_64.xml.gz
9fb5a96fb9a423077885ddc5a3eb1e426fe7f4db94e2f3374273ce4267f4a05b-other.sqlite.bz2
bc7372b8befa9b51b26a8a998ca89b5be3e5636e30546b1e3f11d198d7bed64d-productid.gz
cachecookie
gen
packages
repomd.xml
与包相关的命令
[root@localhost ~]# yum groups list
已加载插件: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 兼容性
   兼容性程序库
   图形管理工具
   安全性工具
   开发工具
   控制台互联网工具
   智能卡支持
   科学记数法支持
   系统管理
   系统管理工具
完成
[root@localhost ~]# yum goups install Development tools
  subversion-libs.x86_64 0:1.7.14-10.el7                                   
  systemtap-client.x86_64 0:3.1-3.el7                                      
  systemtap-devel.x86_64 0:3.1-3.el7                                       
  systemtap-runtime.x86_64 0:3.1-3.el7                                     
  trousers.x86_64 0:0.3.14-2.el7                                           
  unzip.x86_64 0:6.0-16.el7                                                
  zip.x86_64 0:3.0-11.el7
完毕!
与历史相关的命令
[root@localhost ~]# yum groups remove -y Base
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
No environment named Base exists
Maybe run: yum groups mark remove (see man yum)
指定组中没有要移除的软件包

作业

如何配置本地光盘yum仓库以及网络yum仓库

[root@localhost ~]# mount /dev/cdrom /mnt
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhost ~]# 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@localhost ~]# cat /etc/yum.repos.d/wang.repo 
[wang]
name=wang
baseurl=file:///mnt
gpgcheck=0
enabled=1

[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.
正在清理软件源: wang
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 list all
yum-utils.noarch                      1.1.31-42.el7           wang         
zenity.x86_64                         3.22.0-1.el7            wang         
zip.x86_64                            3.0-11.el7              wang         
zlib.i686                             1.2.7-17.el7            wang         
zlib-devel.i686                       1.2.7-17.el7            wang         
zsh.x86_64                            5.0.2-28.el7            wang         
zziplib.i686                          0.13.62-5.el7           wang         
zziplib.x86_64                        0.13.62-5.el7           wang         
[root@localhost ~]# yum -y install epel-release

如何使用yum安装 httpd php nginx{nginx源不能下载}

[root@localhost ~]# yum -y install httpd php
已安装:
  php.x86_64 0:5.4.16-42.el7                                               

作为依赖被安装:
  libzip.x86_64 0:0.10.1-8.el7          php-cli.x86_64 0:5.4.16-42.el7    
  php-common.x86_64 0:5.4.16-42.el7    

完毕!
[root@localhost ~]# yum list | grep nginx
pcp-pmda-nginx.x86_64                   3.11.8-7.el7               wang         
[root@localhost ~]# yum -y install httpd php 
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 httpd-2.4.6-67.el7.x86_64 已安装并且是最新版本
软件包 php-5.4.16-42.el7.x86_64 已安装并且是最新版本
无须任何处理

如何配置yum缓存rpm包(至少阐述两种方式)

[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.
wang                                                 | 4.1 kB     00:00     
(1/2): wang/filelists_db                               | 3.4 MB   00:00     
(2/2): wang/other_db                                   | 1.5 MB   00:00     
元数据缓存已建立
[root@localhost ~]# vim /etc/yum.conf 
[root@localhost ~]# cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=1
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=3
[root@localhost ~]# yum -y install yum-plugin-downloadonly
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 yum-3.4.3-154.el7.noarch 已安装并且是最新版本
无须任何处理
[root@localhost ~]# yum -y install --downloadonly --downloaddir=/tmp httpd
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 httpd-2.4.6-67.el7.x86_64 已安装并且是最新版本
无须任何处理

如何使用yum安装本地缓存好的rpm包

[root@localhost ~]# yum -y install tree
Running transaction
  正在安装    : tree-1.6.0-10.el7.x86_64                               1/1 
  验证中      : tree-1.6.0-10.el7.x86_64                               1/1 

已安装:
  tree.x86_64 0:1.6.0-10.el7                                               

完毕!

如何使用yum删除httpd软件包

[root@localhost ~]# rpm -q httpd
httpd-2.4.6-67.el7.x86_64
[root@localhost ~]# yum -y remove httpd
[root@localhost ~]# rpm -q httpd
未安装软件包 httpd

如何构建企业内部yum仓库服务(请写出详细步骤,至少准备两台虚拟机,使用http方式)

[root@localhsot ~]# mkdir /wly
[root@localhsot ~]# mount /dev/sr0 /wly
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhsot ~]# cd /etc/yum.repos.d/
[root@localhsot yum.repos.d]# ls
redhat.repo  wang.repo
[root@localhsot yum.repos.d]# vi wang.repo 
[root@localhsot yum.repos.d]# cat wang.repo 
[wang]
name=wang
baseurl=file:///wly
gpgcheck=0
enabled=1
[root@localhsot yum.repos.d]# 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.
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
正在清理软件源: wang
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@localhsot yum.repos.d]# yum repolist
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
wang                                                 | 4.1 kB     00:00     
(1/2): wang/group_gz                                   | 137 kB   00:00     
(2/2): wang/primary_db                                 | 4.0 MB   00:00     
源标识                              源名称                             状态
wang                                wang                               4,986
repolist: 4,986
[root@localhsot yum.repos.d]# yum -y install httpd
[root@localhsot yum.repos.d]# systemctl start httpd
[root@localhsot yum.repos.d]# systemctl stop firewalld
[root@localhsot yum.repos.d]# ss -antl
State      Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN     0      128        *:22                     *:*                  
LISTEN     0      100    127.0.0.1:25                     *:*                  
LISTEN     0      128       :::80                    :::*                  
LISTEN     0      128       :::22                    :::*                  
LISTEN     0      100      ::1:25                    :::*

yum工具的使用_第1张图片

[root@localhsot yum.repos.d]# mkdir /var/www/html/rhel7.2
[root@localhsot yum.repos.d]# mount /dev/sr0 /var/www/html/rhel7.2/
mount: /dev/sr0 写保护,将以只读方式挂载
[root@localhsot yum.repos.d]# vi /etc/yum.repos.d/wly.repo
[root@localhsot yum.repos.d]# cat /etc/yum.repos.d/wly.repo 
[wly]
name=wly
baseurl=file:///var/www/html/rhel7.2
gpgcheck=0
[root@localhsot yum.repos.d]#

yum工具的使用_第2张图片

你可能感兴趣的:(linux)