yum工具的使用
1.yum仓库管理
1.1yum本地仓库
//挂载光盘镜像,临时挂载
[root@yy ~]# mkdir /mnt/cdrom
[root@yy ~]# mount /dev/cdrom /mnt/cdrom/
mount: /mnt/cdrom: WARNING: device write-protected, mounted read-only.
[root@yy ~]# ls /mnt/cdrom/
AppStream BaseOS EFI images isolinux LICENSE media.repo TRANS.TBL
//配置本地仓库
[root@yy ~]# cd /etc/yum.repos.d/
[root@yy yum.repos.d]# ls
yy.repo
[root@yy yum.repos.d]# rm -rf *
[root@yy yum.repos.d]# ls
[root@yy yum.repos.d]# vi yy.repo
[root@yy yum.repos.d]# cat yy.repo
[BaseOS]
[BaseOS]
name=BaseOS
baseurl=file:///mnt/cdrom/BaseOS
gpgcheck=0
enabled=1
[AppStream]
name=AppStream
baseurl=file:///mnt/cdrom/AppStream
gpgcheck=0
enabled=1
[root@yy yum.repos.d]#
//清空本地仓库缓存
[root@yy ~]# dnf clean all
15 files removed
//缓存元数据
[root@yy ~]# yum makecache
BaseOS 28 MB/s | 2.6 MB 00:00
AppStream 29 MB/s | 7.5 MB 00:00
Last metadata expiration check: 0:00:01 ago on Mon 11 Jul 2022 07:50:48 PM CST.
Metadata cache created.
[root@yy ~]#
//列出所有可用仓库
[root@yy ~]# dnf repolist
repo id repo name
AppStream AppStream
BaseOS BaseOS
[root@yy ~]#
//检验yum本地仓库
[root@yy ~]# dnf list all
BaseOS 23 MB/s | 2.6 MB 00:00
AppStream 21 MB/s | 7.5 MB 00:00
Last metadata expiration check: 0:00:01 ago on Mon 11 Jul 2022 07:44:16 PM CST.
Installed Packages
NetworkManager.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-libnm.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-team.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-tui.x86_64 1:1.32.10-4.el8 @anaconda
acl.x86_64 2.2.53-1.el8 @anaconda
audit.x86_64 3.0-0.17.20191104git1c2f876.el8 @anaconda
audit-libs.x86_64 3.0-0.17.20191104git1c2f876.el8 @anaconda
authselect.x86_64 1.2.2-3.el8 @anaconda
1.2 网络仓库配置
网络仓库获取rpm包就直接从开源镜像站获取即可,配置方式和本地仓库基本一致。
开源镜像站地址:
http://mirrors.163.com
http://mirrors.sohu.com
https://mirrors.tuna.tsinghua.edu.cn
http://mirrors.aliyun.com
//配置网络yum仓库
[root@yy yum.repos.d]# vi yy.repo
[root@yy yum.repos.d]# cat yy.repo
[BaseOS]
name=BaseOS
baseurl=https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
gpgcheck=0
enabled=1
[AppStream]
name=AppStream
baseurl=https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
gpgcheck=0
enabled=1
[root@yy yum.repos.d]#
//清理缓存
[root@yy ~]# dnf clean all
13 files removed
//检验yum仓库
[root@yy ~]# dnf list all
BaseOS 3.7 MB/s | 4.6 MB 00:01
AppStream 4.4 MB/s | 8.4 MB 00:01
Last metadata expiration check: 0:00:01 ago on Mon 11 Jul 2022 07:57:43 PM CST.
Installed Packages
NetworkManager.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-libnm.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-team.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-tui.x86_64 1:1.32.10-4.el8 @anaconda
acl.x86_64 2.2.53-1.el8 @anaconda
audit.x86_64 3.0-0.17.20191104git1c2f876.el8 @anaconda
audit-libs.x86_64 3.0-0.17.20191104git1c2f876.el8 @anaconda
authselect.x86_64 1.2.2-3.el8 @anaconda
authselect-libs.x86_64 1.2.2-3.el8 @anaconda
basesystem.noarch 11-5.el8 @anaconda
bash.x86_64 4.4.20-2.el8 @anaconda
bash-completion.noarch 1:2.7-5.el8 @BaseOS
//阿里云源
[root@yy ~]# wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
--2022-07-11 20:02:00-- https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
Resolving mirrors.aliyun.com (mirrors.aliyun.com)... 223.76.171.226, 223.76.171.228, 223.76.171.227, ...
Connecting to mirrors.aliyun.com (mirrors.aliyun.com)|223.76.171.226|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 2495 (2.4K) [application/octet-stream]
Saving to: ‘/etc/yum.repos.d/CentOS-Base.repo’
/etc/yum.repos.d/CentOS-Base.repo 100%[===================================================================================================>] 2.44K --.-KB/s in 0s
2022-07-11 20:02:00 (93.6 MB/s) - ‘/etc/yum.repos.d/CentOS-Base.repo’ saved [2495/2495]
[root@yy ~]# cd /etc/yum.repos.d/
[root@yy yum.repos.d]# ls
CentOS-Base.repo yy.repo
[root@yy yum.repos.d]# cat /etc/yum.repos.d/CentOS-Base.repo
# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client. You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#
[base]
name=CentOS-8.5.2111 - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that may be useful
[extras]
name=CentOS-8.5.2111 - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/extras/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-8.5.2111 - Plus - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/centosplus/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/centosplus/$basearch/os/
gpgcheck=0
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-8.5.2111 - PowerTools - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
gpgcheck=0
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-8.5.2111 - AppStream - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/
http://mirrors.aliyuncs.com/centos-vault/8.5.2111/AppStream/$basearch/os/
http://mirrors.cloud.aliyuncs.com/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[root@yy yum.repos.d]#
2. yum/dnf管理软件
2.1 yum/dnf命令
//yum命令语法
yum/dnf [options] [command] [package ...]
//常用的选项
-y //自动回答为"yes"
-q //静默模式,安装时不输出信息至标准输出
--nogpgcheck //使用当gpgcheck=1时会使用gpgkey验证包的来源合法性,此时可以使用此命令跳过检查
--disablerepo=repoidglob //临时禁用此处指定的repo
--enablerepo=repoidglob //临时启用此处指定的repo
--noplugins //禁用所有插件
//常用的command
list //列出所有的包
all //默认项
available //列出仓库中有的,但尚未安装的所有可用的包
installed //列出已经安装的包
updates //可用的升级
clean //清理缓存
all //清除所有缓存
packages //清除包缓存
headers //清除头部缓存
metadata //清除元数据缓存
dbcache //清除数据库缓存
repolist //显示repo列表及其简要信息
all //列出所有仓库
enabled //默认项,列出开启的仓库
disabled //列出关闭的仓库
install //安装,可以一次安装多个包
yum install packages [...]
remove //卸载,可以一次卸载多个包
provides command //查看指定命令是由哪个包安装生成的
grouplist //列出可用的组
groupinstall "group name" //安装一组软件
localinstall //安装本地rpm包,自动解决依赖关系
info //查看包的信息,显示rpm -qi package的结果
yum info packages
update //升级
yum update packages [...]
update_to //升级为指定版本
downgrade package1 package2 //将package1降级为package2
search string //以指定的关键字搜索程序包名以及概要信息
deplist package //显示指定包的依赖关系
history //查看yum的历史事务信息
// yum/dnf 安装
[root@yy ~]# dnf -y install httpd
Last metadata expiration check: 0:00:30 ago on Mon 11 Jul 2022 08:12:36 PM CST.
Dependencies resolved.
========================================================================================================
Package Architecture Version Repository Size
========================================================================================================
Installing:
httpd x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 AppStream 1.4 M
Installing dependencies:
apr x86_64 1.6.3-12.el8 AppStream 129 k
apr-util x86_64 1.6.1-6.el8
// yum/dnf安装httpd成功
[root@yy ~]# dnf list installed |grep httpd
centos-logos-httpd.noarch 85.8-2.el8 @BaseOS
httpd.x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 @AppStream
httpd-filesystem.noarch 2.4.37-43.module_el8.5.0+1022+b541f3b1 @AppStream
httpd-tools.x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 @AppStream
available //列出仓库中有的,但尚未安装的所有可用的包
[root@yy ~]# dnf list available |head -5
Last metadata expiration check: 0:10:43 ago on Mon 11 Jul 2022 08:13:09 PM CST.
Available Packages
CUnit.i686 2.1.3-17.el8 AppStream
CUnit.x86_64 2.1.3-17.el8 AppStream
GConf2.i686 3.2.6-22.el8 AppStream
installed //列出已经安装的包
[root@yy ~]# dnf list installed |head -5
Installed Packages
NetworkManager.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-libnm.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-team.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-tui.x86_64 1:1.32.10-4.el8 @anaconda
updates //列出可用的升级软件包
[root@yy ~]# dnf list updates
Last metadata expiration check: 0:13:10 ago on Mon 11 Jul 2022 08:13:09 PM CST.
Available Upgrades
kernel.x86_64 4.18.0-348.7.1.el8_5 BaseOS
kernel-core.x86_64 4.18.0-348.7.1.el8_5 BaseOS
kernel-modules.x86_64 4.18.0-348.7.1.el8_5 BaseOS
kernel-tools.x86_64 4.18.0-348.7.1.el8_5 BaseOS
kernel-tools-libs.x86_64 4.18.0-348.7.1.el8_5 BaseOS
kexec-tools.x86_64 2.0.20-57.el8_5.1 BaseOS
libgcc.x86_64 8.5.0-4.el8_5 BaseOS
repolist //显示repo列表及其简要信息
all
[root@yy ~]# dnf repolist all
repo id repo name status
AppStream AppStream enabled
BaseOS BaseOS enabled
enabled //默认项
[root@yy ~]# dnf repolist
repo id repo name
AppStream AppStream
BaseOS BaseOS
disabled //禁用项
[root@yy ~]# dnf repolist disabled
[root@yy ~]#
remove|erase //卸载
[root@yy ~]# dnf -y remove httpd
Dependencies resolved.
===========================================================================================================================================================================================
Package Architecture Version Repository Size
===========================================================================================================================================================================================
Removing:
httpd x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 @AppStream 4.3 M
Removing unused dependencies:
apr x86_64 1.6.3-12.el8 @AppStream 272 k
apr-util x86_64 1.6.1-6.el8 @AppStream 231 k
apr-util-bdb x86_64 1.6.1-6.el8 @AppStream 12 k
apr-util-openssl x86_64 1.6.1-6.el8 @AppStream 20 k
centos-logos-httpd noarch 85.8-2.el8 @BaseOS 197 k
httpd-filesystem noarch 2.4.37-43.module_el8.5.0+1022+b541f3b1 @AppStream 400
httpd-tools x86_64 2.4.37-43.module_el8.5.0+1022+b541f3b1 @AppStream 193 k
mailcap noarch 2.1.48-3.el8 @BaseOS 71 k
mod_http2 x86_64 1.15.7-3.module_el8.4.0+778+c970deab @AppStream 394 k
Transaction Summary
===========================================================================================================================================================================================
Remove 10 Packages
Freed space: 5.6 M
Running transaction check
Transaction check succeeded.
Running transaction test
[root@yy ~]# dnf list installed |grep httpd
[root@yy ~]#
update //升级
//先查询那些服务可以升级
[root@yy ~]# dnf list updates |grep python
python3-perf.x86_64 4.18.0-348.7.1.el8_5 BaseOS
//升级
[root@yy ~]# dnf update python3-perf.x86_64
Last metadata expiration check: 0:22:53 ago on Mon 11 Jul 2022 08:13:09 PM CST.
Dependencies resolved.
===========================================================================================================================================================================================
Package Architecture Version Repository Size
===========================================================================================================================================================================================
Upgrading:
python3-perf x86_64 4.18.0-348.7.1.el8_5 BaseOS 7.1 M
Transaction Summary
===========================================================================================================================================================================================
Upgrade 1 Package
Total download size: 7.1 M
//没有可以升级的python
[root@yy ~]# dnf list updates |grep python
[root@yy ~]#
info //显示rpm -qi package的结果
[root@yy ~]# dnf info wget
Last metadata expiration check: 0:24:42 ago on Mon 11 Jul 2022 08:13:09 PM CST.
Installed Packages
Name : wget
Version : 1.19.5
Release : 10.el8
Architecture : x86_64
Size : 2.8 M
Source : wget-1.19.5-10.el8.src.rpm
Repository : @System
From repo : AppStream
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.
provides|whatprovides //查看指定的文件或特性是由哪个包安装生成的
[root@yy ~]# dnf provides httpd
Last metadata expiration check: 0:25:59 ago on Mon 11 Jul 2022 08:13:09 PM CST.
httpd-2.4.37-41.module_el8.5.0+977+5653bbea.x86_64 : Apache HTTP Server
Repo : AppStream
Matched from:
Provide : httpd = 2.4.37-41.module_el8.5.0+977+5653bbea
httpd-2.4.37-43.module_el8.5.0+1022+b541f3b1.x86_64 : Apache HTTP Server
Repo : AppStream
Matched from:
Provide : httpd = 2.4.37-43.module_el8.5.0+1022+b541f3b1
search string1 [string2 …] //以指定的关键字搜索程序包名及summary信息
[root@yy ~]# dnf search httpd
Last metadata expiration check: 0:27:01 ago on Mon 11 Jul 2022 08:13:09 PM CST.
=============================================================================== Name Exactly Matched: httpd ===============================================================================
httpd.x86_64 : Apache HTTP Server
============================================================================== Name & Summary Matched: httpd ==============================================================================
centos-logos-httpd.noarch : CentOS-related icons and pictures used by httpd
keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
python3-keycloak-httpd-client-install.noarch : Tools to configure Apache HTTPD as Keycloak client
=================================================================================== Name Matched: httpd ===================================================================================
httpd-devel.x86_64 : Development interfaces for the Apache HTTP server
httpd-filesystem.noarch : The basic directory layout for the Apache HTTP server
httpd-manual.noarch : Documentation for the Apache HTTP server
httpd-tools.x86_64 : Tools for use with the Apache HTTP Server
libmicrohttpd.i686 : Lightweight library for embedding a webserver in applications
libmicrohttpd.x86_64 : Lightweight library for embedding a webserver in applications
================================================================================= Summary Matched: httpd ==================================================================================
mod_auth_mellon.x86_64 : A SAML 2.0 authentication module for the Apache Httpd Server
mod_dav_svn.x86_64 : Apache httpd module for Subversion server
[root@yy ~]#
deplist package [package2 …] //显示指定包的依赖关系
[root@yy ~]# dnf deplist httpd|head -5
Last metadata expiration check: 0:28:04 ago on Mon 11 Jul 2022 08:13:09 PM CST.
package: httpd-2.4.37-41.module_el8.5.0+977+5653bbea.x86_64
dependency: /bin/sh
provider: bash-4.4.20-2.el8.x86_64
dependency: /etc/mime.types
provider: mailcap-2.1.48-3.el8.noarch
history //查看yum的历史事务信息
[root@yy ~]# dnf history
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
6 | update python3-perf.x86_64 | 2022-07-11 20:36 | Upgrade | 1
5 | -y remove httpd | 2022-07-11 20:31 | Removed | 10
4 | -y install httpd | 2022-07-11 20:13 | Install | 10
3 | -y install wget | 2022-07-11 20:01 | Install | 2
2 | -y install bash-completion | 2022-07-10 13:35 | Install | 5
1 | | 2022-06-27 19:33 | Install | 378 EE
[root@yy ~]#
grouplist //列出可用的组
[root@yy ~]# dnf grouplist
Last metadata expiration check: 0:30:23 ago on Mon 11 Jul 2022 08:13:09 PM CST.
Available Environment Groups:
Server with GUI
Server
Workstation
Custom Operating System
Virtualization Host
Installed Environment Groups:
Minimal Install
Available Groups:
Legacy UNIX Compatibility
Container Management
Development Tools
.NET Core Development
Graphical Administration Tools
Headless Management
Network Servers
RPM Development Tools
Scientific Support
Security Tools
Smart Card Support
System Tools
搜索软件包
[root@localhost ~]# yum list all
[root@yy ~]# dnf list all | head -5
Last metadata expiration check: 0:31:40 ago on Mon 11 Jul 2022 08:13:09 PM CST.
Installed Packages
NetworkManager.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-libnm.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-team.x86_64 1:1.32.10-4.el8 @anaconda
[root@yy ~]# dnf list all | head -5
Last metadata expiration check: 0:31:40 ago on Mon 11 Jul 2022 08:13:09 PM CST.
Installed Packages
NetworkManager.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-libnm.x86_64 1:1.32.10-4.el8 @anaconda
NetworkManager-team.x86_64 1:1.32.10-4.el8 @anaconda