1.8 yum工具使用

1.rpm的弊端

rpm有什么弊端呢?

其弊端是显而易见的,当用rpm安装软件时,若遇到有依赖关系的软件,必须先安装依赖的软件才能继续安装我们要安装的软件,当依赖关系很复杂的情况下,这种安装方式就很让人头疼,所以我们需要另一种安装方式来解决这个问题,使用rpm解决

2.yum的优劣势

yum有什么优势呢?

yum最大的优势就是能够解决rpm的依赖问题,yum能够自动解决软件安装时的依赖关系。
yum的缺陷就是如果在未完成安装的情况下强行中止安装过程,下次再安装时将无法解决依赖关系,Fedora22+、redhat7和centos7等可以通过手动安装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/cdrom /mnt
    mount: /dev/sr0 is write-protected, mounting read-only
    [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工具。

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
[root@localhost ~]#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本地仓库

  1. 挂载光盘
  2. 复制光盘内容到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
    
  3. 配置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 ~]#
    
  4. 清空yum本地缓存
    [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
    
  5. 检验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
    polkit-kde.x86_64                                                            0.99.1-4.20130311git.el7                                    myrepo
    polkit-qt.i686                                                               0.103.0-10.el7_0                                            myrepo
    polkit-qt.x86_64                                                             0.103.0-10.el7_0                                            myrepo
    poppler.i686                                                                 0.26.5-16.el7                                               myrepo
    poppler-glib.i686                                                            0.26.5-16.el7                                               myrepo
    poppler-qt.i686                                                              0.26.5-16.el7                                               myrepo
    poppler-qt.x86_64                                                            0.26.5-16.el7                                               myrepo
    popt.i686                                                                    1.13-16.el7                                                 myrepo
    popt-devel.i686                                                              1.13-16.el7                                                 myrepo      
    ......
    

8.2 下载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

8.3 配置软件官方仓库

// 源查找方式基本一致,zabbix,mysql,saltstack,openstack等等,上官网找
[root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
[nginx]
name=nginx repo 
baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/$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 https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-cron-3.4.3-163.el7.centos.noarch.rpm
[root@localhost ~]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost ~]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm
[root@localhost ~]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-52.el7.noarch.rpm
[root@localhost ~]# wget https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-52.el7.noarch.rpm

//如果没有wget命令则使用curl命令
[root@localhost ~]# curl -o yum-utils-1.1.31-50.el7.noarch.rpm  https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-cron-3.4.3-163.el7.centos.noarch.rpm
[root@localhost ~]# curl -o yum-3.4.3-161.el7.centos.noarch.rpm  https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-metadata-parser-1.1.4-10.el7.x86_64.rpm
[root@localhost ~]# curl -o yum-metadata-parser-1.1.4-10.el7.x86_64.rpm  https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-plugin-fastestmirror-1.1.31-52.el7.noarch.rpm
[root@localhost ~]# curl -o yum-plugin-fastestmirror-1.1.31-50.el7.noarch.rpm   https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-updateonboot-1.1.31-52.el7.noarch.rpm
[root@localhost ~]# curl -o yum-updateonboot-1.1.31-50.el7.noarch.rpm https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/yum-utils-1.1.31-52.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

9.yum管理软件

9.1 yum命令语法:

  • yum [options] [command] [package …]

9.2 常用的options:

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

9.3 常用的command:

list            //列表
    all         //默认项
    available   //列出仓库中有的,但尚未安装的所有可用的包
    installed   //列出已经安装的包
    updates     //可用的升级
    
clean           //清理缓存
    packages
    headers
    metadata
    dbcache
    all
    
repolist        //显示repo列表及其简要信息
    all
    enabled     //默认项
    disabled
    
install         //安装
    yum install packages [...]
    
update          //升级
    yum update packages [...]
update_to       //升级为指定版本

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

remove|erase    //卸载

info    //显示rpm -qi package的结果
    yum info packages
    
provides|whatprovides   //查看指定的文件或特性是由哪个包安装生成的

search string1 [string2 ...]    //以指定的关键字搜索程序包名及summary信息

deplist package [package2 ...]  //显示指定包的依赖关系

history     //查看yum的历史事务信息

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

grouplist       //列出可用的组

groupinstall "group name"   //安装一组软件
        
createrepo命令    //创建yum仓库的元数据信息
[root@localhost ~]# yum install createrepo -y
[root@localhost ~]# createrepo [options] <directory>

9.4 具体实例

9.4.1 搜索软件包
  • 命令:yum list all
  • 作用:列出软件仓库中可用的软件
    示例:
    [root@localhost ~]# yum list all
    ......
    zulucrypt.x86_64                                  5.0.1-1.el7                         epel         
    zulucrypt-console.x86_64                          5.0.1-1.el7                         epel         
    zulucrypt-devel.x86_64                            5.0.1-1.el7                         epel         
    zulucrypt-doc.noarch                              5.0.1-1.el7                         epel         
    zulucrypt-libs.x86_64                             5.0.1-1.el7                         epel
    ......
    
  • 命令:yum list|grep ftp
  • 作用:进行模糊查找
    示例:
    [root@localhost ~]# yum list |grep ftp
    curlftpfs.x86_64                         0.9.2-14.el7                    epel   
    edg-gridftp-client.x86_64                1.2.9.2-5.el7                   epel   
    ftp.x86_64                               0.17-67.el7                     base   
    ftplib.x86_64                            4.0-4.el7                       epel   
    ftplib-devel.x86_64                      4.0-4.el7                       epel
    
  • 命令:yum info ftp
  • 作用:列出软件包详情
    [root@localhost ~]# yum info ftp
    已加载插件: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
    可安装的软件包
    名称    :ftp
    架构    :x86_64
    版本    :0.17
    发布    :67.el7
    大小    :61 k
    源    :base/x86_64
    简介    : 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.
    
9.4.2 安装软件包
  • 命令:yum install traceroute
  • 作用:安装软件只需要给出软件名称
    示例:
[root@localhost ~]# yum install traceroute
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager
正在安装:
 traceroute              x86_64              3:2.0.22-2.el7                base               59 k
安装  1 软件包
总下载量:59 k
安装大小:92 k
Is this ok [y/d/N]: y
Downloading packages:
traceroute-2.0.22-2.el7.x86_64.rpm                                          |  59 kB  00:00:05     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : 3:traceroute-2.0.22-2.el7.x86_64                                               1/1 
  验证中      : 3:traceroute-2.0.22-2.el7.x86_64                                               1/1 
已安装:
  traceroute.x86_64 3:2.0.22-2.el7                                                                 
完毕!
  • 命令:yum -y install php
  • 作用:安装过程中分析依赖关系后, 直接安装, 无需交互
    示例:
[root@localhost ~]# yum -y install php
已加载插件:fastestmirror, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
已安装:
  php.x86_64 0:5.4.16-46.el7                                                                       
作为依赖被安装:
  libzip.x86_64 0:0.10.1-8.el7  php-cli.x86_64 0:5.4.16-46.el7  php-common.x86_64 0:5.4.16-46.el7 
完毕!
  • 命令:yum localinstall /mnt/Packages/bind-9.9.4-50.el7.x86_64.rpm
  • 作用:安装本地的rpm包, 如果有依赖关系, 会自动从软件仓库中下载所需依赖(非来自.repo定义的软件仓库)
    示例:
[root@localhost myrepo]# yum localinstall /mnt/Packages/bind-9.9.4-50.el7.x86_64.rpm 
/mnt/Packages/bind-9.9.4-50.el7.x86_64.rpm 将被安装
正在解决依赖关系
--> 正在检查事务
---> 软件包 bind.x86_64.32.9.9.4-50.el7 将被 安装
--> 正在处理依赖关系 bind-libs = 32:9.9.4-50.el7,它被软件包 32:bind-9.9.4-50.el7.x86_64 需要                                                                       | 3.6 kB  00:00:00     
epel                                                                             
(1/9): epel/x86_64/group_gz                                                 |  88 kB  00:00:05     
(2/9): epel/x86_64/updateinfo                                               | 1.0 MB  00:00:05     
......                                           
--> 正在处理依赖关系 libbind9.so.90()(64bit),它被软件包 32:bind-9.9.4-50.el7.x86_64 需要
--> 正在处理依赖关系 libdns.so.100()(64bit),它被软件包 32:bind-9.9.4-50.el7.x86_64 需要
---> 软件包 bind-libs.x86_64.32.9.9.4-50.el7 将被 安装
--> 解决依赖关系完成
Is this ok [y/d/N]: y
  正在安装    : 32:bind-libs-9.9.4-50.el7.x86_64                                               1/2 
  正在安装    : 32:bind-9.9.4-50.el7.x86_64                                                    2/2 
已安装:
  bind.x86_64 32:9.9.4-50.el7                                                                      
作为依赖被安装:
  bind-libs.x86_64 32:9.9.4-50.el7                                                                 
完毕!
  • 命令:yum install [链接地址]
  • 作用:安装网络上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进行签名检查
  • 方式1:指定公钥位置
[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
  • 方式2:提前导入公钥
[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
  • 方式3:不进行签名验证
//不检查软件包的签名
[root@localhost ~]# yum install httpd --nogpgcheck

作业

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

    1. 挂载光盘
      [root@localhost ~]# mount /dev/cdrom /mnt
      mount: /dev/sr0 写保护,将以只读方式挂载
    2. 复制光盘内容到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
    3. 配置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
    4. 清空yum本地缓存
      [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

    2.配置网络仓库

    [root@localhost ~]# vim /etc/yum.repos.d/nginx.repo
    [wlck]
    name=wlck.repo
    baseurl=https://mirrors.aliyun.com/centos/7/os/x86_64/Packages/$basearch/
    gpgcheck=0
    enabled=1

  2. 如何使用yum安装 httpd php nginx

    [root@localhost ~]# yum -y install httpd php nginx
    已安装:
    nginx.x86_64 1:1.12.2-3.el7

    完毕!

  3. 如何配置yum缓存rpm包(至少阐述两种方式)
    1.使用makecache命令,默认缓存到指定位置,通过修改/etc/yum.conf,修改路径

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

    2.通过安装插件downloadonly,下载缓存包到指定目录

    1.安装插件支持只下载软件包不安装
    [root@localhost ~]# yum -y install yum-plugin-downloadonly
    2.将软件下载至指定目录
    [root@localhost ~]# yum -y install --downloadonly --downloaddir=/tmp/ httpd
    正在安装:
    httpd x86_64 2.4.6-90.el7.centos base 2.7 M
    事务概要
    ===================================================================================================
    安装 1 软件包
    总下载量:2.7 M
    安装大小:9.4 M
    Background downloading packages, then exiting:
    httpd-2.4.6-90.el7.centos.x86_64.rpm

  4. 如何使用yum安装本地缓存好的rpm包
    1.使用默认缓存路径中的rpm包

    [root@localhost ~]# yum -y install httpd

    2.使用本地指定目录下的rpm包

    [root@localhost ~]# yum localinstall /tmp/httpd-2.4.6-90.el7.centos.x86_64.rpm

  5. 如何使用yum删除httpd软件包

    [root@localhost ~]# yum -y remove 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.
    正在解决依赖关系
    –> 正在检查事务

    删除:
    httpd.x86_64 0:2.4.6-90.el7.centos
    作为依赖被删除:
    php.x86_64 0:5.4.16-46.el7
    完毕!

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值