yum和dnf
CentOS 使用 yum, dnf 解决rpm的包依赖关系
YUM: Yellowdog Update Modifier,rpm的前端程序,可解决软件包相关依赖性,可在多个库之间定位软件包,up2date的替代工具,CentOS 8 用dnf 代替了yum ,不过保留了和yum的兼容性,配置也是通用的
yum/dnf 工作原理
yum/dnf 是基于C/S 模式
- yum 服务器存放rpm包和相关包的元数据库
- yum 客户端访问yum服务器进行安装或查询等
yum 实现过程
先在yum服务器上创建 yum repository(仓库),在仓库中事先存储了众多rpm包,以及包的相关的元数据文件(放置于特定目录repodata下),当yum客户端利用yum/dnf工具进行安装时包时,会自动下载repodata中的元数据,查询远数据是否存在相关的包及依赖关系,自动从仓库中找到相关包下载并安装
yum客户端配置
yum客户端配置文件
/etc/yum.conf #为所有仓库提供公共配置
/etc/yum.repos.d/*.repo: #为每个仓库的提供配置文件
帮助参考: man 5 yum.conf
repo仓库配置文件指向的定义:
[repositoryID]
name=Some name for this repository
baseurl=url://path/to/repository/
enabled={1|0}
gpgcheck={1|0}
gpgkey=URL
enablegroups={1|0}
failovermethod={roundrobin|priority}
roundrobin:意为随机挑选,默认值
priority:按顺序访问
cost= 默认为1000
yum服务器的baseurl形式:
file:// 本地路径
http://
https://
ftp://
注意:yum仓库指向的路径一定必须是repodata目录所在目录
相关变量
yum的repo配置文件中可用的变量:
$releasever: 当前OS的发行版的主版本号,如:8,7,6
$arch: CPU架构,如:aarch64, i586, i686,x86_64等
$basearch:系统基础平台;i386, x86_64
$contentdir:表示目录,比如:centos-8,centos-7
$YUM0-$YUM9:自定义变量
范例
http://server/centos/$releasever/$basearch/
http://server/centos/7/x86_64
http://server/centos/6/i386
范例:CentOS 8 配置文件
[20:56:41 root@centos8 ~]#ll /etc/yum.conf
lrwxrwxrwx. 1 root root 12 May 14 2019 /etc/yum.conf -> dnf/dnf.conf
[20:57:14 root@centos8 ~]#cat /etc/yum.conf
[main]
gpgcheck=1 安装包前要做包的合法性校验
installonly_limit=3 同时可以安装3个包,最小值为2,如设为0或1,为不限制
clean_requirements_on_remove=True 删除包时,是否将不再使用的包删除
best=True 升级时,自动选择安装最新版,即使缺少包的依赖
范例:CentOS 7的配置文件
[21:00:47 root@centos7 ~]#cat /etc/yum.conf
[main]
cachedir=/var/cache/yum/$basearch/$releasever
keepcache=0
debuglevel=2
logfile=/var/log/yum.log
exactarch=1
obsoletes=1
gpgcheck=1
plugins=1
installonly_limit=5
bugtracker_url=http://bugs.centos.org/set_project.php?project_id=23&ref=http://bugs.centos.org/bug_report_page.php?category=yum
distroverpkg=centos-release
# This is the default, if you make this bigger yum won't see if the metadata
# is newer on the remote and so you'll "gain" the bandwidth of not having to
# download the new metadata and "pay" for it by yum not having correct
# information.
# It is esp. important, to have correct metadata, for distributions like
# Fedora which don't keep old packages around. If you don't like this checking
# interupting your command line usage, it's much better to have something
# manually check the metadata once an hour (yum-updatesd will do this).
# metadata_expire=90m
# PUT YOUR REPOS HERE OR IN separate files named file.repo
# in /etc/yum.repos.d
baseurl 指向的路径
阿里云提供了写好的CentOS和ubuntu的仓库文件下载链接
http://mirrors.aliyun.com/repo/
CentOS系统的yum源
#阿里云
https://mirrors.aliyun.com/centos/$releasever/os/x86_64/
#华为云
https://mirrors.huaweicloud.com/centos/$releasever/os/x86_64/
#清华大学
https://mirrors.tuna.tsinghua.edu.cn/centos/$releasever/os/x86_64/
EPEL的yum源
#阿里云
https://mirrors.aliyun.com/epel/$releasever/x86_64
#华为云
https://mirrors.huaweicloud.com/epel/$releasever/x86_64
#清华大学
https://mirrors.tuna.tsinghua.edu.cn/epel/$releasever/x86_64
阿里巴巴开源软件
https://opsx.alibaba.com/
范例:为CentOS7用系统安装光盘作的本地yum仓库
#挂载光盘至某目录,如/mnt/
[21:03:50 root@centos7 ~]#mount /dev/sr0 /mnt
mount: /dev/sr0 is write-protected, mounting read-only
#创建配置文件
[21:04:03 root@centos7 ~]#vim /etc/yum.conf
[Centos7]
name=Centos 7
baseurl=file:///mnt
gpgcheck=0
enable=1
范例:为CentOS 8 配置 yum 的系统和EPEL源仓库
[21:13:20 root@centos8 ~]#cat /etc/yum.repos.d/CentOS-Base.repo
[BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
gpgcheck=1
gpgkey=/etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
gpgcheck=0
[epel]
name=EPEL
baseurl=http://mirrors.aliyun.com/epel/$releasever/Everything/$basearch
gpgcheck=0enabled=1
[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os
gpgcheck=0
注意:与之前的版本不同,CentOS 8 系统有两个yum 源:BaseOS和AppStream ,需要分别设置两个仓库
范例:用脚本实现创建yum仓库配置文件
[21:19:43 root@centos8 yum.repos.d]#cat /data/scripts/yum.sh
#!/bin/bash
mkdir /etc/yum.repos.d/backup
mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/backup
cat > /etc/yum.repos.d/base.repo << EOF
[bace]
name=base
baseurl=https://mirrors.aliyun.com/centos/\$releasever/os/\$basearch
gpgcheck=0
EOF
yum-config-manager命令
可以生成yum仓库的配置文件及启用或禁用仓库,来自于yum-utils包
格式
#增加仓库
yum-config-manager --add-repo URL或file
#禁用仓库
yum-config-manager --disable “仓库名"
#启用仓库
yum-config-manager --enable “仓库名”
范例:创建仓库配置
[21:44:35 root@centos7 ~]#rpm -qf `which yum-config-manager `
yum-utils-1.1.31-54.el7_8.noarch
[21:49:08 root@centos7 ~]#yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
adding repo from: https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[21:49:21 root@centos7 ~]#ls /etc/yum.repos.d/
CentOS-Base.repo docker-ce.repo
范例:创建仓库配置
#生成172.16.0.1_cobbler_ks_mirror_8_.repo
[21:49:49 root@centos7 ~]#yum-config-manager --add-repo=http://172.16.0.1/cobbler/ks_mirror/8/
adding repo from: http://172.16.0.1/cobbler/ks_mirror/8/
[172.16.0.1_cobbler_ks_mirror_8_]
name=added from: http://172.16.0.1/cobbler/ks_mirror/8/
baseurl=http://172.16.0.1/cobbler/ks_mirror/8/
enabled=1
范例:创建仓库配置
[21:53:01 root@centos7 ~]#ls /etc/yum.repos.d/
172.16.0.1_cobbler_ks_mirror_8_.repo CentOS-Base.repo
[21:53:15 root@centos7 ~]#yum-config-manager --add-repo /data/docker-ce.repo
adding repo from: /data/docker-ce.repo
grabbing file /data/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
范例:启用和禁用仓库
[root@centos8 ~]#cat /etc/yum.repos.d/base.repo
[BaseOS]name=BaseOS
baseurl=file:///misc/cd/BaseOS
gpgcheck=0
[AppStream]
name=AppStream
baseurl=file:///misc/cd/AppStream
gpgcheck=0
[epel]name=EPEL
baseurl=http://mirrors.aliyun.com/epel/$releasever/Everything/$basearch http://mirrors.huaweicloud.com/epel/$releasever/Everything/$basearch
gpgcheck=0
enabled=0
[extras]
name=extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os
http://mirrors.huaweicloud.com/centos/$releasever/extras/$basearch/os
gpgcheck=0
enabled=1
[root@centos8 ~]#yum repolist
BaseOS 3.8 MB/s | 3.9 kB 00:00
AppStream 4.2 MB/s | 4.3 kB 00:00
extras 10 kB/s | 1.5 kB 00:00
repo id repo name
status
AppStream AppStream
4,755
BaseOS BaseOS
1,659extras extras
12
[root@centos8 ~]#yum-config-manager --disable extras
[root@centos8 ~]#yum repolist
BaseOS 3.8 MB/s | 3.9 kB 00:00
AppStream 4.2 MB/s | 4.3 kB 00:00
repo id repo name
status
AppStream AppStream 4,755
BaseOS BaseOS 1,659
[root@centos8 ~]#yum-config-manager --enable extras
[root@centos8 ~]#yum repolist
BaseOS 3.8 MB/s | 3.9 kB 00:00
AppStream 4.2 MB/s | 4.3 kB 00:00
extras 12 kB/s | 1.5 kB 00:00
repo id repo name status
AppStream AppStream 4,755
BaseOS BaseOS 1,659
extras extras 12
yum命令
yum命令的用法:
yum [options] [command] [package ...]
yum的命令行选项:
-y #自动回答为“yes”
-q #静默模式
--nogpgcheck #禁止进行gpg check
--enablerepo=repoidglob #临时启用此处指定的repo,支持通配符,如:”*“
--disablerepo=repoidglob #临时禁用此处指定的repo,和上面语句同时使用,放在后面的生效
显示仓库列表
yum repolist [all|enabled|disabled]
范例
[root@centos8 ~]#yum repolist
[root@centos8 ~]#yum repolist --disabled
repo id
repo name
epel
[root@centos8 ~]#yum repolist allLast metadata expiration check: 0:01:32 ago on Sun 29 Dec 2019 12:13:10 AM CST.
repo id repo name status
AppStream AppStream
enabled: 4,681
BaseOS BaseOS
enabled: 1,655
epel EPEL
disabled
extras extras disabled
[root@centos8 ~]#yum --enablerepo=ep* --disablerepo=A* repolist Last metadata expiration check: 0:01:18 ago on Sun 29 Dec 2019 12:13:27 AM CST.
repo id repo name status
BaseOS BaseOS 1,657
epel EPEL 3,733
范例: 显示仓库的详细信息
[root@centos8 ~]#yum repolist -v
Loaded plugins: builddep, changelog, config-manager, copr, debug, debuginfo-install, download, generate_completion_cache, needs-restarting, playground, repoclosure, repodiff, repograph, repomanage, reposync
YUM version: 4.2.17
cachedir: /var/cache/dnf
User-Agent: constructed: 'libdnf (CentOS Linux 8; generic; Linux.x86_64)'
repo: downloading from remote: BaseOS
BaseOS
77 MB/s | 2.2 MB 00:00
BaseOS: using metadata from Tue 09 Jun 2020 06:06:00 AM CST.
repo: downloading from remote: AppStream
AppStream
97 MB/s | 5.7 MB 00:00
AppStream: using metadata from Tue 09 Jun 2020 06:06:04 AM CST.
repo: downloading from remote: epel
EPEL
13 MB/s | 7.2 MB 00:00
epel: using metadata from Fri 03 Jul 2020 08:21:13 AM CST.
repo: downloading from remote: extras
extras
28 kB/s | 6.7 kB 00:00
extras: using metadata from Fri 05 Jun 2020 08:15:26 AM CST.
Last metadata expiration check: 0:00:01 ago on Sat 04 Jul 2020 12:17:23 PM CST.
Completion plugin: Generating completion cache...
Repo-id : AppStream
Repo-name : AppStream
Repo-revision : 8.2.2004
Repo-distro-tags : [cpe:/o:centos:centos:8]: , 8, C, O, S, e, n, t
Repo-updated : Tue 09 Jun 2020 06:06:04 AM CST
Repo-pkgs : 5,326
Repo-available-pkgs: 4,901
Repo-size : 6.0 G
Repo-baseurl : file:///misc/cd/AppStream, https://mirrors.aliyun.com/centos/8/AppStream/x86_64/os/
Repo-expire : 172,800 second(s) (last: Sat 04 Jul 2020 12:17:20 PM CST)
Repo-filename : /etc/yum.repos.d/base.repo
Repo-id : BaseOS
Repo-name : BaseOS
Repo-revision : 8.2.2004
Repo-distro-tags : [cpe:/o:centos:centos:8]: , 8, C, O, S, e, n, t
Repo-updated : Tue 09 Jun 2020 06:06:00 AM CST
Repo-pkgs : 1,674
Repo-available-pkgs: 1,672Repo-size : 1.0 G
Repo-baseurl : file:///misc/cd/BaseOS, https://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
Repo-expire : 172,800 second(s) (last: Sat 04 Jul 2020 12:17:19 PM CST)
Repo-filename : /etc/yum.repos.d/base.repo
Repo-id : epel
Repo-name : EPEL
Repo-revision : 1593735642
Repo-updated : Fri 03 Jul 2020 08:21:13 AM CST
Repo-pkgs : 5,931
Repo-available-pkgs: 5,930
Repo-size : 7.7 G
Repo-baseurl : https://mirrors.aliyun.com/epel/8/Everything/x86_64
Repo-expire : 172,800 second(s) (last: Sat 04 Jul 2020 12:17:21 PM CST)
Repo-filename : /etc/yum.repos.d/base.repo
Repo-id : extras
Repo-name : extras
Repo-revision : 1591316131
Repo-updated : Fri 05 Jun 2020 08:15:26 AM CST
Repo-pkgs : 20
Repo-available-pkgs: 20
Repo-size : 236 k
Repo-baseurl : https://mirrors.aliyun.com/centos/8/extras/x86_64/os
Repo-expire : 172,800 second(s) (last: Sat 04 Jul 2020 12:17:23 PM CST)
Repo-filename : /etc/yum.repos.d/base.repo
Total packages: 12,951
显示程序包
yum list
yum list [all | glob_exp1] [glob_exp2] [...]
yum list {available|installed|updates} [glob_exp1] [...]
范例
[22:24:58 root@centos7 ~]#yum list mariadb-server
Available Packages
mariadb-server.x86_64 1:5.5.65-1.el7 base
[22:25:50 root@centos7 ~]#yum list mariadb-server --showduplicates
Available Packages
mariadb-server.x86_64 1:5.5.56-2.el7 Centos7
mariadb-server.x86_64 1:5.5.65-1.el7 base
范例: 只查看已经安装的包
[22:22:01 root@centos8 yum.repos.d]#yum list installed|head
Installed Packages
NetworkManager.x86_64 1:1.14.0-14.el8 @anaconda
NetworkManager-libnm.x86_64 1:1.14.0-14.el8 @anaconda
NetworkManager-team.x86_64 1:1.14.0-14.el8 @anaconda
NetworkManager-tui.x86_64 1:1.14.0-14.el8 @anaconda
acl.x86_64 2.2.53-1.el8 @anaconda
apr.x86_64 1.6.3-9.el8 @AppStream
apr-util.x86_64 1.6.1-6.el8 @AppStream
apr-util-bdb.x86_64 1.6.1-6.el8 @AppStream
apr-util-openssl.x86_64 1.6.1-6.el8 @AppStream
范例: 查看可安装的包
[22:24:06 root@centos7 ~]#yum list available |head
Available Packages
389-ds-base.x86_64 1.3.10.1-14.el7_8 updates
389-ds-base-devel.x86_64 1.3.10.1-14.el7_8 updates
389-ds-base-libs.x86_64 1.3.10.1-14.el7_8 updates
389-ds-base-snmp.x86_64 1.3.10.1-14.el7_8 updates
Cython.x86_64 0.19-5.el7 base
ElectricFence.i686 2.2.2-39.el7 base
ElectricFence.x86_64 2.2.2-39.el7 Centos7
GConf2.i686 3.2.6-8.el7 base
GConf2.x86_64 3.2.6-8.el7 Centos7
范例: 查看可以升级的包
[22:24:47 root@centos7 ~]#yum list updates |head
Updated Packages
GeoIP.x86_64 1.5.0-14.el7 base
NetworkManager.x86_64 1:1.18.4-3.el7 base
NetworkManager-libnm.x86_64 1:1.18.4-3.el7 base
NetworkManager-team.x86_64 1:1.18.4-3.el7 base
NetworkManager-tui.x86_64 1:1.18.4-3.el7 base
acl.x86_64 2.2.51-15.el7 base
alsa-lib.x86_64 1.1.8-1.el7 base
audit.x86_64 2.8.5-4.el7 base
audit-libs.x86_64 2.8.5-4.el7 base
范例: 查看指定的包
[09:11:26 root@centos7 yum.repos.d]#yum list exim
Available Packages
exim.x86_64 4.94-1.el709:11:24 root@centos7 yum.repos.d]#yum list exim*
Available Packages
exim.x86_64 4.94-1.el7 epel
exim-greylist.x86_64 4.94-1.el7 epel
exim-mon.x86_64 4.94-1.el7 epel
exim-mysql.x86_64 4.94-1.el7 epel
exim-pgsql.x86_64 4.94-1.el7 epel
exim-sysvinit.noarch 4.94-1.el7
安装程序包
yum install package1 [package2] [...]
yum reinstall package1 [package2] [...] #重新安装
--downloadonly #只下载相关包默认至/var/cache/yum/x86_64/7/目录下,而不执行install/upgrade/erase
--downloaddir=<path>, --destdir=<path> #--downloadonly选项来指定下载的目录,如果不存在自动创建
安装epel源
范例:安装epel源
[22:28:21 root@centos7 ~]#yum -y install epel-release
[22:28:47 root@centos7 ~]#yum -y install sl
[22:28:58 root@centos7 ~]#rpm -ql sl
/usr/bin/sl
/usr/share/doc/sl-5.02
/usr/share/doc/sl-5.02/LICENSE
/usr/share/doc/sl-5.02/README.ja.md
/usr/share/doc/sl-5.02/README.md
/usr/share/man/ja/man1/sl.1.ja.gz
/usr/share/man/man1/sl.1.gz
#运行安装sl程序,可以看到下面火车,这标志着我们可以当老司机了
[22:29:04 root@centos7 ~]#sl -a
#一个好玩的小软件
[22:29:04 root@centos7 ~]#yum -y install cowsay
[22:29:04 root@centos7 ~]#cowsay hello
[22:29:04 root@centos7 ~]#animalsay hello
升级最新内核
范例:利用elrepo源在CentOS 7 安装新版内核
说明: 区别在于,内核-lt基于一个长期支持分支,而内核-ml基于主线稳定分支
[09:23:46 root@centos7 data]#yum install https://www.elrepo.org/elrepo-release-7.0-4.el7.elrepo.noarch.rpm
[09:24:25 root@centos7 data]#rpm -ql elrepo-release.noarch 0:7.0-4.el7.elrepo
/etc/pki/elrepo
/etc/pki/elrepo/SECURE-BOOT-KEY-elrepo.org.der
/etc/pki/rpm-gpg
/etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
/etc/yum.repos.d
/etc/yum.repos.d/elrepo.repo
package 0:7.0-4.el7.elrepo is not installed
[09:24:52 root@centos7 data]#yum repolist
elrepo | 2.9 kB 00:00:00
elrepo/primary_db | 377 kB 00:00:21
repo id repo name status
base/7 base 10,070
elrepo ELRepo.org Community Enterprise Linux Repository - el7 114
epel epel 13,425
repolist: 23,609
[09:25:35 root@centos7 data]#cat /etc/yum.repos.d/elrepo.repo
### Name: ELRepo.org Community Enterprise Linux Repository for el7
### URL: http://elrepo.org/
[elrepo]
name=ELRepo.org Community Enterprise Linux Repository - el7
baseurl=http://elrepo.org/linux/elrepo/el7/$basearch/
http://mirrors.coreix.net/elrepo/elrepo/el7/$basearch/
http://mirror.rackspace.com/elrepo/elrepo/el7/$basearch/
http://repos.lax-noc.com/elrepo/elrepo/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo.el7
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0
[elrepo-testing]
name=ELRepo.org Community Enterprise Linux Testing Repository - el7
baseurl=http://elrepo.org/linux/testing/el7/$basearch/
http://mirrors.coreix.net/elrepo/testing/el7/$basearch/
http://mirror.rackspace.com/elrepo/testing/el7/$basearch/
http://repos.lax-noc.com/elrepo/testing/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-testing.el7
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0
[elrepo-kernel]
name=ELRepo.org Community Enterprise Linux Kernel Repository - el7
baseurl=http://elrepo.org/linux/kernel/el7/$basearch/
http://mirrors.coreix.net/elrepo/kernel/el7/$basearch/
http://mirror.rackspace.com/elrepo/kernel/el7/$basearch/
http://repos.lax-noc.com/elrepo/kernel/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-kernel.el7
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0
[elrepo-extras]
name=ELRepo.org Community Enterprise Linux Extras Repository - el7
baseurl=http://elrepo.org/linux/extras/el7/$basearch/
http://mirrors.coreix.net/elrepo/extras/el7/$basearch/
http://mirror.rackspace.com/elrepo/extras/el7/$basearch/
http://repos.lax-noc.com/elrepo/extras/el7/$basearch/
mirrorlist=http://mirrors.elrepo.org/mirrors-elrepo-extras.el7
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-elrepo.org
protect=0
[09:26:27 root@centos7 data]#yum --disablerepo="*" --enablerepo="elrepo-kernel" list available
Available Packages
elrepo-release.noarch 7.0-5.el7.elrepo elrepo-kernel
kernel-lt.x86_64 4.4.232-1.el7.elrepo elrepo-kernel
kernel-lt-devel.x86_64 4.4.232-1.el7.elrepo elrepo-kernel
kernel-lt-doc.noarch 4.4.232-1.el7.elrepo elrepo-kernel
kernel-lt-headers.x86_64 4.4.232-1.el7.elrepo elrepo-kernel
kernel-lt-tools.x86_64 4.4.232-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs.x86_64 4.4.232-1.el7.elrepo elrepo-kernel
kernel-lt-tools-libs-devel.x86_64 4.4.232-1.el7.elrepo elrepo-kernel
kernel-ml.x86_64 5.8.1-1.el7.elrepo elrepo-kernel
kernel-ml-devel.x86_64 5.8.1-1.el7.elrepo elrepo-kernel
kernel-ml-doc.noarch 5.8.1-1.el7.elrepo elrepo-kernel
kernel-ml-headers.x86_64 5.8.1-1.el7.elrepo elrepo-kernel
kernel-ml-tools.x86_64 5.8.1-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs.x86_64 5.8.1-1.el7.elrepo elrepo-kernel
kernel-ml-tools-libs-devel.x86_64 5.8.1-1.el7.elrepo elrepo-kernel
perf.x86_64 5.8.1-1.el7.elrepo elrepo-kernel
python-perf.x86_64 5.8.1-1.el7.elrepo elrepo-kernel
[09:39:35 root@centos7 data]#yum -y --enablerepo="elrepo-kernel" install kernel-ml
[09:39:35 root@centos7 data]#ll /boot
total 117520
-rw-r--r--. 1 root root 147819 Apr 21 2018 config-3.10.0-862.el7.x86_64
-rw-r--r--. 1 root root 216692 Aug 12 00:21 config-5.8.1-1.el7.elrepo.x86_64
drwxr-xr-x. 3 root root 17 Jul 29 08:28 efi
drwxr-xr-x. 2 root root 27 Jul 29 08:28 grub
drwx------. 5 root root 97 Aug 13 09:38 grub2
-rw-------. 1 root root 51916818 Jul 29 08:31 initramfs-0-rescue-47585107eb094b96a9105ae12e9561ce.img
-rw-------. 1 root root 19043770 Jul 29 08:32 initramfs-3.10.0-862.el7.x86_64.img
-rw-------. 1 root root 19779540 Aug 13 09:38 initramfs-5.8.1-1.el7.elrepo.x86_64.img
-rw-r--r--. 1 root root 304926 Apr 21 2018 symvers-3.10.0-862.el7.x86_64.gz
-rw-r--r--. 1 root root 400950 Aug 12 00:21 symvers-5.8.1-1.el7.elrepo.x86_64.gz
-rw-------. 1 root root 3409143 Apr 21 2018 System.map-3.10.0-862.el7.x86_64
-rw-------. 1 root root 4751513 Aug 12 00:21 System.map-5.8.1-1.el7.elrepo.x86_64
-rwxr-xr-x. 1 root root 6224704 Jul 29 08:31 vmlinuz-0-rescue-47585107eb094b96a9105ae12e9561ce
-rwxr-xr-x. 1 root root 6224704 Apr 21 2018 vmlinuz-3.10.0-862.el7.x86_64
-rwxr-xr-x. 1 root root 7894208 Aug 12 00:21 vmlinuz-5.8.1-1.el7.elrepo.x86_64
只下载相关的依赖包
#/data/目录如果不存在,会自动创建
[root@centos8 ~]#yum -y install --downloadonly --downloaddir=/data/httpd httpd
[root@centos8 ~]#ls /data/httpd/
apr-1.6.3-9.el8.x86_64.rpm httpd-2.4.37-16.module_el8.1.0+256+ae790463.x86_64.rpm
apr-util-1.6.1-6.el8.x86_64.rpm httpd-filesystem-2.4.37-16.module_el8.1.0+256+ae790463.noarch.rpm
apr-util-bdb-1.6.1-6.el8.x86_64.rpm httpd-tools-2.4.37-16.module_el8.1.0+256+ae790463.x86_64.rpm
apr-util-openssl-1.6.1-6.el8.x86_64.rpm mailcap-2.1.48-3.el8.noarch.rpm
centos-logos-httpd-80.5-2.el8.noarch.rpm mod_http2-1.11.3-3.module_el8.1.0+213+acce2796.x86_64.rp
卸载程序包
yum remove | erase package1 [package2] [...]
4.3.5 升级和降级
检查可用升级:
yum check-update
升级和降级
yum upgrade|update [package1] [package2] [...]
yum upgrade-minimal #最小化升级
yum downgrade package1 [package2] [...] (降级)
范例
[09:48:44 root@centos7 yum.repos.d]#cat test.repo
[base]
name=base
baseurl=https://mirrors.huaweicloud.com/centos/$releasever/os/x86_64/
https://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.huaweicloud.com/epel/7/x86_64/
https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
[update]
name=aliyun update
baseurl=https://mirrors.aliyun.com/centos/7/updates/x86_64/
gpgcheck=0
[09:49:05 root@centos7 yum.repos.d]#yum --disablerepo=* --enablerep=update list available
[09:48:44 root@centos7 yum.repos.d]#cat test.repo
[base]
name=base
baseurl=https://mirrors.huaweicloud.com/centos/$releasever/os/x86_64/
https://mirrors.aliyun.com/centos/7/os/x86_64/
gpgcheck=0
[epel]
name=epel
baseurl=https://mirrors.huaweicloud.com/epel/7/x86_64/
https://mirrors.aliyun.com/epel/7/x86_64/
gpgcheck=0
[update]
name=aliyun update
baseurl=https://mirrors.aliyun.com/centos/7/updates/x86_64/
gpgcheck=0
[09:49:05 root@centos7 yum.repos.d]#yum info samba --showduplicates
Available Packages
Name : samba
Arch : x86_64
Version : 4.10.4
Release : 10.el7
Size : 708 k
Repo : base/7
Summary : Server and Client software to interoperate with Windows machines
URL : http://www.samba.org/
License : GPLv3+ and LGPLv3+
Description : Samba is the standard Windows interoperability suite of programs for Linux and
: Unix.
Name : samba
Arch : x86_64
Version : 4.10.4
Release : 11.el7_8
Size : 708 k
Repo : update
Summary : Server and Client software to interoperate with Windows machines
URL : http://www.samba.org/
License : GPLv3+ and LGPLv3+
Description : Samba is the standard Windows interoperability suite of programs for Linux and
: Unix.
[09:48:44 root@centos7 yum.repos.d]#yum install samba --disablerepo=updates
[09:48:44 root@centos7 yum.repos.d]#yum update samba
[09:48:44 root@centos7 yum.repos.d]#yum update
查询
查看程序包information:
yum info [...]
查看指定的特性(可以是某文件)是由哪个程序包所提供:
yum provides | whatprovides feature1 [feature2] [...]
注意:文件要写全路径,而不只是文件名,否则可能无法查询到
范例
[09:59:09 root@centos7 yum.repos.d]#ll /etc/vsftpd/vsftpd.conf
ls: cannot access /etc/vsftpd/vsftpd.conf: No such file or directory
[09:59:36 root@centos7 yum.repos.d]#yum provides vsftpd.conf
Repository base is listed more than once in the configuration
Repository epel is listed more than once in the configuration
No matches found
#注意要写文件全路径才能查询到
[10:00:10 root@centos7 yum.repos.d]#yum provides /etc/vsftpd/vsftpd.conf
Repository base is listed more than once in the configuration
Repository epel is listed more than once in the configuration
vsftpd-3.0.2-27.el7.x86_64 : Very Secure Ftp Daemon
Repo : base
Matched from:
Filename : /etc/vsftpd/vsftpd.conf
#使用通配符
[10:00:39 root@centos7 yum.repos.d]#yum provides */updata*
[09:59:52 root@centos7 yum.repos.d]#yum provides */vsftpd.conf
以指定的关键字搜索程序包名及summary信息
yum deplist package1 [package2] [...]
范例
[08:59:09 root@centos8 yum.repos.d]#dnf info bash
Last metadata expiration check: 1:32:55 ago on Thu 13 Aug 2020 08:38:57 AM CST.
Installed Packages
Name : bash
Version : 4.4.19
Release : 7.el8
Arch : x86_64
Size : 6.6 M
Source : bash-4.4.19-7.el8.src.rpm
Repo : @System
From repo : anaconda
Summary : The GNU Bourne Again shell
URL : https://www.gnu.org/software/bash
License : GPLv3+
Description : The GNU Bourne Again shell (Bash) is a shell or command language
: interpreter that is compatible with the Bourne shell (sh). Bash
: incorporates useful features from the Korn shell (ksh) and the C shell
: (csh). Most sh scripts can be run by bash without modification.
Available Packages
Name : bash
Version : 4.4.19
Release : 10.el8
Arch : x86_64
Size : 1.5 M
Source : bash-4.4.19-10.el8.src.rpm
Repo : BaseOS
Summary : The GNU Bourne Again shell
URL : https://www.gnu.org/software/bash
License : GPLv3+
Description : The GNU Bourne Again shell (Bash) is a shell or command language
: interpreter that is compatible with the Bourne shell (sh). Bash
: incorporates useful features from the Korn shell (ksh) and the C shell
: (csh). Most sh scripts can be run by bash without modification.
[10:11:52 root@centos8 yum.repos.d]#dnf list bash*
Installed Packages
bash.x86_64 4.4.19-7.el8 @anaconda
Available Packages
bash.x86_64 4.4.19-10.el8 BaseOS
bash-completion.noarch 1:2.7-5.el8 BaseOS
bash-doc.x86_64 4.4.19-10.el8 BaseOS
bashmount.noarch 4.3.0-1.el8 epel
bashtop.noarch 0.9.24-1.el8 epel
范例
10:12:10 root@centos8 yum.repos.d]#dnf provides /bin/ls
coreutils-8.30-6.el8.x86_64 : A set of basic GNU tools commonly used in shell scripts
Repo : @System
Matched from:
Provide : /bin/ls
coreutils-8.30-7.el8_2.1.x86_64 : A set of basic GNU tools commonly used in shell scripts
Repo : BaseOS
Matched from:
Provide : /bin/ls
coreutils-single-8.30-7.el8_2.1.x86_64 : coreutils multicall binary
Repo : BaseOS
Matched from:
Provide : /bin/ls
范例
[10:22:31 root@centos8 yum.repos.d]#rpm -ivh /mnt/AppStream/Packages/httpd-2.4.37-11.module_el8.0.0+172+85fc1f40.x86_64.rpm
error: Failed dependencies:
httpd-filesystem = 2.4.37-11.module_el8.0.0+172+85fc1f40 is needed by httpd-2.4.37-11.module_el8.0.0+172+85fc1f40.x86_64
httpd-tools = 2.4.37-11.module_el8.0.0+172+85fc1f40 is needed by httpd-2.4.37-11.module_el8.0.0+172+85fc1f40.x86_64
[10:22:38 root@centos8 yum.repos.d]#yum provides /etc/mime.types
Last metadata expiration check: 0:04:48 ago on Thu 13 Aug 2020 10:18:24 AM CST.
mailcap-2.1.48-3.el8.noarch : Helper application and MIME type associations for file types
Repo : @System
Matched from:
Filename : /etc/mime.types
mailcap-2.1.48-3.el8.noarch : Helper application and MIME type associations for file types
Repo : BaseOS
Matched from:
Filename : /etc/mime.types
[10:23:12 root@centos8 yum.repos.d]#yum deplist httpd
Last metadata expiration check: 0:05:22 ago on Thu 13 Aug 2020 10:18:24 AM CST.
package: httpd-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64
dependency: /bin/sh
provider: bash-4.4.19-10.el8.x86_64
dependency: /etc/mime.types
provider: mailcap-2.1.48-3.el8.noarch
dependency: httpd-filesystem
provider: httpd-filesystem-2.4.37-21.module_el8.2.0+382+15b0afa8.noarch
dependency: httpd-filesystem = 2.4.37-21.module_el8.2.0+382+15b0afa8
provider: httpd-filesystem-2.4.37-21.module_el8.2.0+382+15b0afa8.noarch
dependency: httpd-tools = 2.4.37-21.module_el8.2.0+382+15b0afa8
provider: httpd-tools-2.4.37-21.module_el8.2.0+382+15b0afa8.x86_64
dependency: libapr-1.so.0()(64bit)
provider: apr-1.6.3-9.el8.x86_64
dependency: libaprutil-1.so.0()(64bit)
provider: apr-util-1.6.1-6.el8.x86_64
dependency: libbrotlienc.so.1()(64bit)
provider: brotli-1.0.6-1.el8.x86_64
dependency: libc.so.6(GLIBC_2.14)(64bit)
provider: glibc-2.28-101.el8.x86_64
dependency: libcrypt.so.1()(64bit)
provider: libxcrypt-4.1.1-4.el8.x86_64
dependency: libcrypt.so.1(XCRYPT_2.0)(64bit)
provider: libxcrypt-4.1.1-4.el8.x86_64
dependency: libdl.so.2()(64bit)
provider: glibc-2.28-101.el8.x86_64
dependency: libexpat.so.1()(64bit)
provider: expat-2.2.5-3.el8.x86_64
dependency: liblua-5.3.so()(64bit)
provider: lua-libs-5.3.4-11.el8.x86_64
dependency: libm.so.6()(64bit)
provider: glibc-2.28-101.el8.x86_64
dependency: libpcre.so.1()(64bit)
provider: pcre-8.42-4.el8.x86_64
dependency: libpthread.so.0()(64bit)
provider: glibc-2.28-101.el8.x86_64
dependency: libpthread.so.0(GLIBC_2.2.5)(64bit)
provider: glibc-2.28-101.el8.x86_64
dependency: libselinux.so.1()(64bit)
provider: libselinux-2.9-3.el8.x86_64
dependency: libsystemd.so.0()(64bit)
provider: systemd-libs-239-31.el8_2.2.x86_64
dependency: libsystemd.so.0(LIBSYSTEMD_209)(64bit)
provider: systemd-libs-239-31.el8_2.2.x86_64
dependency: libz.so.1()(64bit)
provider: zlib-1.2.11-13.el8.x86_64
dependency: mod_http2
provider: mod_http2-1.11.3-3.module_el8.2.0+307+4d18d695.x86_64
dependency: rtld(GNU_HASH)
provider: glibc-2.28-101.el8.i686
provider: glibc-2.28-101.el8.x86_64
dependency: system-logos-httpd
provider: centos-logos-httpd-80.5-2.el8.noarch
dependency: systemd-units
provider: systemd-239-31.el8_2.2.i686
provider: systemd-239-31.el8_2.2.x86_64
范例: CentOS 8 查看未安装包的文件列表
[10:23:46 root@centos8 yum.repos.d]#rpm -q memcached
package memcached is not installed
[10:24:50 root@centos8 yum.repos.d]#dnf repoquery -l memcached
Last metadata expiration check: 0:06:37 ago on Thu 13 Aug 2020 10:18:24 AM CST.
/etc/sysconfig/memcached
/usr/bin/memcached
/usr/bin/memcached-tool
/usr/lib/.build-id
/usr/lib/.build-id/25
....
范例: CentOS 7 查看未安装包的文件列表
[10:01:27 root@centos7 yum.repos.d]#rpm -q memcached
package memcached is not installed
[10:25:46 root@centos7 yum.repos.d]#yum -y install yum-utils
[10:25:57 root@centos7 yum.repos.d]#repoquery -ql memcached
Repository base is listed more than once in the configuration
Repository epel is listed more than once in the configuration
/etc/sysconfig/memcached
/usr/bin/memcached
/usr/bin/memcached-tool
/usr/lib/systemd/system/memcached.service
...
仓库缓存
清除目录/var/cache/yum/缓存
yum clean [ packages | metadata | expire-cache | rpmdb | plugins | all ]
构建缓存
yum makecache
范例:管理yum缓存
[10:34:32 root@centos7 yum.repos.d]#du -sh /var/cache/yum/
554M /var/cache/yum/
[10:41:47 root@centos7 cache]#ls yum/
base epel timedhosts
[10:34:41 root@centos7 yum.repos.d]#yum clean all
Cleaning repos: base epel
[10:40:04 root@centos7 cache]#du -sh yum/
0 yum/
[10:40:08 root@centos7 cache]#yum makecache
[10:41:41 root@centos7 cache]#du -sh yum/
271M yum/
查看yum事务历史
yum 执行安装卸载命令会记录到相关日志中
日志文件:
#CentOS 7以前版本日志
/var/log/yum.log
#CentOS 8 版本日志
/var/log/dnf.rpm.log
/var/log/dnf.log
日志命令
yum history [info|list|packages-list|packages-info|summary|addon-info|redo|undo|rollback|new|sync|stats]
范例
[10:25:02 root@centos8 yum.repos.d]#dnf history
ID | Command line | Date and time | Action(s) | Altered
-------------------------------------------------------------------------------
16 | install -y zip unzip | 2020-08-10 11:55 | Install | 2
15 | install -y nmap | 2020-08-05 11:30 | Install | 2
14 | install net-tools* -y | 2020-08-05 09:34 | Install | 1
13 | install -y patch | 2020-08-04 09:38 | Install | 1
12 | install -y tree | 2020-08-03 14:15 | Install | 1
11 | install -y vim | 2020-08-03 08:05 | Install | 4
10 | install -y mail* | 2020-07-31 14:17 | Install | 19
9 | install -y postfix | 2020-07-31 14:13 | Install | 1
8 | install lsof | 2020-07-31 10:15 | Install | 1
7 | install -y bc | 2020-07-30 21:45 | Install | 1
6 | install -y man* | 2020-07-30 19:43 | Install | 3
5 | install -y dos2unix | 2020-07-29 16:22 | Install | 1
4 | install -y lrz* | 2020-07-29 16:18 | Install | 1
3 | install make -y | 2020-07-29 16:06 | Install | 1
2 | install -y wget* | 2020-07-29 16:02 | Install | 1
1 | | 2020-07-29 08:53 | Install | 398 EE
[10:45:47 root@centos8 yum.repos.d]#dnf history info 13
Transaction ID : 13
Begin time : Tue 04 Aug 2020 09:38:57 AM CST
Begin rpmdb : 429:a608f4d0c4ed6ccc39f12e69547814971ba2081d
End time : Tue 04 Aug 2020 09:38:58 AM CST (1 seconds)
End rpmdb : 430:9f9c11160ff1ce49707b3e46d251a7f4f60ac9e8
User : root <root>
Return-Code : Success
Releasever : 8
Command Line : install -y patch
Packages Altered:
Install patch-2.7.6-11.el8.x86_64 @base
[10:46:19 root@centos8 yum.repos.d]#dnf history undo 15
Removed:
nmap-2:7.70-5.el8.x86_64 nmap-ncat-2:7.70-5.el8.x86_64
Complete!
[10:46:19 root@centos8 yum.repos.d]#dnf history redo 15
安装和升级本地程序包
yum localinstall|install rpmfile1 [rpmfile2] [...]
yum localupdate|update rpmfile1 [rpmfile2] [...]
查看包的安全警报
yum updateinfo --summary|--list|--info
范例
[root@centos8 ~]#yum updateinfo summary
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Last metadata expiration check: 0:07:29 ago on Sun 14 Jun 2020 10:01:18 AM CST.
Updates Information Summary: available
1 Security notice(s)
1 Moderate Security notice(s)
[root@centos8 ~]#yum updateinfo
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Last metadata expiration check: 0:07:34 ago on Sun 14 Jun 2020 10:01:18 AM CST.
Updates Information Summary: available
1 Security notice(s)
1 Moderate Security notice(s)
[root@centos8 ~]#yum updateinfo all
Repository AppStream is listed more than once in the configuration
Repository extras is listed more than once in the configuration
Last metadata expiration check: 0:07:48 ago on Sun 14 Jun 2020 10:01:18 AM CST.
Updates Information Summary: all
1 Security notice(s)
1 Moderate Security notice(s)
1 Bugfix notice(s)
包组管理的相关命令
yum grouplist [hidden] [groupwildcard] [...]
yum groupinstall group1 [group2] [...]
yum groupupdate group1 [group2] [...]
yum groupremove group1 [group2] [...]
yum groupinfo group1 [...]
范例:最小化安装的系统安装图形环境
[10:48:05 root@centos8 yum.repos.d]#yum grouplist
Last metadata expiration check: 0:06:19 ago on Thu 13 Aug 2020 10:46:58 AM CST.
Available Environment Groups:
Server with GUI
Server
Workstation
KDE Plasma Workspaces
Virtualization Host
Custom Operating System
Installed Environment Groups:
Minimal Install
Available Groups:
Container Management
.NET Core Development
RPM Development Tools
Development Tools
Graphical Administration Tools
Headless Management
Legacy UNIX Compatibility
Network Servers
Scientific Support
Security Tools
Smart Card Support
System Tools
Fedora Packager
Xfce
[10:53:17 root@centos8 yum.repos.d]#yum groupinfo "Server with GUI"
Last metadata expiration check: 0:06:30 ago on Thu 13 Aug 2020 10:46:58 AM CST.
Environment Group: Server with GUI
Description: An integrated, easy-to-manage server with a graphical interface.
no group 'dns-server' from environment 'graphical-server-environment'
Mandatory Groups:
Common NetworkManager submodules
Container Management
Core
Fonts
GNOME
Guest Desktop Agents
Hardware Monitoring Utilities
Hardware Support
Headless Management
Internet Browser
Multimedia
Printing Client
Server product core
Standard
base-x
Optional Groups:
Basic Web Server
Debugging Tools
FTP Server
File and Storage Server
Guest Agents
Infiniband Support
Mail Server
Network File System Client
Network Servers
Performance Tools
Remote Desktop Clients
Remote Management for Linux
Virtualization Client
Virtualization Hypervisor
Virtualization Tools
Windows File Server
[10:53:28 root@centos8 yum.repos.d]#dnf groupinstall GNOME -y
[10:53:28 root@centos8 yum.repos.d]#init 5
实现私有yum仓库
下载所有yum仓库的相关包和meta 数据
#CentOS 8 dnf 工具集成
dnf reposync --help #查看帮助
#默认只下载rpm包,不下载 meta数据,需要指定--download-metadata 才能下载 meta
dnf reposync --repoid=REPOID --download-metadata -p /path
#CentOS 7 以前版本,reposync工具来自于
yum-utils包reposync --repoid=REPOID --download-metadata -p /path
创建私有yum仓库:
createrepo [options] <directory>
范例:创建局域网的基于Base的私有yum源
#仓库服务器配置
[10:53:28 root@centos8 yum.repos.d]#yum -y install httpd
[10:56:30 root@centos8 yum.repos.d]#systemctl enable --now httpd
[10:56:55 root@centos8 yum.repos.d]#mkdir /var/www/html/centos/8 -pv
mkdir: created directory '/var/www/html/centos'
mkdir: created directory '/var/www/html/centos/8'
[10:57:25 root@centos8 yum.repos.d]#mount /dev/sr0 /mnt
mount: /mnt: /dev/sr0 already mounted on /mnt.
[10:57:34 root@centos8 yum.repos.d]#cp -a /mnt/* /var/www/html/centos/8/
#yum客户端配置
[11:08:28 root@centos8 yum.repos.d]#cat test.repo
[BaseOS]
name=BaseOS
baseurl=http://10.0.0.101/centos/8/BaseOS
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial[
AppStream]
name=Appstream
baseurl=http://10.0.0.101/centos/8/AppStream/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
范例:下载阿里云的extras源,制作私有yum源
[11:08:59 root@centos8 yum.repos.d]#yum repolist
Last metadata expiration check: 0:22:38 ago on Thu 13 Aug 2020 10:46:58 AM CST.
repo id repo name status
AppStream AppStream 4,935
BaseOS BaseOS 1,673
epel EPEL 6,203
extras extras 23
[11:09:36 root@centos8 yum.repos.d]#dnf reposync --repoid=extras --download-metadata -p /var/www/html/centos
[11:10:29 root@centos8 yum.repos.d]#ls /var/www/html/centos/
8 extras
[11:10:45 root@centos8 yum.repos.d]#yum repolist
Last metadata expiration check: 0:00:30 ago on Thu 13 Aug 2020 11:10:25 AM CST.
repo id repo name status
AppStream AppStream 4,935
BaseOS BaseOS 1,673
epel EPEL 6,203
extras extras 23
[11:13:53 root@centos8 yum.repos.d]#cat test.repo
[BaseOS]
name=BaseOS
baseurl=http://10.0.0.101/centos/8/BaseOS
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial[
[AppStream]
name=Appstream
baseurl=http://10.0.0.101/centos/8/AppStream/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[extras]
name=extras
baseurl=http://10.0.0.101/centos/extras
[11:14:59 root@centos8 yum.repos.d]#yum --disablerepo=* --enablerepo=extras list available
[11:15:36 root@centos8 yum.repos.d]##yum -y install epel-release
范例:下载阿里云的EPEL源,制作私有yum源
[11:15:36 root@centos8 yum.repos.d]#cat base.repo
[epel]
name=EPEL
baseurl=https://mirrors.aliyun.com/epel/$releasever/Everything/$basearch
https://mirrors.huaweicloud.com/epel/8/Everything/x86_64/
gpgcheck=0
enabled=1
[11:17:27 root@centos8 yum.repos.d]#dnf repolist
Last metadata expiration check: 0:07:40 ago on Thu 13 Aug 2020 11:10:25 AM CST.
repo id repo name status
AppStream AppStream 4,935
BaseOS BaseOS 1,673
epel EPEL 6,203
extras extras 23
#下载相关仓库包和元数据
[11:40:13 root@centos8 yum.repos.d]#dnf reposync --repoid=epel --download-metadata -p /var/www/html
#--download-metadata 加此选项可以下载元数据
#下载相关的key文件
[11:41:16 root@centos8 yum.repos.d]#wget -P /var/www/html/epel/ https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
#下面两个步骤只有没meta数据才需要执行
#[root@centos8 ~]#dnf -y install createrepo httpd
#[root@centos8 ~]#createrepo /var/www/html/epel/
[11:41:16 root@centos8 yum.repos.d]#ls /var/www/html/epel/
Packages repodata RPM-GPG-KEY-EPEL-8
[11:44:56 root@centos8 yum.repos.d]#cat test.repo
[BaseOS]
name=BaseOS
baseurl=http://10.0.0.101/centos/8/BaseOS
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial[
[AppStream]
name=Appstream
baseurl=http://10.0.0.101/centos/8/AppStream/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
[extras]
name=extras
baseurl=http://10.0.0.101/centos/extras
[epel]
name=epel
baseurl=http://10.0.0.101/epel/gpg
key=http://10.0.0.8/epel/RPM-GPG-KEY-EPEL-8
[11:44:46 root@centos8 yum.repos.d]#yum repolist
Last metadata expiration check: 0:25:35 ago on Thu 13 Aug 2020 11:19:20 AM CST.
repo id repo name status
AppStream AppStream 4,935
BaseOS BaseOS 1,673
epel EPEL 6,203
extras extras 23
[11:45:14 root@centos8 yum.repos.d]#dnf install openvpn
DNF 介绍
DNF,即DaNdiFied,是新一代的RPM软件包管理器。DNF 发行日期是2015年5月11日,DNF 包管理器采用Python 编写,发行许可为GPL v2,首先出现在Fedora 18 发行版中。在 RHEL 8.0 版本正式取代了 YUM,DNF包管理器克服了YUM包管理器的一些瓶颈,提升了包括用户体验,内存占用,依赖分析,运行速度等
配置文件:
/etc/dnf/dnf.conf
仓库文件:
/etc/yum.repos.d/ *.repo
日志:
/var/log/dnf.rpm.log
/var/log/dnf.log
DNF 使用帮助:man dnf
dnf 用法与yum一致
dnf [options] <command> [<arguments>...]
dnf --versiondnf repolist
dnf reposync
dnf install httpd
dnf remove httpd
dnf clean all
dnf makecache
dnf list installed
dnf list available
dnf search nano
dnf history undo 1
CentOS 7 使用 dnf ,下载并安装下面包
wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/dnf-conf-0.6.4-2.sdl7.noarch.rpm wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/dnf-0.6.4-2.sdl7.noarch.rpm wget http://springdale.math.ias.edu/data/puias/unsupported/7/x86_64/python-dnf-0.6.4-2.sdl7.noarch.rpm wget https://mirrors.aliyun.com/centos/7/extras/x86_64/Packages/python2-libcomps-0.1.8-12.el7.x86_64.rpmwget https://mirrors.aliyun.com/centos/7/extras/x86_64/Packages/libcomps-0.1.8-12.el7.x86_64.rpm
yum Troubleshooting( 发现并修理故障 )
yum 和 dnf 失败最主要原因:
-
yum的配置文件格式或路径错误
解决方法:检查/etc/yum.repos.d/*.repo文件格式
-
yum cache
解决方法:yum clean all
-
网络不通:
解决方法:网卡配置