yum管理工具
[TOC]
yum概述
什么是yum
yum也是一直rpm包管理工具,相比于rpm命令,優(yōu)勢是可以自動解決依賴關系
自動解決依賴關系的前提條件,你的yum源中要有這些依賴包
舉例
??nginx?
??安裝需要??pcre-devel?
?? 、?? openssl-devel?
?
yum install -y nginx
什么是yum源
yum源:可以理解為手機中的應用商店
yum其他名稱:鏡像站,yum倉庫,rpm倉庫
配置yum源
# 使用阿里云的yun源
http://mirrors.aliyun.com
# 系統(tǒng)中需要的基礎yum源
base源:和鏡像中的linux基礎rpm包差不多
epel源:一些擴展安裝包
# yum源存的配置文件存放目錄
[root@zxw <sub>]# ll /etc/yum.repos.d/
total 40
-rw-r--r--. 1 root root 1664 Oct 23 2020 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Oct 23 2020 CentOS-CR.repo
-rw-r--r--. 1 root root 649 Oct 23 2020 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root 314 Oct 23 2020 CentOS-fasttrack.repo
-rw-r--r--. 1 root root 630 Oct 23 2020 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Oct 23 2020 CentOS-Sources.repo
-rw-r--r--. 1 root root 8515 Oct 23 2020 CentOS-Vault.repo
-rw-r--r--. 1 root root 616 Oct 23 2020 CentOS-x86_64-kernel.repo
# 1.刪除所有官方y(tǒng)um源
[root@zxw </sub>]# rm -f /etc/yum.repos.d/*
[root@zxw <sub>]# ll /etc/yum.repos.d/
total 0
# 2.安全方式,不使用yum源
[root@zxw </sub>]# 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@zxw <sub>]# ll /etc/yum.repos.d/
total 4
-rw-r--r--. 1 root root 2523 Apr 23 15:43 CentOS-Base.repo
# 下載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@zxw </sub>]# ll /etc/yum.repos.d/
total 8
-rw-r--r--. 1 root root 2523 Apr 23 15:43 CentOS-Base.repo
-rw-r--r--. 1 root root 664 Apr 23 15:54 epel.repo
## 注意:在/etc/yum.repos.d/目錄下所有的yum源配置,必須以.repo結尾
舉例
# 安裝nginx服務,使用nginx官方y(tǒng)um源
# 1.打開官網(wǎng) http://nginx.org/
# 2.找nginx的倉庫
# 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
? ? ? ?
[root@zxw ~]# ll /etc/yum.repos.d/
total 12
-rw-r--r--. 1 root root 2523 Apr 23 15:43 CentOS-Base.repo
-rw-r--r--. 1 root root 664 Apr 23 15:54 epel.repo
-rw-r--r--. 1 root root 614 Apr 23 16:06 nginx.repo
1.阿里云鏡像站:http://mirrors.aliyun.com
2.網(wǎng)易鏡像站: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源的鏡像網(wǎng)站:mirrors.aliyun.com
- 下載兩個源(base,epel)
- base源:所有系統(tǒng)的基礎軟件包
- centos
- 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
yum包管理命令
# 1.查詢倉庫中所有的rpm包
yum list
可以配合|grep過濾出想要的rpm包
# 2.查看倉庫中所有安裝包的詳細信息
yum info
yum info tree
# 3.根據(jù)命令或文件查找該命令屬于哪個rpm包
yum provides 命令
注意:盡量接命令的絕對路徑,不知道命令的絕對路徑的情況下,*/命令
yum命令實踐
yum查詢
# 查看yum倉庫中的所有可以安裝的rpm包
[root@zxw <sub>]# yum list
# 過濾看看yum倉庫中是否有wget包
[root@zxw </sub>]# yum list|grep wget
wget.x86_64 1.14-18.el7_6.1 base
包名 版本和發(fā)布次數(shù) 這個包在那個倉庫中
# 查看指定包的詳細信息
[root@zxw <sub>]# yum info wget
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: mirrors.aliyun.com
* extras: mirrors.aliyun.com
* updates: mirrors.aliyun.com
Available Packages
Name : wget
Arch : x86_64
Version : 1.14
Release : 18.el7_6.1
Size : 547 k
Repo : base/7/x86_64
Summary : A utility for retrieving files using the HTTP or FTP protocols
URL : http://www.gnu.org/software/wget/
License : GPLv3+
Description : GNU Wget is a file retrieval utility which can use either the HTTP or
: FTP protocols. Wget features include the ability to work in the
: background while you are logged out, recursive retrieval of
: directories, file name wildcard matching, remote file timestamp
: storage and comparison, use of Rest with FTP servers and Range with
: HTTP servers to retrieve files over slow or unstable connections,
: support for Proxy servers, and configurability.
# 產(chǎn)看yum倉庫中,所有安裝包的詳細信息
yum info
# 根據(jù)命令查找包
[root@zxw </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
No matches found(# 因為沒有安裝,所以它找不到)
# 該命令率屬于的包名
net-tools-2.0-0.25.20131004git.el7.x86_64 : Basic networking tools
# 該命令率屬于的倉庫
Repo : base
Matched from:
# 裝完后,命令會在/usr/sdin下叫ifconfig
Filename : /sbin/ifconfig
# 根據(jù)命令查找屬于那個安裝包,最好寫命令的絕對路徑
[root@zxw ~]# 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
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= 那兩個網(wǎng)址不是咱們使用的,可以刪除 )
# 2.報錯
[root@zxw ~]# 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
(# 原因:后臺已經(jīng)有yum進程在安裝服務,要么就等安裝結束,要么 kill PID )
# 3.網(wǎng)絡波動
多執(zhí)行幾次
# 4.環(huán)境變量損壞
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
$releasever : 7
$basearch ? : x86_64
本文摘自 :https://blog.51cto.com/u