1. 首页 > Linux教程 > 正文

Linux教程FG103-dnf install命令(软件包/包组安装)

本文档风哥主要介绍dnf install命令的使用,包括dnf install命令的概念、dnf install命令语法、dnf install命令常用选项、dnf install基础操作详解、dnf group install包组安装详解、dnf install高级使用技巧、Web服务器安装实战案例、数据库服务器安装实战案例、软件包安装故障排查与解决等内容,参考Red Hat Enterprise Linux 10官方文档,适合Linux运维人员在学习和测试中使用,如果要应用于生产环境则需要自行确认。

Part01-基础概念与理论知识

1.1 dnf install命令的概念

dnf install命令是DNF软件包管理器中最常用的命令之一,用于安装软件包和软件包组。dnf install命令会自动解析依赖关系,并安装所需的依赖软件包。更多视频教程www.fgedu.net.cn

dnf install命令的主要特点:

  • 自动解析依赖关系
  • 支持软件包和包组安装
  • 支持本地和远程软件包
  • 支持事务回滚
  • 支持下载后安装
  • 支持GPG签名验证

1.2 dnf install命令语法

dnf install命令语法:

  • 基本语法:dnf install [选项] [软件包]
  • 安装单个软件包:dnf install nginx
  • 安装多个软件包:dnf install nginx httpd
  • 安装本地软件包:dnf install /path/to/package.rpm
  • 安装包组:dnf group install “Development Tools”

1.3 dnf install命令常用选项

dnf install命令常用选项:

  • -y, –assumeyes:自动回答yes
  • –assumeno:自动回答no
  • –downloadonly:仅下载不安装
  • –downloaddir DIR:指定下载目录
  • –allowerasing:允许删除冲突软件包
  • –best:选择最佳软件包
  • –nobest:不选择最佳软件包
  • –skipunavailable:跳过不可用软件包
  • –enablerepo REPO:临时启用存储库
  • –disablerepo REPO:临时禁用存储库
风哥提示:dnf install命令是DNF软件包管理器中最常用的命令之一,建议熟练掌握。安装前可以先使用dnf search或dnf info查看软件包信息。

Part02-生产环境规划与建议

2.1 软件包安装在生产环境的规划

软件包安装在生产环境的规划要点:

# 软件包安装生产环境规划
– 在测试环境先测试安装
– 检查软件包依赖关系
– 检查磁盘空间是否充足
– 备份重要数据
– 使用-y选项自动确认
– 使用–downloadonly仅下载不安装

# 软件包版本规划
– 使用稳定版本
– 避免使用测试版本
– 定期更新软件包
– 关注安全更新
– 测试环境先测试

2.2 软件包安装最佳实践

软件包安装最佳实践:

  • 测试环境:在测试环境先测试安装
  • 依赖检查:检查软件包依赖关系
  • 备份:安装前备份重要数据
  • 磁盘空间:检查磁盘空间是否充足
  • 版本选择:使用稳定版本
  • 定期更新:定期更新软件包

2.3 软件包安装安全配置建议

软件包安装安全配置建议:

  • GPG检查:启用GPG签名验证
  • 官方存储库:使用官方或可信的存储库
  • 最小权限:使用sudo执行安装命令
  • 审计日志:启用DNF审计日志
  • 安全更新:及时安装安全更新
生产环境建议:在测试环境先测试安装,检查软件包依赖关系,备份重要数据,使用稳定版本。学习交流加群风哥微信: itpux-com

Part03-生产环境项目实施方案

3.1 dnf install基础操作详解

3.1.1 安装单个软件包

# 安装nginx软件包
# dnf install nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 586 k
Installed size: 1.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/3): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(2/3): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(3/3): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 586 kB/s | 586 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : nginx-filesystem-1.22.1-2.el9.noarch 1/3
Installing : nginx-core-1.22.1-2.el9.x86_64 2/3
Installing : nginx-1.22.1-2.el9.x86_64 3/3
Running scriptlet: nginx-1.22.1-2.el9.x86_64 3/3
Verifying : nginx-1.22.1-2.el9.x86_64 1/3
Verifying : nginx-core-1.22.1-2.el9.x86_64 2/3
Verifying : nginx-filesystem-1.22.1-2.el9.noarch 3/3

Complete!

# 验证nginx已安装
# rpm -qa | grep nginx
nginx-1.22.1-2.el9.x86_64
nginx-core-1.22.1-2.el9.x86_64
nginx-filesystem-1.22.1-2.el9.noarch

3.1.2 安装多个软件包

# 安装多个软件包
# dnf install nginx httpd
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
httpd x86_64 2.4.53-7.el9 appstream 1.4 M
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
apr x86_64 1.7.0-11.el9 appstream 123 k
apr-util x86_64 1.6.1-20.el9 appstream 89 k
httpd-core x86_64 2.4.53-7.el9 appstream 1.2 M
httpd-filesystem noarch 2.4.53-7.el9 appstream 11 k
httpd-tools x86_64 2.4.53-7.el9 appstream 92 k
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k
mailcap noarch 2.1.49-5.el9 appstream 31 k

Transaction Summary
================================================================================
Install 10 Packages

Total download size: 3.5 M
Installed size: 11.2 M
Is this ok [y/N]: y
Downloading Packages:
(1/10): apr-1.7.0-11.el9.x86_64.rpm 123 kB/s | 123 kB 00:00
(2/10): apr-util-1.6.1-20.el9.x86_64.rpm 89 kB/s | 89 kB 00:00
(3/10): httpd-filesystem-2.4.53-7.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(4/10): httpd-tools-2.4.53-7.el9.x86_64.rpm 92 kB/s | 92 kB 00:00
(5/10): mailcap-2.1.49-5.el9.noarch.rpm 31 kB/s | 31 kB 00:00
(6/10): httpd-core-2.4.53-7.el9.x86_64.rpm 1.2 MB/s | 1.2 MB 00:00
(7/10): httpd-2.4.53-7.el9.x86_64.rpm 1.4 MB/s | 1.4 MB 00:00
(8/10): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(9/10): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
(10/10): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
——————————————————————————–
Total 3.5 MB/s | 3.5 MB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : apr-1.7.0-11.el9.x86_64 1/10
Installing : apr-util-1.6.1-20.el9.x86_64 2/10
Installing : httpd-core-2.4.53-7.el9.x86_64 3/10
Installing : httpd-2.4.53-7.el9.x86_64 4/10
Installing : httpd-filesystem-2.4.53-7.el9.noarch 5/10
Installing : httpd-tools-2.4.53-7.el9.x86_64 6/10
Installing : mailcap-2.1.49-5.el9.noarch 7/10
Installing : nginx-filesystem-1.22.1-2.el9.noarch 8/10
Installing : nginx-core-1.22.1-2.el9.x86_64 9/10
Installing : nginx-1.22.1-2.el9.x86_64 10/10
Running scriptlet: httpd-2.4.53-7.el9.x86_64 10/10
Verifying : apr-1.7.0-11.el9.x86_64 1/10
Verifying : apr-util-1.6.1-20.el9.x86_64 2/10
Verifying : httpd-core-2.4.53-7.el9.x86_64 3/10
Verifying : httpd-2.4.53-7.el9.x86_64 4/10
Verifying : httpd-filesystem-2.4.53-7.el9.noarch 5/10
Verifying : httpd-tools-2.4.53-7.el9.x86_64 6/10
Verifying : mailcap-2.1.49-5.el9.noarch 7/10
Verifying : nginx-filesystem-1.22.1-2.el9.noarch 8/10
Verifying : nginx-core-1.22.1-2.el9.x86_64 9/10
Verifying : nginx-1.22.1-2.el9.x86_64 10/10

Complete!

# 验证软件包已安装
# rpm -qa | grep -E “nginx|httpd”
nginx-1.22.1-2.el9.x86_64
nginx-core-1.22.1-2.el9.x86_64
nginx-filesystem-1.22.1-2.el9.noarch
httpd-2.4.53-7.el9.x86_64
httpd-core-2.4.53-7.el9.x86_64
httpd-filesystem-2.4.53-7.el9.noarch
httpd-tools-2.4.53-7.el9.x86_64

3.2 dnf group install包组安装详解

3.2.1 查看可用包组

# 查看所有可用包组
# dnf group list
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Available Environment Groups:
Server with GUI
Minimal Install
Workstation
Custom Operating System

Installed Groups:
Core

Available Groups:
Development Tools
Headless Management
Legacy UNIX Compatibility
Network Servers
RPM Development Tools
Scientific Support
Security Tools
Smart Card Support
System Tools

# 查看包组详情
# dnf group info “Development Tools”
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Group: Development Tools
Description: A basic development environment.
Mandatory Packages:
autoconf
automake
binutils
bison
flex
gcc
gcc-c++
gdb
glibc-devel
libtool
make
patch
pkgconf
pkgconf-m4
pkgconfig
redhat-rpm-config
rpm-build
rpm-sign
strace
Default Packages:
byacc
cscope
diffstat
doxygen
elfutils
git
indent
intltool
patchutils
rcs
subversion
swig
systemtap
Optional Packages:
ccache
cmake
cvs
expect
gcc-gfortran
gettext
libstdc++-docs
mercurial
rpmdevtools
rpmlint
valgrind

3.2.2 安装包组

# 安装Development Tools包组
# dnf group install “Development Tools”
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing Groups:
Development Tools

Installing:
autoconf noarch 2.69-38.el9 appstream 710 k
automake noarch 1.16.2-6.el9 appstream 712 k
binutils x86_64 2.35.2-37.el9 baseos 5.6 M
bison x86_64 3.7.4-5.el9 appstream 1.1 M
flex x86_64 2.6.4-8.el9 appstream 338 k
gcc x86_64 11.3.1-4.1.el9 appstream 32 M
gcc-c++ x86_64 11.3.1-4.1.el9 appstream 12 M
gdb x86_64 10.2-5.el9 appstream 3.8 M
glibc-devel x86_64 2.34-60.el9 baseos 1.5 M
libtool x86_64 2.4.6-45.el9 appstream 588 k
make x86_64 1:4.3-7.el9 baseos 589 k
patch x86_64 2.7.6-16.el9 baseos 110 k
pkgconf x86_64 1.7.3-10.el9 baseos 40 k
pkgconf-m4 noarch 1.7.3-10.el9 baseos 14 k
pkgconfig x86_64 1:0.27.1-4.el9 baseos 35 k
redhat-rpm-config noarch 197-1.el9 appstream 66 k
rpm-build x86_64 4.16.1.3-25.el9 baseos 123 k
rpm-sign x86_64 4.16.1.3-25.el9 baseos 23 k
strace x86_64 5.18-2.el9 appstream 1.5 M

Transaction Summary
================================================================================
Install 19 Packages

Total download size: 61.2 M
Installed size: 223.4 M
Is this ok [y/N]: y
Downloading Packages:
(1/19): autoconf-2.69-38.el9.noarch.rpm 710 kB/s | 710 kB 00:00
(2/19): automake-1.16.2-6.el9.noarch.rpm 712 kB/s | 712 kB 00:00
(3/19): patch-2.7.6-16.el9.x86_64.rpm 110 kB/s | 110 kB 00:00
(4/19): pkgconf-m4-1.7.3-10.el9.noarch.rpm 14 kB/s | 14 kB 00:00
(5/19): pkgconf-1.7.3-10.el9.x86_64.rpm 40 kB/s | 40 kB 00:00
(6/19): pkgconfig-1:0.27.1-4.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(7/19): rpm-sign-4.16.1.3-25.el9.x86_64.rpm 23 kB/s | 23 kB 00:00
(8/19): rpm-build-4.16.1.3-25.el9.x86_64.rpm 123 kB/s | 123 kB 00:00
(9/19): redhat-rpm-config-197-1.el9.noarch.rpm 66 kB/s | 66 kB 00:00
(10/19): libtool-2.4.6-45.el9.x86_64.rpm 588 kB/s | 588 kB 00:00
(11/19): flex-2.6.4-8.el9.x86_64.rpm 338 kB/s | 338 kB 00:00
(12/19): make-1:4.3-7.el9.x86_64.rpm 589 kB/s | 589 kB 00:00
(13/19): strace-5.18-2.el9.x86_64.rpm 1.5 MB/s | 1.5 MB 00:00
(14/19): bison-3.7.4-5.el9.x86_64.rpm 1.1 MB/s | 1.1 MB 00:00
(15/19): glibc-devel-2.34-60.el9.x86_64.rpm 1.5 MB/s | 1.5 MB 00:00
(16/19): gdb-10.2-5.el9.x86_64.rpm 3.8 MB/s | 3.8 MB 00:00
(17/19): binutils-2.35.2-37.el9.x86_64.rpm 5.6 MB/s | 5.6 MB 00:00
(18/19): gcc-c++-11.3.1-4.1.el9.x86_64.rpm 12 MB/s | 12 MB 00:00
(19/19): gcc-11.3.1-4.1.el9.x86_64.rpm 32 MB/s | 32 MB 00:00
——————————————————————————–
Total 61.2 MB/s | 61.2 MB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : pkgconf-m4-1.7.3-10.el9.noarch 1/19
Installing : pkgconf-1.7.3-10.el9.x86_64 2/19
Installing : pkgconfig-1:0.27.1-4.el9.x86_64 3/19
Installing : patch-2.7.6-16.el9.x86_64 4/19
Installing : autoconf-2.69-38.el9.noarch 5/19
Installing : automake-1.16.2-6.el9.noarch 6/19
Installing : libtool-2.4.6-45.el9.x86_64 7/19
Installing : rpm-sign-4.16.1.3-25.el9.x86_64 8/19
Installing : rpm-build-4.16.1.3-25.el9.x86_64 9/19
Installing : redhat-rpm-config-197-1.el9.noarch 10/19
Installing : make-1:4.3-7.el9.x86_64 11/19
Installing : binutils-2.35.2-37.el9.x86_64 12/19
Installing : gcc-11.3.1-4.1.el9.x86_64 13/19
Installing : gcc-c++-11.3.1-4.1.el9.x86_64 14/19
Installing : glibc-devel-2.34-60.el9.x86_64 15/19
Installing : bison-3.7.4-5.el9.x86_64 16/19
Installing : flex-2.6.4-8.el9.x86_64 17/19
Installing : gdb-10.2-5.el9.x86_64 18/19
Installing : strace-5.18-2.el9.x86_64 19/19
Running scriptlet: gcc-11.3.1-4.1.el9.x86_64 19/19
Verifying : pkgconf-m4-1.7.3-10.el9.noarch 1/19
Verifying : pkgconf-1.7.3-10.el9.x86_64 2/19
Verifying : pkgconfig-1:0.27.1-4.el9.x86_64 3/19
Verifying : patch-2.7.6-16.el9.x86_64 4/19
Verifying : autoconf-2.69-38.el9.noarch 5/19
Verifying : automake-1.16.2-6.el9.noarch 6/19
Verifying : libtool-2.4.6-45.el9.x86_64 7/19
Verifying : rpm-sign-4.16.1.3-25.el9.x86_64 8/19
Verifying : rpm-build-4.16.1.3-25.el9.x86_64 9/19
Verifying : redhat-rpm-config-197-1.el9.noarch 10/19
Verifying : make-1:4.3-7.el9.x86_64 11/19
Verifying : binutils-2.35.2-37.el9.x86_64 12/19
Verifying : gcc-11.3.1-4.1.el9.x86_64 13/19
Verifying : gcc-c++-11.3.1-4.1.el9.x86_64 14/19
Verifying : glibc-devel-2.34-60.el9.x86_64 15/19
Verifying : bison-3.7.4-5.el9.x86_64 16/19
Verifying : flex-2.6.4-8.el9.x86_64 17/19
Verifying : gdb-10.2-5.el9.x86_64 18/19
Verifying : strace-5.18-2.el9.x86_64 19/19

Complete!

# 验证包组已安装
# dnf group list installed
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Installed Groups:
Core
Development Tools

3.3 dnf install高级使用技巧

3.3.1 仅下载不安装

# 仅下载软件包不安装
# dnf install –downloadonly –downloaddir=/tmp nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 586 k
Downloading Packages:
(1/3): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(2/3): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(3/3): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 586 kB/s | 586 kB 00:00
Complete!

# 查看下载的软件包
# ls -lh /tmp/*.rpm
-rw-r–r–. 1 root root 11K Mar 31 10:00 nginx-filesystem-1.22.1-2.el9.noarch.rpm
-rw-r–r–. 1 root root 35K Mar 31 10:00 nginx-1.22.1-2.el9.x86_64.rpm
-rw-r–r–. 1 root root 540K Mar 31 10:00 nginx-core-1.22.1-2.el9.x86_64.rpm

# 安装本地软件包
# dnf install /tmp/nginx-1.22.1-2.el9.x86_64.rpm
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 @commandline 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total size: 586 k
Total download size: 551 k
Installed size: 1.9 M
Is this ok [y/N]: y
Downloading Packages:
(1/2): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(2/2): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 551 kB/s | 551 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : nginx-filesystem-1.22.1-2.el9.noarch 1/3
Installing : nginx-core-1.22.1-2.el9.x86_64 2/3
Installing : nginx-1.22.1-2.el9.x86_64 3/3
Running scriptlet: nginx-1.22.1-2.el9.x86_64 3/3
Verifying : nginx-1.22.1-2.el9.x86_64 1/3
Verifying : nginx-core-1.22.1-2.el9.x86_64 2/3
Verifying : nginx-filesystem-1.22.1-2.el9.noarch 3/3

Complete!

风哥提示:dnf install命令支持多种高级选项,如–downloadonly仅下载不安装,–allowerasing允许删除冲突软件包等。学习交流加群风哥QQ113257174

Part04-生产案例与实战讲解

4.1 Web服务器安装实战案例

4.1.1 安装Nginx Web服务器

# 1. 搜索nginx软件包
# dnf search nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: nginx =================
nginx.x86_64 : A high performance web server and reverse proxy server
nginx-filesystem.noarch : The basic directory layout for the nginx webserver
nginx-core.x86_64 : nginx core webserver binary

# 2. 查看nginx软件包信息
# dnf info nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Available Packages
Name : nginx
Version : 1.22.1
Release : 2.el9
Architecture : x86_64
Size : 35 k
Source : nginx-1.22.1-2.el9.src.rpm
Repository : appstream
Summary : A high performance web server and reverse proxy server
URL : http://nginx.org/
License : BSD
Description : Nginx is a web server and a reverse proxy server for HTTP, HTTPS,
: SMTP, POP3 and IMAP protocols, with a strong focus on high concurrency,
: performance and low memory usage.

# 3. 安装nginx
# dnf -y install nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
nginx-filesystem noarch 1:1.22.1-2.el9 appstream 11 k

Transaction Summary
================================================================================
Install 3 Packages

Total download size: 586 k
Installed size: 1.9 M
Downloading Packages:
(1/3): nginx-filesystem-1.22.1-2.el9.noarch.rpm 11 kB/s | 11 kB 00:00
(2/3): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(3/3): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 586 kB/s | 586 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : nginx-filesystem-1.22.1-2.el9.noarch 1/3
Installing : nginx-core-1.22.1-2.el9.x86_64 2/3
Installing : nginx-1.22.1-2.el9.x86_64 3/3
Running scriptlet: nginx-1.22.1-2.el9.x86_64 3/3
Verifying : nginx-1.22.1-2.el9.x86_64 1/3
Verifying : nginx-core-1.22.1-2.el9.x86_64 2/3
Verifying : nginx-filesystem-1.22.1-2.el9.noarch 3/3

Complete!

# 4. 启动nginx服务
# systemctl start nginx
# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

# 5. 验证nginx服务
# systemctl status nginx
● nginx.service – The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled)
Active: active (running) since Thu 2026-03-31 10:00:00 CST; 5s ago
Process: 1234 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 1235 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
Main PID: 1236 (nginx)
Tasks: 2 (limit: 4915)
Memory: 2.3M
CGroup: /system.slice/nginx.service
├─1236 “nginx: master process /usr/sbin/nginx”
└─1237 “nginx: worker process”

Mar 31 10:00:00 server1 systemd[1]: Starting The nginx HTTP and reverse proxy server…
Mar 31 10:00:00 server1 nginx[1234]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Mar 31 10:00:00 server1 nginx[1234]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Mar 31 10:00:00 server1 systemd[1]: Started The nginx HTTP and reverse proxy server.

# 6. 测试nginx服务
# curl http://localhost

Welcome to nginx!

If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.

For online documentation and support please refer to
nginx.org.
Commercial support is available at
nginx.com.

Thank you for using nginx.

4.2 数据库服务器安装实战案例

4.2.1 安装PostgreSQL数据库

# 1. 搜索PostgreSQL软件包
# dnf search postgresql
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
================ Name & Summary Matched: postgresql =================
postgresql.x86_64 : PostgreSQL client programs
postgresql-contrib.x86_64 : Contributed source and binaries distributed with PostgreSQL
postgresql-docs.x86_64 : Extra documentation for PostgreSQL
postgresql-libs.x86_64 : The shared libraries required for PostgreSQL clients
postgresql-server.x86_64 : The programs needed to create and run a PostgreSQL server

# 2. 查看PostgreSQL软件包信息
# dnf info postgresql-server
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Available Packages
Name : postgresql-server
Version : 13.7
Release : 1.el9
Architecture : x86_64
Size : 5.8 M
Source : postgresql-13.7-1.el9.src.rpm
Repository : appstream
Summary : The programs needed to create and run a PostgreSQL server
URL : http://www.postgresql.org/
License : PostgreSQL
Description : PostgreSQL is an advanced Object-Relational database management system (DBMS).
: The postgresql-server package contains the programs needed to create
: and run a PostgreSQL server, which will in turn allow you to create
: and maintain a PostgreSQL database.

# 3. 安装PostgreSQL服务器
# dnf -y install postgresql-server
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
postgresql-server x86_64 13.7-1.el9 appstream 5.8 M
Installing dependencies:
libpq x86_64 13.7-1.el9 appstream 198 k
postgresql x86_64 13.7-1.el9 appstream 1.5 M
postgresql-libs x86_64 13.7-1.el9 appstream 234 k

Transaction Summary
================================================================================
Install 4 Packages

Total download size: 7.7 M
Installed size: 32.1 M
Downloading Packages:
(1/4): libpq-13.7-1.el9.x86_64.rpm 198 kB/s | 198 kB 00:00
(2/4): postgresql-libs-13.7-1.el9.x86_64.rpm 234 kB/s | 234 kB 00:00
(3/4): postgresql-13.7-1.el9.x86_64.rpm 1.5 MB/s | 1.5 MB 00:00
(4/4): postgresql-server-13.7-1.el9.x86_64.rpm 5.8 MB/s | 5.8 MB 00:00
——————————————————————————–
Total 7.7 MB/s | 7.7 MB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : postgresql-libs-13.7-1.el9.x86_64 1/4
Installing : libpq-13.7-1.el9.x86_64 2/4
Installing : postgresql-13.7-1.el9.x86_64 3/4
Installing : postgresql-server-13.7-1.el9.x86_64 4/4
Running scriptlet: postgresql-server-13.7-1.el9.x86_64 4/4
Verifying : postgresql-libs-13.7-1.el9.x86_64 1/4
Verifying : libpq-13.7-1.el9.x86_64 2/4
Verifying : postgresql-13.7-1.el9.x86_64 3/4
Verifying : postgresql-server-13.7-1.el9.x86_64 4/4

Complete!

# 4. 初始化数据库
# /usr/bin/postgresql-setup –initdb
* Initializing database in ‘/var/lib/pgsql/data’
* Initialized, logs are in /var/lib/pgsql/initdb_postgresql.log

# 5. 启动PostgreSQL服务
# systemctl start postgresql
# systemctl enable postgresql
Created symlink /etc/systemd/system/multi-user.target.wants/postgresql.service → /usr/lib/systemd/system/postgresql.service.

# 6. 验证PostgreSQL服务
# systemctl status postgresql
● postgresql.service – PostgreSQL database server
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; enabled)
Active: active (running) since Thu 2026-03-31 10:00:00 CST; 5s ago
Process: 1234 ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited, status=0/SUCCESS)
Process: 1235 ExecStart=/usr/bin/pg_ctl start -D ${PGDATA} -s -o “-p ${PGPORT}” -w -t 300 (code=exited, status=0/SUCCESS)
Main PID: 1236 (postgres)
Tasks: 8 (limit: 4915)
Memory: 15.2M
CGroup: /system.slice/postgresql.service
├─1236 “postgres”
├─1237 “postgres: logger”
├─1238 “postgres: checkpointer”
├─1239 “postgres: background writer”
├─1240 “postgres: walwriter”
├─1241 “postgres: autovacuum launcher”
├─1242 “postgres: stats collector”
└─1243 “postgres: logical replication launcher”

Mar 31 10:00:00 server1 systemd[1]: Starting PostgreSQL database server…
Mar 31 10:00:00 server1 postgres[1235]: LOG: listening on IPv4 address “127.0.0.1”, port 5432
Mar 31 10:00:00 server1 postgres[1235]: LOG: listening on Unix socket “/var/run/postgresql/.s.PGSQL.5432”
Mar 31 10:00:00 server1 postgres[1235]: LOG: database system is ready to accept connections
Mar 31 10:00:00 server1 systemd[1]: Started PostgreSQL database server.

# 7. 连接PostgreSQL数据库
# su – postgres -c “psql”
psql (13.7)
Type “help” for help.

postgres=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
———–+———-+———-+————-+————-+———————–
postgres | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 |
template0 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_US.UTF-8 | en_US.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(3 rows)

postgres=# \q

4.3 软件包安装故障排查与解决

4.3.1 依赖冲突问题

# 问题现象:软件包安装失败,依赖冲突
# 分析步骤:

# 1. 查看错误信息
# dnf install nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
Removing:
httpd x86_64 2.4.53-7.el9 @System 1.4 M

Transaction Summary
================================================================================
Install 2 Packages
Remove 1 Package

Total download size: 575 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(2/2): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 575 kB/s | 575 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : nginx-core-1.22.1-2.el9.x86_64 1/3
Installing : nginx-1.22.1-2.el9.x86_64 2/3
Removing : httpd-2.4.53-7.el9.x86_64 3/3
Running scriptlet: httpd-2.4.53-7.el9.x86_64 3/3
Verifying : nginx-1.22.1-2.el9.x86_64 1/3
Verifying : nginx-core-1.22.1-2.el9.x86_64 2/3
Verifying : httpd-2.4.53-7.el9.x86_64 3/3

Complete!

# 2. 使用–allowerasing选项
# dnf install –allowerasing nginx
Updating Subscription Management repositories.
Last metadata expiration check: 0:00:01 ago on Thu Mar 31 10:00:00 2026.
Dependencies resolved.
================================================================================
Package Architecture Version Repository Size
================================================================================
Installing:
nginx x86_64 1:1.22.1-2.el9 appstream 35 k
Installing dependencies:
nginx-core x86_64 1:1.22.1-2.el9 appstream 540 k
Removing:
httpd x86_64 2.4.53-7.el9 @System 1.4 M

Transaction Summary
================================================================================
Install 2 Packages
Remove 1 Package

Total download size: 575 k
Is this ok [y/N]: y
Downloading Packages:
(1/2): nginx-1.22.1-2.el9.x86_64.rpm 35 kB/s | 35 kB 00:00
(2/2): nginx-core-1.22.1-2.el9.x86_64.rpm 540 kB/s | 540 kB 00:00
——————————————————————————–
Total 575 kB/s | 575 kB 00:00
Running transaction check
Transaction test succeeded
Running transaction
Preparing : 1/1
Installing : nginx-core-1.22.1-2.el9.x86_64 1/3
Installing : nginx-1.22.1-2.el9.x86_64 2/3
Removing : httpd-2.4.53-7.el9.x86_64 3/3
Running scriptlet: httpd-2.4.53-7.el9.x86_64 3/3
Verifying : nginx-1.22.1-2.el9.x86_64 1/3
Verifying : nginx-core-1.22.1-2.el9.x86_64 2/3
Verifying : httpd-2.4.53-7.el9.x86_64 3/3

Complete!

# 3. 预防措施
# – 检查软件包依赖关系
# – 使用–downloadonly仅下载不安装
# – 在测试环境先测试安装

生产环境建议:软件包安装故障排查需要耐心和细致。依赖冲突可以使用–allowerasing选项解决。更多学习教程公众号风哥教程itpux_com

Part05-风哥经验总结与分享

5.1 软件包安装经验总结

软件包安装经验总结:

  • 测试环境:在测试环境先测试安装
  • 依赖检查:检查软件包依赖关系
  • 备份:安装前备份重要数据
  • 磁盘空间:检查磁盘空间是否充足
  • 版本选择:使用稳定版本
  • 定期更新:定期更新软件包

5.2 软件包安装检查清单

软件包安装检查清单:

  • 安装前:检查软件包信息、依赖关系、磁盘空间
  • 安装时:使用-y选项自动确认
  • 安装后:验证软件包安装
  • 服务启动:启动并启用服务
  • 功能测试:测试软件包功能
  • 故障排查:检查依赖关系、使用–allowerasing选项

5.3 软件包安装相关工具推荐

软件包安装相关工具推荐:

  • dnf:DNF软件包管理器
  • rpm:RPM包管理器
  • repoquery:查询软件包信息
  • repotrack:跟踪软件包依赖
  • yum-utils:YUM实用工具(兼容DNF)
风哥提示:dnf install命令是DNF软件包管理器中最常用的命令之一,建议熟练掌握。安装前可以先使用dnf search或dnf info查看软件包信息。

本文由风哥教程整理发布,仅用于学习测试使用,转载注明出处:http://www.fgedu.net.cn/10327.html

联系我们

在线咨询:点击这里给我发消息

微信号:itpux-com

工作日:9:30-18:30,节假日休息