yum管理工具

yum管理工具


yum概述


什么是yum

yum 也是一种 rpm 包管理工具,相比于rpm命令,优势是可以自动解决依赖关系。

自动解决依赖关系前提条件,你的yum源中要有这些依赖包

举例

nginx 安装需要依赖 pcre-devel 、 openssl-devel

yum install -y nginx

什么是yun源

yum源:可以理解为手机中的应用商店

yum源其他名称:镜像站,yum仓库,rpm仓库

配置yum源

# 使用阿里云yum源
http://mirrors.aliyun.com

# 挂载镜像
root@localhost.localdomain,10.0.0.167:~ # mount /dev/cdrom /mnt/

# 系统中需要的基础yum源
base源:和镜像中的Linux基础rpm包差不多
epel源:一些扩展安装包

# yum源的配置文件存放目录
14:57:38 root@localhost.localdomain,10.0.0.167:~ # ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 2523 Apr 21 10:50 CentOS-Base.repo
-rw-r--r--. 1 root root  664 Apr 21 10:59 epel.repo

# 1.删除所有官方yum源
root@localhost.localdomain,10.0.0.167:~ #  rm -f /etc/yum.repos.d/*
# 2.安全方式,不使用yum源
root@localhost.localdomain,10.0.0.167:~ # 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
15:05:13 root@localhost.localdomain,10.0.0.167:~ # ll /etc/yum.repos.d
total 8
-rw-r--r--. 1 root root 2523 Apr 21 10:50 CentOS-Base.repo
-rw-r--r--. 1 root root  664 Apr 21 10:59 epel.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
15:05:13 root@localhost.localdomain,10.0.0.167:~ # ll /etc/yum.repos.d
total 8
-rw-r--r--. 1 root root 2523 Apr 21 10:50 CentOS-Base.repo
-rw-r--r--. 1 root root  664 Apr 21 10:59 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 

sudo sed -e 's|^mirrorlist=|#mirrorlist=|g' \ 
         -e 
's|^#baseurl=http://mirror.centos.org|baseurl=https://mirrors.tuna.tsinghua.edu.cn|g' \ 
       -i.bak \ 
       /etc/yum.repos.d/CentOS-*.repo

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查询

# 查看yum仓库中的所有可以安装的rpm包
15:11:16 root@localhost.localdomain,10.0.0.167:~ # yum list

# 过滤看看yum仓库中是否有wget包
root@localhost.localdomain,10.0.0.167:~ # yum list|grep wget
包名           版本和发布次数           这包在哪个仓库中
wget.x86_64   1.14-18.el7_6.1          @base

# 查看指定包的详细信息
root@localhost.localdomain,10.0.0.167:~ # yum info wget

# 根据命令查找包
root@localhost.localdomain,10.0.0.167:~ # 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@zls ~]# 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安装

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重装

yum reinstall -y 包名 

作用:误删除了该服务相关的任何一个文件,使用reinstall都可以恢复,但是恢复的是最初始的配置

reinstall的方式,必须跟最开始安装这个包的方式保持一致。

yum更新

# 查看当前系统中,有哪些软件是可以更新的
root@localhost.localdomain,10.0.0.167:~ # yum check-update
# 更新指定的软件包
root@localhost.localdomain,10.0.0.167:~ # yum update -y zlib
# 更新所有可更新的软件包 
root@localhost.localdomain,10.0.0.167:~ # yum update -y

yum卸载

[root@zls ~]# yum erase 包名 -y
[root@zls ~]# yum remove 包名 -y

yum仓库指令

# 查看所有源中可用的yum仓库
root@localhost.localdomain,10.0.0.167:~ # yum repolist
仓库名                            仓库描述                                 仓库状态:多少个包
repo id                           repo name                                     status
base/7/x86_64          CentOS-7 - Base - mirrors.aliyun.com                    10,072

# 查看所有源中,所有的yum仓库
root@localhost.localdomain,10.0.0.167:~ # yum repolist all
仓库名                            仓库描述                                 仓库状态:多少个包
repo id                           repo name                                   status
base/7/x86_64          CentOS-7 - Base - mirrors.aliyun.com               enabled: 10,07

# 使用yum-config-manager
# 1.没有命令,要安装命令
root@localhost.localdomain,10.0.0.167:~ # yum install -y yum-config-manager
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
No package yum-config-manager available.
Error: Nothing to do

# 2.查询该命令属于哪个包?
[root@zls vsftpd]# 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.localdomain,10.0.0.167:~ # 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缓存命令

## 清除所有的缓存 
yum clean all

## 加载缓存 
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 clean packages 
只会清除默认路径下的rpm包
  0 ✓ 11:39:00 root@db01,172.16.1.51:~ # find /var/cache/yum/ -type f -name '*.rpm'
/var/cache/yum/x86_64/7/base/packages/centos-indexhtml-7-9.el7.centos.noarch.rpm /var/cache/yum/x86_64/7/base/packages/gperftools-libs-2.6.1-1.el7.x86_64.rpm /var/cache/yum/x86_64/7/epel/packages/nginx-1.20.1-9.el7.x86_64.rpm /var/cache/yum/x86_64/7/epel/packages/nginx-filesystem-1.20.1-9.el7.noarch.rpm /var/cache/yum/x86_64/7/epel/packages/openssl11-libs-1.1.1k-3.el7.x86_64.rpm
  0 ✓ 11:39:35 root@db01,172.16.1.51:~ # yum clean packages
Loaded plugins: fastestmirror 
Cleaning repos: base epel extras updates
5 package files removed 
0 ✓ 11:39:52 root@db01,172.16.1.51:~ # find /var/cache/yum/ -type f -name '*.rpm' 
0 ✓ 11:39:57 root@db01,172.16.1.51:~ # ll /tmp/ 
total 2932
drwxr-xr-x. 78 root root 8192 Apr 19 00:43 etc
-rw-r--r--. 1 root root 2847720 Mar 25 02:21 httpd-2.4.6-97.el7.centos.5.x86_64.rpm 
-rw-r--r--. 1 root root 96468 Mar 25 02:21 httpd-tools-2.4.6-97.el7.centos.5.x86_64.rpm
-rw-r--r--. 1 root root 31264 Jul 4 2014 mailcap-2.1.41-2.el7.noarch.rpm 
-rw-------. 1 root root 1183 Apr 22 11:36 yum_save_tx.2022-04-22.11-36._LHwE3.yumtx 
-rw-------. 1 root root 1140 Apr 22 11:38 yum_save_tx.2022-04-22.11-38.Scig9G.yumtx

yum包管理

# 查看有哪些包组可以安装
root@localhost.localdomain,10.0.0.167:~ # yum group list

# 安装包组
yum groups install 包组名字 

# 卸载包组
yum groups remove 包组名字

yum历史命令

# 查看yum的历史操作 
root@localhost.localdomain,10.0.0.167:~ # yum history

命令的ID  执行的命令                   执行的时间          动作            操作几个包
ID     | Login user               | Date and time    | Action(s)      | Altered
-------------------------------------------------------------------------------
    10 | install -y tree             | 2022-04-24 15:11 | Install        |    5   
     9 | install -y yum-utils        | 2022-04-24 15:09 | Install        |   31   
     8 | root <root>              | 2022-04-21 11:34 | Install        |    1  <
     7 | root <root>              | 2022-04-20 16:17 | Erase          |    1 ><
     6 | root <root>              | 2022-04-20 16:14 | Erase          |    1 ><
     5 | root <root>              | 2022-04-20 16:13 | Erase          |    1 ><

# 查看某个历史操作的详细信息 
[root@zls vsftpd]# yum history info ID 
[root@zls vsftpd]# yum history info 46

# 撤销历史操作:一般撤销更新操作 
[root@zls vsftpd]# yum history undo ID
[root@zls vsftpd]# yum history undo 55


yun仓库配置文件

# 仓库名字
 [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 

公钥:锁 
私钥:钥匙

posted @   hjx、贤  阅读(96)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 【自荐】一款简洁、开源的在线白板工具 Drawnix
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
点击右上角即可分享
微信分享提示