yum管理工具
目录
yum管理工具
yum概述
什么是yum
yum也是一种rpm包管理工具,相比于rpm命令,优势是可以自动解决依赖关系
自动解决依赖关系前提条件,你的yum源中要有这些依赖包
举例:
nginx 安装需要依赖 pcre-devel 、 openssl-devel
yum install -y nginx
什么是yum源
yum源:可以理解为手机中的应用商店
yum源其他名称:镜像站,yum仓库,rpm仓库
配置yum源
# 使用阿里云的yum源
http://mirrors.aliyun.com 
# 系统中需要的基础yum源
base源:和镜像中的Linux基础rpm包差不多
epel源:一些扩展安装包
# yum源的配置文件存放目录
[root@zls ~]# ll /etc/yum.repos.d/ 
-rw-r--r-- 1 root root 1759 Jul 5 2021 CentOS-Base.repo 
-rw-r--r-- 1 root root 664 Jul 5 2021 epel.repo 
# 1.删除所有官方yum源
[root@zls ~]# rm -f /etc/yum.repos.d/* 
# 2.安全方式,不使用yum源
[root@zls ~]# gzip -r /etc/yum.repos.d/ 
# 3.下载Base源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo 
[root@zls ~]# ll /etc/yum.repos.d 
-rw-r--r-- 1 root root 2523 Apr 20 23:42 CentOS-Base.repo 
# 4.下载epel源
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo 
[root@zls ~]# ll /etc/yum.repos.d/ 
-rw-r--r-- 1 root root 2523 Apr 20 23:42 CentOS-Base.repo
-rw-r--r-- 1 root root 664 Apr 20 23:48 epel.repo 
# 注意:在/etc/yum.repos.d/目录下所有的yum源配置,必须以.repo结尾
# 安装nginx服务,使用nginx官方yum源
# 1.打开官网 http://nginx.org/ 
# 2.找nginx的yum仓库
# 3.vim /etc/yum.repos.d/nginx.repo 
[nginx-stable] 
name=nginx stable repo 
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/ 
gpgcheck=1 
enabled=1 
gpgkey=https://nginx.org/keys/nginx_signing.key 
module_hotfixes=true 
[nginx-mainline] 
name=nginx mainline repo 
baseurl=http://nginx.org/packages/mainline/centos/$releasever/$basearch/ 
gpgcheck=1 
enabled=0 
gpgkey=https://nginx.org/keys/nginx_signing.key 
module_hotfixes=true
**1.阿里云镜像站:http://mirrors.aliyun.com **
**2.网易镜像站:http://mirrors.163.com/ **
**3.清华源:https://mirrors.tuna.tsinghua.edu.cn **
4.中科大源:https://mirrors.ustc.edu.cn/
**5.华为源:https://mirrors.huaweicloud.com/home **
yum命令实践
yum查询 info provides
# 查看yum仓库中所有可以安装的rpm包 
[root@localhost ~]# yum list 
# 过滤看看yum仓库中是否有wget包 
[root@localhost ~]# yum list|grep wget 
包名 版本和发布次数 这包在哪个仓库中
wget.x86_64 1.14-18.el7_6.1 @base 
# 查看指定包的详细信息 
[root@localhost ~]# yum info wget 
# 查看yum仓库中,所有安装包的详细信息 
[root@localhost ~]# yum info 
# 根据命令查找包 
[root@localhost ~]# yum provides ifconfig 
# 该命令隶属于的包名 
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools 
# 该命令隶属于的仓库 
Repo        : @base 
Matched from: 
# 装完后,命令会在/usr/sbin下叫ifconfig 
Filename : /usr/sbin/ifconfig 
# 根据命令查找属于哪个安装包,最好写命令的绝对路径 
[root@localhost ~]# yum provides */ifconfig 
Loaded plugins: fastestmirror 
Loading mirror speeds from cached hostfile 
 * base: mirrors.aliyun.com 
 * extras: mirrors.aliyun.com 
 * updates: mirrors.aliyun.com 
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools 
Repo        : base 
Matched from: 
Filename    : /sbin/ifconfig 
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools 
Repo        : @base 
Matched from: 
Filename    : /sbin/ifconfig
yum安装 install
# yum安装方式
  -本地安装
  yum localinstall -y 包名 (前提该包已经下载在服务器上了)
  -yum源安装
  yum install -y tree
  -网站安装
  yum install -y http://test.driverzeng.com/Nginx_package/nginx-1.12.2- 3.el7.x86_64.rpm
# 自动解决依赖关系的前提条件,在你的yum源中都要有该软件的依赖包
yum重装 reinstall
yum reinstall -y 包名
# 作用:误删了服务相关的任何一个文件,使用reinstall都可以恢复,但是恢复的是最初始的配置
# reinstall的重装方式,必须与最开始安装这个包的方式保持一致
yum更新 check-update
# 查看当前系统中,有哪些软件是可以更新的
[root@localhost ~]# yum check-update
# 更新指定的软件包
[root@localhost ~]# yum update -y tree
# 更新所有可更新的软件包(不建议怎么做,会更新系统)
[root@localhost ~]# yum update -y
yum卸载 remove
[root@localhost ~]# yum remove -y 包名
[root@localhost ~]# yum erase -y 包名
yum仓库指令 repolist all
# 查看所有源中可用的yum仓库
[root@localhost ~]# yum repolist
仓库名            仓库描述                             仓库状态:多少个包
repo id          repo name                           status
base/7/x86_64    CentOS-7 - Base - mirrors.aliyun.co 10,072
# 查看所有源中所有的yum仓库
[root@localhost ~]# yum repolist all
仓库名                 仓库描述               仓库状态:多少个包
repo id               repo name             status
base/7/x86_64         CentOS-7 - Base - mir enabled: 10,072
# 使用yum-config-manager 
# 1.没有命令,要安装命令
[root@localhost ~]# yum install -y yum-config-manager
No package yum-config-manager available.
Error: Nothing to do
# 2.查询该命令属于哪个包
[root@localhost ~]# yum provides */yum-config-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
yum-utils-1.1.31-54.el7_8.noarch : Utilities based around
                                 : the yum package manager
Repo        : base
Matched from:
Filename    : /usr/bin/yum-config-manager
# 3.安装对应的rpm包
[root@localhost ~]# yum install -y yum-utils
# 修改yum源配置文件,开启或关闭仓库 
# 1.开启 
[root@zls vsftpd]# yum-config-manager --enable nginx-mainline 
# 2.关闭 
[root@zls vsftpd]# yum-config-manager --disable nginx-mainline
yum缓存命令 clean all makecache
# 清楚所有的缓存
[root@localhost ~]# yum clean all
# yum clean packages 
只会清除默认路径下的rpm包
# 加载缓存
[root@localhost ~]# yum makecache
# 默认情况下,yum是不会下载rpm包的,只会安装
# 除非开启下载的配置
vim /etc/yum.conf 
[main] 
cachedir=/var/cache/yum/$basearch/$releasever 
keepcache=0 
# 把0改成1就是开启下载rpm
# 下面是yum下载的默认路径
ll /var/cache/yum/x86_64/7/ 
total 8 
drwxr-xr-x. 4 root root 256 Apr 22 11:31 base 
drwxr-xr-x. 4 root root 4096 Apr 22 11:31 epel 
drwxr-xr-x. 4 root root 161 Apr 22 11:31 extras
-rw-r--r--. 1 root root 118 Apr 22 11:31 timedhosts 
-rw-r--r--. 1 root root 0 Apr 22 11:31 timedhosts.txt 
drwxr-xr-x. 4 root root 161 Apr 22 11:31 updates
# 下载nginx,不安装,并指定目录 
yum install nginx -y --downloadonly --downloaddir=/tmp
--downloadonly:仅下载,不安装 
--downloaddir:指定下载的目录
yum包组管理命令
# 查看有哪些包组可以安装
[root@localhost ~]# yum group list
# 安装包组 
yum groups install 包组名字 
# 卸载包组 
yum groups remove 包组名字
yum历史命令 history
# 查看yum的历史操作
[root@localhost ~]# yum history
Loaded plugins: fastestmirror
命令的ID  命令的执行者                 执行的时间           动作             操作几个包
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    10 | root <root>              | 2022-04-21 10:19 | Install        |    1  <
     9 | root <root>              | 2022-04-20 10:44 | Install        |   31 > 
# 查看某个历史操作的详细信息 
[root@localhost ~]# yum history info ID 
[root@localhost ~]# yum history info 10
# 撤销历史操作:一般撤销更新操作 
[root@localhost ~]# yum history undo ID 
[root@localhost ~]# yum history undo 10
yum仓库配置文件
# 仓库名字
[base] 
# 仓库的描述 
name=CentOS-$releasever - Base - mirrors.aliyun.com 
# 仓库的地址 
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/ 
# 仓库签名检查机制 
gpgcheck=1 
# 仓库开启/关闭 (1:开启,0:关闭,默认1) 
enabled=1 
# 公钥的地址 
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
公钥:锁 
私钥:钥匙
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号