yum管理工具

Posted 少年已不年少

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了yum管理工具相关的知识,希望对你有一定的参考价值。

一. yum概述

1.什么是yum

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

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

举例

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

yum install -y nginx

2.什么是yum源

yum源:可以理解为手机中的应用商店
yum源其他名称:镜像站,yum仓库,rpm仓库

3.配置yum源

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

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

## yum源的配置文件存放目录
[root@Quanyi ~]# 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@Quanyi ~]# rm -f /etc/yum.repos.d/*

## 2.安全方式,不使用yum源,压缩打包一下
[root@Quanyi ~]# 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@Quanyi ~]# 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@Quanyi ~]# 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

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源的镜像站:mirrors.aliyun.com

yum管理工具_centos

下载·两个源

  • Base源:所有系统的基础软件包
  • 选择centos

yum管理工具_yum源_02

配置方法

yum管理工具_nginx_03

epel源:扩展软件包

yum管理工具_nginx_04

配置方法

yum管理工具_yum源_05

二. yum命令实践

1.yum查询

## 查看yum仓库中的所有可以安装的rpm包
[root@Quanyi <sub>]# yum list

## 过滤看看yum仓库中是否有zip包
zip.x86_64 3.0-11.el7 @base
# 包名 版本和发布次数 这包在哪个仓库中

## 查看指定包的详细信息
[root@Quanyi </sub>]# yum info zip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Installed Packages
Name : zip
Arch : x86_64
Version : 3.0
Release : 11.el7
Size : 796 k
Repo : installed
From repo : base
Summary : A file compression and packaging utility compatible with PKZIP
URL : http://www.info-zip.org/Zip.html
License : BSD
Description : The zip program is a compression and file packaging utility. Zip is
: analogous to a combination of the UNIX tar and compress commands and
: is compatible with PKZIP (a compression and file packaging utility for
: MS-DOS systems).
:
: Install the zip package if you need to compress files using the zip
: program.

## 查看yum仓库中,所有安装包的详细信息
[root@Quanyi <sub>]# yum info

## 根据命令查找包
[root@Quanyi </sub>]# yum provides zip
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
zip-3.0-11.el7.x86_64 : A file compression and packaging utility compatible with PKZIP
Repo : base



zip-3.0-11.el7.x86_64 : A file compression and packaging utility compatible with PKZIP
Repo : @base


[root@Quanyi <sub>]# 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 : /usr/sbin/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@Quanyi </sub>]# yum provides */wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
1:bash-completion-2.1-8.el7.noarch : Programmable completion for Bash
Repo : base
Matched from:
Filename : /usr/share/bash-completion/completions/wget



fmf-0.16.0-1.el7.noarch : Flexible Metadata Format
Repo : epel
Matched from:
Filename : /usr/share/doc/fmf-0.16.0/examples/wget



wget-1.14-18.el7_6.1.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
Repo : base
Matched from:
Filename : /usr/bin/wget



wget-1.14-18.el7_6.1.x86_64 : A utility for retrieving files using the HTTP or FTP protocols
Repo : @base
Matched from:
Filename : /usr/bin/wget

2.yum报错

## 1.报错
http://mirrors.cloud.aliyuncs.com/centos/7/os/x86_64/Packages/python-srpm-macros-3-
34.el7.noarch.rpm: [Errno 14] curl#6 - "Could not resolve host: mirrors.cloud.aliyuncs.com;
Unknown error"
#原因是aliyun的Base源中有另外两个 baseurl= 那两个网址不是咱们使用的,可以删除

## 2.报错
[root@Quanyi ~]# yum install -y tree
Loaded plugins: fastestmirror
Existing lock /var/run/yum.pid: another copy is running as pid 37209.
Another app is currently holding the yum lock; waiting for it to exit...
The other application is: yum
  Memory :  24 M RSS (769 MB VSZ)
  Started: Thu Apr 21 21:33:34 2022 - 00:06 ago
  State : Sleeping, pid: 37209
#原因:后台已经有yum进程在安装服务,要么就等安装结束,要么 kill PID

## 3.网络波动
多执行几次
## 4.环境变量损坏
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
$releasever : 7
$basearch   : x86_64

3.yum安装

yum安装方式:
##举例:
1.-本地安装
# yum localinstall -y 包名   (前提该包已经下载在服务器上了

2.-yum源安装
# yum install -y tree

3.-网站上安装
# yum install -y http://test.driverzeng.com/Nginx_package/nginx-1.12.2-
3.el7.x86_64.rpm

# 自动解决依赖关系的前提条件:在你的所有yum源中都要有该软件的依赖包

4.yum重置

#举例:
[root@Quanyi ~]# yum reinstall -y zip

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

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

5.yum更新

#举例:
# 查看当前系统中,有哪些软件是可以更新的
[root@Quanyi <sub>]# yum check-update
cryptsetup-libs.x86_64 2.0.3-6.el7 base
curl.x86_64 7.29.0-59.el7_9.1 updates
cyrus-sasl-lib.x86_64 2.1.26-24.el7_9 updates

# 更新指定的软件包
[root@Quanyi </sub>]# yum update -y curl.x86_64

# 更新所有可更新的软件包
[root@Quanyi ~]# yum update -y (这个更新操作危险,内核版本也会更新)

6.yum卸载

# 两种方法:
[root@Quanyi <sub>]# yun erase zip -y

[root@Quanyi </sub>]# yun remove zip -y

7.yum仓库指令

## 举例:
## 查看所有源中可用的yum仓库
[root@Quanyi <sub>]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
#仓库名 仓库描述 仓库状态:多少个包
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 13,751
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 509
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 3,728
repolist: 28,060

# 查看所有源中,所有的yum仓库
[root@Quanyi </sub>]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
#仓库名 仓库描述 仓库状态:多少个包
repo id repo name status
base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com enabled: 10,072
centosplus/7/x86_64 CentOS-7 - Plus - mirrors.aliyun.com disabled
contrib/7/x86_64 CentOS-7 - Contrib - mirrors.aliyun.com disabled
epel/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 enabled: 13,751
epel-debuginfo/x86_64 Extra Packages for Enterprise Linux 7 - x86_64 - Debug disabled
epel-source Extra Packages for Enterprise Linux 7 - x86_64 - Source disabled
extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com enabled: 509
updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com enabled: 3,728
repolist: 28,060

## 使用yum-config-manager
# 1.没有这个命令,所以会报错,要安装命令
[root@Quanyi <sub>]# 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@Quanyi </sub>]# 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
epel/x86_64/filelists_db | 12 MB 00:00:12
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@Quanyi <sub>]# yum install -y yum-utils

## 修改yum源配置文件,开启或关闭仓库
# 1.开启
[root@Quanyi </sub>]# yum-config-manager --enable nginx-mainline

# 2.关闭
[root@Quanyi ~]# yum-config-manager --disable nginx-mainline

8.yum缓存命令

## 举例:
## 清除所有的缓存
[root@Quanyi <sub>]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
Cleaning up list of fastest mirrors

## 加载缓存
[root@Quanyi </sub>]# yum makecache

## 默认情况下,yum是不会下载rpm的只会安装
## 除非开启,下载的配置
[root@Quanyi <sub>]# vim /etc/yum.conf

1 [main]
2 cachedir=/var/cache/yum/$basearch/$releasever
3 keepcache=0 # 把0改成1就是开启下载rpm
4 debuglevel=2
5 logfile=/var/log/yum.log

## 下面是yum下载后的默认路径
[root@Quanyi </sub>]# ll /var/cache/yum/x86_64/7/
total 24
drwxr-xr-x. 4 root root 4096 Apr 22 16:56 base
drwxr-xr-x. 4 root root 33 Apr 22 15:45 centosplus
drwxr-xr-x. 4 root root 33 Apr 22 15:45 contrib
drwxr-xr-x. 4 root root 4096 Apr 22 16:56 epel
drwxr-xr-x. 4 root root 33 Apr 22 15:45 epel-debuginfo
drwxr-xr-x. 4 root root 33 Apr 22 15:45 epel-source
drwxr-xr-x. 4 root root 4096 Apr 22 16:56 extras
-rw-r--r--. 1 root root 195 Apr 22 16:57 timedhosts
-rw-r--r--. 1 root root 107 Apr 22 16:56 timedhosts.txt
drwxr-xr-x. 4 root root 4096 Apr 22 16:56 updates

## 下载nginx,不安装,并指定目录
yum install nginx -y --downloadonly --downloaddir=/tmp

--downloadonly:仅下载,不安装
--downloaddir:指定下载的目录

## yum clean packages
只会清除默认路径下的rpm包

[root@Quanyi <sub>]# find /var/cache/yum/ -type f -name *.rpm
/var/cache/yum/x86_64/7/base/packages/tree-1.6.0-10.el7.x86_64.rpm

[root@Quanyi </sub>]# yum clean packages
Loaded plugins: fastestmirror
Cleaning repos: base epel extras updates
1 package file removed

[root@Quanyi <sub>]CentOS修改yum源为阿里云

yum详解

Linux Yum仓库源配置

Linux Yum仓库源配置

yum 命令详解-yum仓库配置文件详解

linux安装MongoDB