签到成功

知道了

CNDBA社区CNDBA社区

Linux 8 中默认包管理工具 DNF 说明

2020-10-30 21:22 4371 0 原创 Linux
作者: dave

1 DNF 概述

Linux 6 和7 是一个跨度有点大的2个linux 版本,主要体现在一些管理工具和命令上。 所以如果要想用好Linux 7+以上版本的Linux,就必须学习这些新的管理方式和命令。

在之前的博客中,我们已经了解到了Linux 7中的网络管理工具:nmcli,如下:http://www.cndba.cn/cndba/dave/article/4289

Linux 7 中网络配置管理(nmcli工具) 说明
https://www.cndba.cn/cndba/dave/article/151

在本片博客中,我们将介绍Linux 8中的包管理工具:DNF。 http://www.cndba.cn/cndba/dave/article/4289

关于dnf, 有一篇英文的介绍,链接如下,可以参考:http://www.cndba.cn/cndba/dave/article/4289

https://dnf.readthedocs.io/en/latest/index.html

http://www.cndba.cn/cndba/dave/article/4289

简单的来说,DNF(Dandified Yum)是新一代的RPM软件包管理器。 DNF包管理器克服了YUM包管理器的一些瓶颈,提升了包括用户体验,内存占用,依赖分析,运行速度等多方面的内容。

从Linux 8开始,Linux 已经将默认的包管理工具替换成了DNF,而不是以前版本中的YUM。

Linux yum 命令介绍
https://www.cndba.cn/Dave/article/709

在RHEL或CentOS7系统中默认没有安装DNF,但可以在使用YUM的同时使用DNF。

安装epel-release依赖:yum install epel-release
安装DNF包:yum install dnf 或者 yum install dnf -y

dnf命令说明:

[root@www.cndba.cn ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 8.3 Beta (Ootpa)
[root@www.cndba.cn ~]#
[root@www.cndba.cn ~]# uname -a
Linux Dave 4.18.0-221.el8.x86_64 #1 SMP Thu Jun 25 20:58:19 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@www.cndba.cn ~]# man dnf
DNF(8)                                                   DNF                                                  DNF(8)

NAME
       dnf - DNF Command Reference

SYNOPSIS
       dnf [options] <command> [<args>...]

DESCRIPTION
       DNF  is  the  next  upcoming  major  version  of YUM, a package manager for RPM-based Linux distributions. It roughly maintains CLI compatibility with YUM and defines a strict API for extensions and plugins.
       Plugins can modify or extend features of DNF or provide additional CLI commands on  top  of  those  mentioned below.  If you know the name of such a command (including commands mentioned below), you may find/install the package which provides it using the appropriate virtual provide in the form  of  dnf-command(<alias>),  where  <alias>  is  the  name  of the command; e.g.``dnf install 'dnf-command(versionlock)'`` installs a versionlock plugin. This approach also applies to specifying dependencies of packages that require a particular DNF  command.

       Return values:
       · 0  : Operation was successful.
       · 1  : An error occurred, which was handled by dnf.
       · 3  : An unknown unhandled error occurred during operation.
       · 100: See check-update
       · 200: There was a problem with acquiring or releasing of locks.
       Available commands:
       · alias
       · autoremove
……

2 DNF 全局配置文件

DNF 默认使用的全局配置文件是/etc/dnf/dnf.conf, 所有*.repo 源文件都在/etc/yum.repos.d 目录下。 并且源文件里配置的优先级要高于全局配置文件,dnf.conf。

[root@www.cndba.cn ~]# cd /etc/dnf
[root@www.cndba.cn dnf]# ls
aliases.d  dnf.conf  modules.d  modules.defaults.d  plugins  protected.d  vars
[root@www.cndba.cn dnf]# cat dnf.conf
[main]
gpgcheck=1
installonly_limit=3
clean_requirements_on_remove=True
best=True
skip_if_unavailable=False
[root@www.cndba.cn dnf]# man dnf.conf
DNF.CONF(5)                                              DNF                                             DNF.CONF(5)

NAME
       dnf.conf - DNF Configuration Reference

DESCRIPTION
       DNF  by  default  uses  the  global  configuration file at /etc/dnf/dnf.conf and all *.repo files found under
       /etc/yum.repos.d. The latter is typically used for repository configuration and takes precedence over  global
       configuration.

       The  configuration file has INI format consisting of section declaration and name=value options below each on
       separate line. There are two types of sections in the configuration files: main and repository. Main  section
       defines all global configuration options and should be only one.

       The  repository  sections define the configuration for each (remote or local) repository. The section name of
       the repository in brackets serve as repo ID reference and should be unique across  configuration  files.  The
       allowed characters of repo ID string are lower and upper case alphabetic letters, digits, -, _, .  and :. The
       minimal repository configuration file should aside from repo ID consists of baseurl, metalink  or  mirrorlist
       option definition.

DISTRIBUTION-SPECIFIC CONFIGURATION
       Configuration  options, namely best and skip_if_unavailable, can be set in the DNF configuration file by your
       distribution to override the DNF defaults.

[MAIN] OPTIONS
       arch   string

              The architecture used for installing packages. By default this is auto-detected. Often  used  together
              with ignorearch option.
……

3 DNF 源配置文件

从我们使用角度来说,最主要的就是配置DNF的源文件。

在RHEL8中把软件源分成了两部分,BaseOS 和AppStream。

  1. BaseOS 存储库:BaseOS 存储库以传统 RPM 包的形式提供底层核心 OS 内容。
  2. AppStream 存储库:Application Stream 存储库提供用户可能希望在给定用户空间中运行的所有应用程序。

在使用本地ISO镜像做源时,针对这2种类型的源,需要分别进行配置。

Linux 8 之前的yum源配置可以参考我之前的博客:

Linux 平台下 yum 源 配置 手册
https://www.cndba.cn/dave/article/154http://www.cndba.cn/cndba/dave/article/4289

3.1 Linux 8 中使用在线源

在服务器能联网的情况下,可以直接使用在线的dnf源。

下载dnf源:

http://www.cndba.cn/cndba/dave/article/4289

[root@www.cndba.cn yum.repos.d]# curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2595  100  2595    0     0  25441      0 --:--:-- --:--:-- --:--:-- 25441

查看dnf 源:

[root@www.cndba.cn dnf]# dnf repolist
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

repo id                                     repo name
AppStream                                   CentOS-8 - AppStream - mirrors.aliyun.com
base                                        CentOS-8 - Base - mirrors.aliyun.com
extras                                      CentOS-8 - Extras - mirrors.aliyun.com
[root@www.cndba.cn dnf]#

这里显示了3个repo 源。

查看源文件的具体内容:

[root@www.cndba.cn yum.repos.d]# ls
CentOS-Base.repo  redhat.repo
[root@www.cndba.cn yum.repos.d]# cat 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-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

[PowerTools]
name=CentOS-$releasever - PowerTools - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/PowerTools/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/PowerTools/$basearch/os/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

[AppStream]
name=CentOS-$releasever - AppStream - mirrors.aliyun.com
failovermethod=priority
baseurl=https://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
        http://mirrors.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos/$releasever/AppStream/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official
[root@www.cndba.cn yum.repos.d]#

3.2 使用本地DNF源

如果服务器不能联网,那么可以直接使用ISO 镜像做源。

将ISO 文件挂载到系统:

http://www.cndba.cn/cndba/dave/article/4289

[root@www.cndba.cn dnf]# mount /dev/cdrom /mnt
mount: /mnt: WARNING: device write-protected, mounted read-only.
[root@www.cndba.cn dnf]# ls /mnt
AppStream  EFI   extra_files.json  images    media.repo               RPM-GPG-KEY-redhat-release
BaseOS     EULA  GPL               isolinux  RPM-GPG-KEY-redhat-beta  TRANS.TBL
[root@www.cndba.cn dnf]#

创建源文件:dave.repohttp://www.cndba.cn/cndba/dave/article/4289

[root@www.cndba.cn yum.repos.d]# cat /etc/yum.repos.d/dave.repo
[dave-AppStream]
name=AppStream
baseurl=file:///mnt/AppStream
gpgcheck=0
enabled=1

[dave-BaseOS]
name=BaseOS
baseurl=file:///mnt/BaseOS
gpgcheck=0
enabled=1
[root@www.cndba.cn yum.repos.d]#

清空并重建cache:http://www.cndba.cn/cndba/dave/article/4289

[root@www.cndba.cn yum.repos.d]# dnf clean all
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

18 files removed
[root@www.cndba.cn yum.repos.d]# dnf makecache
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

CentOS-8 - Base - mirrors.aliyun.com                                                   4.3 MB/s | 2.2 MB     00:00
CentOS-8 - Extras - mirrors.aliyun.com                                                  25 kB/s | 8.1 kB     00:00
CentOS-8 - AppStream - mirrors.aliyun.com                                               10 MB/s | 5.8 MB     00:00
AppStream                                                                              296 MB/s | 6.3 MB     00:00
BaseOS                                                                                 159 MB/s | 2.3 MB     00:00
Metadata cache created.
[root@www.cndba.cn yum.repos.d]#

与linux 8之前的yum 源配置基本参数都是一样的,唯一的区别就是要分别配置好BaseOS和AppStream。

4 DNF 命令

dnf 的命令与yum 基本都是兼容的,所以这里不再具体命令,直接将dnf的命令帮助列举如下:

[root@www.cndba.cn ~]# dnf -v
Loaded plugins: builddep, changelog, config-manager, copr, debug, debuginfo-install, download, generate_completion_cache, needs-restarting, playground, product-id, repoclosure, repodiff, repograph, repomanage, reposync, subscription-manager, uploadprofile
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

usage: dnf [options] COMMAND

List of Main Commands:

alias                     List or create command aliases
autoremove                remove all unneeded packages that were originally installed as dependencies
check                     check for problems in the packagedb
check-update              check for available package upgrades
clean                     remove cached data
deplist                   List package's dependencies and what packages provide them
distro-sync               synchronize installed packages to the latest available versions
downgrade                 Downgrade a package
group                     display, or use, the groups information
help                      display a helpful usage message
history                   display, or use, the transaction history
info                      display details about a package or group of packages
install                   install a package or packages on your system
list                      list a package or groups of packages
makecache                 generate the metadata cache
mark                      mark or unmark installed packages as installed by user.
module                    Interact with Modules.
provides                  find what package provides the given value
reinstall                 reinstall a package
remove                    remove a package or packages from your system
repolist                  display the configured software repositories
repoquery                 search for packages matching keyword
repository-packages       run commands on top of all packages in given repository
search                    search package details for the given string
shell                     run an interactive DNF shell
swap                      run an interactive DNF mod for remove and install one spec
updateinfo                display advisories about packages
upgrade                   upgrade a package or packages on your system
upgrade-minimal           upgrade, but only 'newest' package match which fixes a problem that affects your system

List of Plugin Commands:

builddep                  Install build dependencies for package or spec file
changelog                 Show changelog data of packages
config-manager            manage dnf configuration options and repositories
copr                      Interact with Copr repositories.
debug-dump                dump information about installed rpm packages to file
debug-restore             restore packages recorded in debug-dump file
debuginfo-install         install debuginfo packages
download                  Download package to current directory
needs-restarting          determine updated binaries that need restarting
playground                Interact with Playground repository.
repoclosure               Display a list of unresolved dependencies for repositories
repodiff                  List differences between two sets of repositories
repograph                 Output a full package dependency graph in dot format
repomanage                Manage a directory of rpm packages
reposync                  download all packages from remote repo
uploadprofile             Upload combined profile to Satellite server (list of installed rpms, enabled repositories and modules

General DNF options:
  -c [config file], --config [config file]
                        config file location
  -q, --quiet           quiet operation
  -v, --verbose         verbose operation
  --version             show DNF version and exit
  --installroot [path]  set install root
  --nodocs              do not install documentations
  --noplugins           disable all plugins
  --enableplugin [plugin]
                        enable plugins by name
  --disableplugin [plugin]
                        disable plugins by name
  --releasever RELEASEVER
                        override the value of $releasever in config and repo
                        files
  --setopt SETOPTS      set arbitrary config and repo options
  --skip-broken         resolve depsolve problems by skipping packages
  -h, --help, --help-cmd
                        show command help
  --allowerasing        allow erasing of installed packages to resolve
                        dependencies
  -b, --best            try the best available package versions in
                        transactions.
  --nobest              do not limit the transaction to the best candidate
  -C, --cacheonly       run entirely from system cache, don't update cache
  -R [minutes], --randomwait [minutes]
                        maximum command wait time
  -d [debug level], --debuglevel [debug level]
                        debugging output level
  --debugsolver         dumps detailed solving results into files
  --showduplicates      show duplicates, in repos, in list/search commands
  -e ERRORLEVEL, --errorlevel ERRORLEVEL
                        error output level
  --obsoletes           enables dnf's obsoletes processing logic for upgrade
                        or display capabilities that the package obsoletes for
                        info, list and repoquery
  --rpmverbosity [debug level name]
                        debugging output level for rpm
  -y, --assumeyes       automatically answer yes for all questions
  --assumeno            automatically answer no for all questions
  --enablerepo [repo]   Enable additional repositories. List option. Supports
                        globs, can be specified multiple times.
  --disablerepo [repo]  Disable repositories. List option. Supports globs, can
                        be specified multiple times.
  --repo [repo], --repoid [repo]
                        enable just specific repositories by an id or a glob,
                        can be specified multiple times
  --enable              enable repos with config-manager command
                        (automatically saves)
  --disable             disable repos with config-manager command
                        (automatically saves)
  -x [package], --exclude [package], --excludepkgs [package]
                        exclude packages by name or glob
  --disableexcludes [repo], --disableexcludepkgs [repo]
                        disable excludepkgs
  --repofrompath [repo,path]
                        label and path to an additional repository to use
                        (same path as in a baseurl), can be specified multiple
                        times.
  --noautoremove        disable removal of dependencies that are no longer
                        used
  --nogpgcheck          disable gpg signature checking (if RPM policy allows)
  --color COLOR         control whether color is used
  --refresh             set metadata as expired before running the command
  -4                    resolve to IPv4 addresses only
  -6                    resolve to IPv6 addresses only
  --destdir DESTDIR, --downloaddir DESTDIR
                        set directory to copy packages to
  --downloadonly        only download packages
  --comment COMMENT     add a comment to transaction
  --bugfix              Include bugfix relevant packages, in updates
  --enhancement         Include enhancement relevant packages, in updates
  --newpackage          Include newpackage relevant packages, in updates
  --security            Include security relevant packages, in updates
  --advisory ADVISORY, --advisories ADVISORY
                        Include packages needed to fix the given advisory, in
                        updates
  --bz BUGZILLA, --bzs BUGZILLA
                        Include packages needed to fix the given BZ, in
                        updates
  --cve CVES, --cves CVES
                        Include packages needed to fix the given CVE, in
                        updates
  --sec-severity {Critical,Important,Moderate,Low}, --secseverity {Critical,Important,Moderate,Low}
                        Include security relevant packages matching the
                        severity, in updates
  --forcearch ARCH      Force the use of an architecture
[root@www.cndba.cn ~]#

使用DNF 安装dstat 工具:http://www.cndba.cn/cndba/dave/article/4289

[root@www.cndba.cn yum.repos.d]# dnf install dstat
Updating Subscription Management repositories.
Unable to read consumer identity

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Last metadata expiration check: 0:00:18 ago on Fri 30 Oct 2020 09:15:43 PM CST.
Dependencies resolved.
=======================================================================================================================
 Package                        Architecture         Version                        Repository                    Size
=======================================================================================================================
Installing:
 pcp-system-tools               x86_64               5.1.1-3.el8                    dave-AppStream               191 k
Installing dependencies:
 libuv                          x86_64               1:1.38.0-1.el8                 dave-AppStream               151 k
 pcp                            x86_64               5.1.1-3.el8                    dave-AppStream               1.2 M
 pcp-conf                       x86_64               5.1.1-3.el8                    dave-AppStream                50 k
 pcp-libs                       x86_64               5.1.1-3.el8                    dave-AppStream               536 k
 pcp-selinux                    x86_64               5.1.1-3.el8                    dave-AppStream                47 k
 python3-pcp                    x86_64               5.1.1-3.el8                    dave-AppStream               167 k

Transaction Summary
=======================================================================================================================
Install  7 Packages

Total size: 2.3 M
Installed size: 6.8 M
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                               1/1
  Installing       : libuv-1:1.38.0-1.el8.x86_64                                                                   1/7
  Installing       : pcp-selinux-5.1.1-3.el8.x86_64                                                                2/7
  Running scriptlet: pcp-selinux-5.1.1-3.el8.x86_64                                                                2/7
  Installing       : pcp-conf-5.1.1-3.el8.x86_64                                                                   3/7
  Installing       : pcp-libs-5.1.1-3.el8.x86_64                                                                   4/7
  Running scriptlet: pcp-5.1.1-3.el8.x86_64                                                                        5/7
  Installing       : pcp-5.1.1-3.el8.x86_64                                                                        5/7
  Running scriptlet: pcp-5.1.1-3.el8.x86_64                                                                        5/7
  Installing       : python3-pcp-5.1.1-3.el8.x86_64                                                                6/7
  Installing       : pcp-system-tools-5.1.1-3.el8.x86_64                                                           7/7
  Running scriptlet: pcp-system-tools-5.1.1-3.el8.x86_64                                                           7/7
  Verifying        : libuv-1:1.38.0-1.el8.x86_64                                                                   1/7
  Verifying        : pcp-5.1.1-3.el8.x86_64                                                                        2/7
  Verifying        : pcp-conf-5.1.1-3.el8.x86_64                                                                   3/7
  Verifying        : pcp-libs-5.1.1-3.el8.x86_64                                                                   4/7
  Verifying        : pcp-selinux-5.1.1-3.el8.x86_64                                                                5/7
  Verifying        : pcp-system-tools-5.1.1-3.el8.x86_64                                                           6/7
  Verifying        : python3-pcp-5.1.1-3.el8.x86_64                                                                7/7
Installed products updated.

Installed:
  libuv-1:1.38.0-1.el8.x86_64          pcp-5.1.1-3.el8.x86_64               pcp-conf-5.1.1-3.el8.x86_64
  pcp-libs-5.1.1-3.el8.x86_64          pcp-selinux-5.1.1-3.el8.x86_64       pcp-system-tools-5.1.1-3.el8.x86_64
  python3-pcp-5.1.1-3.el8.x86_64

Complete!
[root@www.cndba.cn yum.repos.d]#

版权声明:本文为博主原创文章,未经博主允许不得转载。

用户评论
* 以下用户言论只代表其个人观点,不代表CNDBA社区的观点或立场
dave

dave

关注

人的一生应该是这样度过的:当他回首往事的时候,他不会因为虚度年华而悔恨,也不会因为碌碌无为而羞耻;这样,在临死的时候,他就能够说:“我的整个生命和全部精力,都已经献给世界上最壮丽的事业....."

  • 2296
    原创
  • 3
    翻译
  • 582
    转载
  • 198
    评论
  • 访问:8503233次
  • 积分:4477
  • 等级:核心会员
  • 排名:第1名
精华文章
    最新问题
    查看更多+
    热门文章
      热门用户
      推荐用户
        Copyright © 2016 All Rights Reserved. Powered by CNDBA · 皖ICP备2022006297号-1·

        QQ交流群

        注册联系QQ