依赖报错别慌!Linux RPM/Yum/ 源码安装全流程通关

CentOS 运维避坑实战

CentOS7.9 安装 Python3.8.16 后 yum 报错,快速修复方案

Linux 软件包管理

Windows 中软件包管理

  1. 控制面板程序和功能。通过安装,将信息注册到系统中。

在这里插入图片描述

  1. 用户下载的绿色软件。例如U盘启动盘工具rufus。

软件包来源:应用商城,第三方官方网站(qq、微信)。

分析 RPM 包

Linux 发行版本

  • 以 RHEL 为代表的发行版本,使用rpm包管理系统:
  • RHEL (Red Hat Enterprise Linux)
  • Fedora(由原来的RedHat桌面版本发展而来,免费版本)
  • CentOS(RHEL的社区克隆版本,免费)
  • CentOS Stream(RHEL的社区克隆版本,免费)
  • Rocky(RHEL的社区克隆版本,免费)
  • OEL(Oralce Enterprise Linux)
  • 以 Debian 为代表的发行版本,使用deb包管理系统:
  • Debian,社区Linux的典范,迄今为止最遵循GNU规范的Linux系统。
  • Ubuntu,Debian衍生版,是一个以桌面应用为主的Linux操作系统。
  • Kali Linux,Debian衍生版,旨在渗透测试和数字取证。
  • 其他版本:ArchLinux Gentoo 等等…

在这里插入图片描述

RPM 包文件名格式

redhat 开发了 rpm 包管理,提供一个标准的软件版本管理方法,比从归档包解压文件到系统简单多了。CentOS 提供的所有软件都是rpm格式。

RPM软件包文件名格式:name-version-release.architecture.rpm

示例:lrzsz-0.12.20-36.el7.x86_64.rpm

  • name,是描述其内容的一个或多个词语(lrzsz)。
  • version,是原始软件的版本号(0.12.20)。
  • release,是基于该版本的发行版号,由软件打包商设置,后者不一定是原始软件开发商(36.el7)。
  • architecture,是编译的软件包运行的处理器架构。
  • noarch,表示此软件包不限定架构。
  • x86_64,表示此软件包限定x86 64位。
  • aarch64,表示此软件包限定ARM 64位。

RPM 包组成

每个rpm包涵三个部分:

  • 需要安装的文件。
  • 包的元数据信息,包括包的名称、版本、架构等;软件包说明;软件包依赖关系;许可证;更变日志;其他信息。
  • 脚本:软件包安装,更新,卸载需要执行的脚本。

通常,软件提供商使用GPG密钥对RPM软件包进行数字签名(Red Hat会对其发布的所有软件包进行数字签名)。 RPM系统通过确认包由相应的GPG密钥签名来验证包的完整性。 如果GPG签名不匹配,RPM系统拒绝安装包。

非对称加密

非对称加密:有一对公钥和私钥。

  • 公钥:分享给别人,用来加密数据。
  • 私钥:自己保留,用来解密公钥加密的数据。

Linux中rpm包会被私钥签名,客户端使用公钥验证签名,确保文件的完整性。

RPM 包安装和更新

  • 如果同一个软件有多个版本,只需安装最高版本。
  • 在大多数情况下,一个软件只能安装一个版本。 kernel是个例外。如果构建包的文件名没有冲突,则可以安装多个版本。 由于只能通过引导到该内核来测试新内核,因此特定设计了包,以便可以一次安装多个版本。如果内核无法启动,则旧内核仍然可用且可引导。
  • 软件包升级只需要安装最新版本,不需要逐步升级。
  • 升级RPM包将删除旧版本的软件包并安装新版本,通常会保留配置文件。

rpm 命令

查询(重点)

基本语法:

rpm {-q|--query} [select-options] [query-options]

   select-options
        [PACKAGE_NAME] [-a,--all] [-f,--file FILE]
        [-g,--group GROUP] {-p,--package PACKAGE_FILE]
        [--hdrid SHA1] [--pkgid MD5] [--tid TID]
        [--querybynumber HDRNUM] [--triggeredby PACKAGE_NAME]
        [--whatprovides CAPABILITY] [--whatrequires CAPABILITY]

   query-options
        [--changelog] [-c,--configfiles] [--conflicts]
        [-d,--docfiles] [--dump] [--filesbypkg] [-i,--info]
        [--last] [-l,--list] [--obsoletes] [--provides]
        [--qf,--queryformat QUERYFMT] [-R,--requires]
        [--scripts] [-s,--state] [--triggers,--triggerscripts]

示例:

# 查询系统中安装了哪些软件包
[root@server ~ 10:10:46]# rpm -qa
libqmi-utils-1.18.0-2.el7.x86_64
libmpcdec-1.2.6-12.el7.x86_64
gtkmm30-3.22.2-1.el7.x86_64
nss-sysinit-3.67.0-4.el7_9.x86_64
...


# 查询系统中某个软件包是否安装
[root@server ~ 10:17:07]# rpm -q httpd
httpd-2.4.6-99.el7.centos.1.x86_64
[root@server ~ 10:18:32]# rpm -q sshd
未安装软件包 sshd 


# 查询系统中某个已安装的软件包元数据信息
[root@server ~ 10:19:38]# rpm -q coreutils -i
Name        : coreutils
Version     : 8.22
Release     : 24.el7_9.2
Architecture: x86_64
Install Date: 2026年07月14日 星期二 10时35分00秒
Group       : System Environment/Base
Size        : 14594210
License     : GPLv3+
Signature   : RSA/SHA256, 2020年11月18日 星期三 22时16分51秒, Key ID 24c6a8a7f4a80eb5
Source RPM  : coreutils-8.22-24.el7_9.2.src.rpm
Build Date  : 2020年11月17日 星期二 06时24分59秒
Build Host  : x86-01.bsys.centos.org
Relocations : (not relocatable)
Packager    : CentOS BuildSystem <http://bugs.centos.org>
Vendor      : CentOS
URL         : http://www.gnu.org/software/coreutils/
Summary     : A set of basic GNU tools commonly used in shell scripts
Description :
These are the GNU core utilities.  This package is the combination of
the old GNU fileutils, sh-utils, and textutils packages.

# 查询系统中某个已安装的软件包包涵哪些文件
[root@server ~ 10:20:02]# rpm -q openssh-server -l
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
/usr/lib/systemd/system/sshd-keygen.service
/usr/lib/systemd/system/sshd.service
/usr/lib/systemd/system/sshd.socket
/usr/lib/systemd/system/sshd@.service
/usr/lib64/fipscheck/sshd.hmac
/usr/libexec/openssh/sftp-server
/usr/sbin/sshd
/usr/sbin/sshd-keygen
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz
/var/empty/sshd

# 查询系统中某个已安装的软件包包涵哪些配置文件
[root@server ~ 10:20:39]# rpm -q openssh-server -c
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd

# 查询系统中某个已安装的软件包包涵哪些文档文件
[root@server ~ 10:21:00]# rpm -q openssh-server -d
/usr/share/man/man5/moduli.5.gz
/usr/share/man/man5/sshd_config.5.gz
/usr/share/man/man8/sftp-server.8.gz
/usr/share/man/man8/sshd.8.gz

# 查询系统中某个某个文件属于哪个已安装的软件包
[root@server ~ 10:21:18]# rpm -q -f /etc/ssh/sshd_config 
openssh-server-7.4p1-22.el7_9.x86_64

# 查询系统中某个已安装的软件包包涵的脚本
[root@server ~ 10:22:43]# rpm -q  openssh-server --scripts 
preinstall scriptlet (using /bin/sh):
getent group sshd >/dev/null || groupadd -g 74 -r sshd || :
getent passwd sshd >/dev/null || \
  useradd -c "Privilege-separated SSH" -u 74 -g sshd \
  -s /sbin/nologin -r -d /var/empty/sshd sshd 2> /dev/null || :
postinstall scriptlet (using /bin/sh):

if [ $1 -eq 1 ] ; then 
        # Initial installation 
        systemctl preset sshd.service sshd.socket >/dev/null 2>&1 || : 
fi
preuninstall scriptlet (using /bin/sh):

if [ $1 -eq 0 ] ; then 
        # Package removal, not upgrade 
        systemctl --no-reload disable sshd.service sshd.socket > /dev/null 2>&1 || : 
        systemctl stop sshd.service sshd.socket > /dev/null 2>&1 || : 
fi
postuninstall scriptlet (using /bin/sh):

systemctl daemon-reload >/dev/null 2>&1 || : 
if [ $1 -ge 1 ] ; then 
        # Package upgrade, not uninstall 
        systemctl try-restart sshd.service >/dev/null 2>&1 || : 
fi


# 查询系统中某个已安装的软件包变更日志
[root@server ~ 10:22:58]# rpm -q  openssh-server --changelog 
* 四 930 2021 Dmitry Belyavskiy <dbelyavs@redhat.com> - 7.4p1-22 + 0.10.3-2
- avoid segfault in Kerberos cache cleanup (#1999263)
- fix CVE-2021-41617 (#2008884)

* 二 625 2019 Jakub Jelen <jjelen@redhat.com> - 7.4p1-21 + 0.10.3-2
- Avoid double comma in the default cipher list in FIPS mode (#1722446)

...

# 下载 httpd 软件包,以及依赖的其他软件包
[root@server ~ 10:24:25]# yum install -y yum-utils
[root@server ~ 10:25:22]# yumdownloader httpd   
[root@server ~ 10:26:05]# ls httpd-*
httpd-2.4.6-99.el7.centos.1.x86_64.rpm

# 查询系统中某个软件包(package)文件包涵哪些配置文件
[root@server ~ 10:26:24]# rpm -q -p httpd-2.4.6-99.el7.centos.1.x86_64.rpm -c
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
...
# 同样-l -d -i也可以配合-p使用

# 查询系统中某个软件包组中包涵哪些软件包
[root@server ~ 10:26:24]# rpm -q -p httpd-2.4.6-99.el7.centos.1.x86_64.rpm -c
/etc/httpd/conf.d/autoindex.conf
/etc/httpd/conf.d/userdir.conf
/etc/httpd/conf.d/welcome.conf
/etc/httpd/conf.modules.d/00-base.conf
/etc/httpd/conf.modules.d/00-dav.conf
...

扩展

# 查看软件包所在仓库精确位置
[root@server ~ 10:28:27]# repoquery  --location httpd
http://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/httpd-2.4.6-99.el7.centos.1.x86_64.rpm

# 此时可以通过 wget 下载特定文件
[root@server ~ 10:30:00]# wget\
http://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/httpd-2.4.6-99.el7.centos.1.x86_64.rpm

验证

基本语法:

rpm {-V|--verify} [select-options] [verify-options]

   select-options
        [PACKAGE_NAME] [-a,--all] [-f,--file FILE]
        [-g,--group GROUP] {-p,--package PACKAGE_FILE]
        [--hdrid SHA1] [--pkgid MD5] [--tid TID]
        [--querybynumber HDRNUM] [--triggeredby PACKAGE_NAME]
        [--whatprovides CAPABILITY] [--whatrequires CAPABILITY]

   verify-options
        [--nodeps] [--nofiles] [--noscripts]
        [--nodigest] [--nosignature]
        [--nolinkto] [--nofiledigest] [--nosize] [--nouser]
        [--nogroup] [--nomtime] [--nomode] [--nordev]
        [--nocaps] [--noconfig] [--noghost]

示例:

# 查看openssh-server软件安装是否有问题
[root@server ~ 16:55:21]# rpm -V openssh-server 
[root@server ~ 17:00:36]#       #无事发生证明没有问题

# 修改(change)
[root@server ~ 17:00:39]# sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
[root@server ~ 17:02:51]# rpm -V openssh-server 
S.5....T.  c /etc/ssh/sshd_config
# 第一段 9位标识 S . 5 . . . . T . ,9项校验指标,.代表校验正常,出现字母代表异常
# 第1位 S:文件Size大小和原始安装文件不一致
# 第2位 .:文件权限Mode正常
# 第3位 5:MD5哈希校验值不匹配,文件内容被修改
# 第4位 .:设备号Device正常
# 第5位 .:软链接Link属性正常
# 第6位 .:文件属主User正常
# 第7位 .:文件属组Group正常
# 第8位 T:文件修改时间mTime和原始文件不同
# 第9位 .:文件能力Capabilities正常
# c 标记:此文件是配置文件config,人为修改属于运维常规操作,无需恐慌
# /etc/ssh/sshd_config:产生校验异常的文件路径(ssh服务主配置文件)

# 移走 /etc/ssh/sshd_config 文件,再次查看
[root@server ~ 17:05:33]# rpm -V openssh-server 
遗漏   c /etc/ssh/sshd_config

# 恢复该文件到原来位置
[root@server ~ 17:05:42]# mv sshd_config /etc/ssh/

安装和卸载

基本语法:

rpm {-i|--install} [install-options] PACKAGE_FILE ...

   install-options
        [--allfiles] [--badreloc] [--excludepath OLDPATH]
        [--excludedocs] [--force] [-h,--hash]
        [--ignoresize] [--ignorearch] [--ignoreos]
        [--includedocs] [--justdb] [--nocollections]
        [--nodeps] [--nodigest] [--nosignature] [--noplugins]
        [--noorder] [--noscripts] [--notriggers]
        [--oldpackage] [--percent] [--prefix NEWPATH]
        [--relocate OLDPATH=NEWPATH]
        [--replacefiles] [--replacepkgs]
        [--test]

示例:

# 下载软件包
[root@server ~ 17:06:50]# repoquery --location lrzsz
http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm
[root@server ~ 17:08:54]# wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm
--2026-07-28 17:10:31--  http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm
正在解析主机 mirrors.aliyun.com (mirrors.aliyun.com)... 221.231.83.17, 221.231.83.58, 221.231.83.87, ...
正在连接 mirrors.aliyun.com (mirrors.aliyun.com)|221.231.83.17|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:79376 (78K) [application/x-rpm]
正在保存至: “lrzsz-0.12.20-36.el7.x86_64.rpm”

100%[================================================>] 79,376      --.-K/s 用时 0.002s  

2026-07-28 17:10:31 (45.3 MB/s) - 已保存 “lrzsz-0.12.20-36.el7.x86_64.rpm” [79376/79376])


# 安装
[root@server ~ 17:10:43]# rpm -i lrzsz-0.12.20-36.el7.x86_64.rpm 
[root@server ~ 17:11:06]# rpm -q lrzsz 
lrzsz-0.12.20-36.el7.x86_64

# 卸载
[root@server ~ 17:11:28]# rpm -e lrzsz 
[root@server ~ 17:11:52]# rpm -q lrzsz
未安装软件包 lrzsz 

# 友好方式安装
[root@server ~ 17:12:07]# rpm -ivh lrzsz-0.12.20-36.el7.x86_64.rpm 
准备中...                          ################################# [100%]
正在升级/安装...
   1:lrzsz-0.12.20-36.el7             ################################# [100%]

# 友好方式卸载
[root@server ~ 17:12:45]# rpm -evh lrzsz
准备中...                          ################################# [100%]
正在清理/删除...
   1:lrzsz-0.12.20-36.el7             ################################# [100%]

# 安装 httpd,报错如下,下一节讲解如下解决
# 安装准备:确保系统中没有提供httpd需要的依赖包
[root@server ~ 17:13:25]# rpm -e apr-util httpd-tools mailcap 
[root@server ~ 17:14:51]# rpm -ivh httpd-2.4.6-99.el7.centos.1.x86_64.rpm 
错误:依赖检测失败:
    /etc/mime.types 被 httpd-2.4.6-99.el7.centos.1.x86_64 需要
    httpd-tools = 2.4.6-99.el7.centos.1 被 httpd-2.4.6-99.el7.centos.1.x86_64 需要
    libapr-1.so.0()(64bit) 被 httpd-2.4.6-99.el7.centos.1.x86_64 需要
    libaprutil-1.so.0()(64bit) 被 httpd-2.4.6-99.el7.centos.1.x86_64 需要
重新安装
rpm {--reinstall} [install-options] PACKAGE_FILE ...

示例:

[root@server ~ 17:15:46]# rpm --reinstall -vh lrzsz*
准备中...                          ################################# [100%]
正在升级/安装...
   1:lrzsz-0.12.20-36.el7             ################################# [100%]

提取 RPM 包中文件

Windows 提取

使用压缩工具(例如360压缩)打开rpm包,浏览和提取。

Linux 提取
  • 方法一:分步骤提取

     # 将文件转换为cpio格式
     [root@server ~ 17:17:42]# rpm2cpio httpd-2.4.6-99.el7.centos.1.x86_64.rpm > httpd-2.4.6-99.el7.centos.1.x86_64.cpio
    
    # 查询 cpio 格式(一种打包格式)文件中有哪些文件
    [root@server ~ 18:44:26]# cpio -t <httpd-2.4.6-99.el7.centos.1.x86_64.cpio
    ./etc/httpd
    ./etc/httpd/conf
    ./etc/httpd/conf.d
    ./etc/httpd/conf.d/README
    ./etc/httpd/conf.d/autoindex.conf
    ...
    
    # 配置管道查询特定文件
    [root@server ~ 18:45:42]# cpio -t <httpd-2.4.6-99.el7.centos.1.x86_64.cpio |grep 'httpd\.conf'
    ./etc/httpd/conf/httpd.conf
    ./usr/lib/tmpfiles.d/httpd.conf
    19347# 提取所有文件,-d选项指明提取过程中创建对应的目录分层结构
    [root@server ~ 18:46:38]# cpio -id '*' < httpd-2.4.6-99.el7.centos.1.x86_64.cpio
    19347# 提取特定文件
    [root@server ~ 18:47:39]# cpio -id ./etc/httpd/conf/httpd.conf < httpd-2.4.6-99.el7.centos.1.x86_64.cpio
    
    
  • 一步提取所有文件

[root@server ~ 18:48:27]# rpm2cpio httpd-2.4.6-99.el7.centos.1.x86_64.rpm | cpio -id '*'

用 yum 管理软件包

yum 介绍

  • rpm 命令是一个管理软件包的工具,不适用于软件包存储库或自动解决来自多个源的依赖项。
  • Yum(Yellowdog Updater Modified)旨在成为管理基于RPM的软件安装和更新的更好系统。yum命令允许安装,更新,删除和获取有关软件包及其依赖项的信息。

yum 命令

help

作用:

# 查看yum命令帮助信息
[root@server ~ 13:33:51]# yum help
info

作用:查看仓库中某个软件包信息

# 查看仓库中httpd包信息
[root@server ~ 13:57:47]# yum info httpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装的软件包
名称    :httpd
架构    :x86_64
版本    :2.4.6
发布    :99.el7.centos.1
大小    :9.4 M
源    :installed
来自源:updates
简介    : Apache HTTP Server
网址    :http://httpd.apache.org/
协议    : ASL 2.0
描述    : The Apache HTTP Server is a powerful, efficient, and extensible
         : web server.


list

作用:查询软件包清单

# 查看仓库中http开头的包有哪些
[root@server ~ 13:58:18]# yum list 'http*'
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装的软件包
httpd.x86_64                                    2.4.6-99.el7.centos.1             @updates
httpd-tools.x86_64                              2.4.6-99.el7.centos.1             @updates
可安装的软件包
http-parser.i686                                2.7.1-9.el7                       base    
http-parser.x86_64                              2.7.1-9.el7                       base 
...

# 查看仓库中httpd包有哪些版本
[root@server ~ 13:58:58]# yum list httpd --showduplicates
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
已安装的软件包
httpd.x86_64                        2.4.6-99.el7.centos.1                         @updates
可安装的软件包
httpd.x86_64                        2.4.6-95.el7.centos                           base    
httpd.x86_64                        2.4.6-97.el7.centos                           updates 
httpd.x86_64                        2.4.6-97.el7.centos.1                         updates 
httpd.x86_64                        2.4.6-97.el7.centos.2                         updates 
httpd.x86_64                        2.4.6-97.el7.centos.4                         updates 
httpd.x86_64                        2.4.6-97.el7.centos.5                         updates 
httpd.x86_64                        2.4.6-98.el7.centos.6                         updates 
httpd.x86_64                        2.4.6-98.el7.centos.7                         updates 
httpd.x86_64                        2.4.6-99.el7.centos.1                         updates
search

作用:根据关键字搜索软件包

# 查看简介包含关键字的软件包
[root@server ~ 13:59:51]# yum search 'web server'
[root@server ~ 13:59:51]# yum search 'web server'
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
================================ N/S matched: web server =================================
erlang-inets.x86_64 : A set of services such as a Web server and a ftp client etc
ghc-happstack-server.x86_64 : Happstack web server
ghc-warp.x86_64 : Fast light-weight web server for WAI applications
...
名称和简介匹配 only,使用“search all”试试。

# 查看描述和简介包含关键字的软件包
[root@server ~ 14:01:01]# yum search all 'web server'
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
==================================== 匹配:web server ====================================
erlang-inets.x86_64 : A set of services such as a Web server and a ftp client etc
ghc-warp.x86_64 : Fast light-weight web server for WAI applications
...
provides

作用:查看仓库中哪个包可以提供相应文件

# 查看仓库中哪个包可以提供文件sar程序
[root@server ~ 14:02:17]# yum provides sar
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base/7/x86_64/filelists_db                                         | 7.2 MB  00:00:02     
epel/x86_64/filelists_db                                           |  15 MB  00:00:04     
extras/7/x86_64/filelists_db                                       | 305 kB  00:00:00     
sysstat-10.1.5-19.el7.x86_64 : Collection of performance monitoring tools for Linux
源    :base
匹配来源:
文件名    :/usr/bin/sar



sysstat-10.1.5-20.el7_9.x86_64 : Collection of performance monitoring tools for Linux
源    :updates
匹配来源:
文件名    :/usr/bin/sar
...

# 备用查询命令
[root@server ~ 14:03:31]# yum provides '*bin/sar'
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
sysstat-10.1.5-19.el7.x86_64 : Collection of performance monitoring tools for Linux
源    :base
匹配来源:
文件名    :/usr/bin/sar
...

# 安装sar工具对应的软件包
[root@server ~ 14:04:24]# yum install sysstat
install

作用:安装软件包

# 安装软件包
[root@server ~ 14:04:58]# yum install vsftpd

# 只下载不安装,将依赖软件包一并下载
# 前提是系统中没安装对应软件包,才会下载
[root@server ~ 14:06:56]# yum install vsftpd --downloadonly --downloaddir=/root/
[root@server ~ 14:08:37]# ls vsftpd-*
vsftpd-3.0.2-29.el7_9.x86_64.rpm

localinstall

作用:安装本地文件系统中软件包

# 安装本地文件系统中vsftpd包
[root@server ~ 14:08:55]# yum localinstall ./vsftpd-3.0.2-29.el7_9.x86_64.rpm

downgrade

作用:软件包降级

# 降级 vsftpd 版本为 3.0.2-28.el7
[root@server ~ 14:12:31]# yum downgrade -y vsftpd- 3.0.2-28.el7
# 降级的时候,要一并降级依赖软件包

依赖降级示例:

# 环境准备:安装最新版httpd
[root@server ~ 14:13:23]# yum install -y httpd

# 降级到特定版本:降级失败,因为已安装的 httpd-tools 无法满足当前httpd版本
[root@server ~ 14:13:56]# yum downgrade -y httpd-2.4.6-97.el7.centos
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-97.el7.centos 将被 降级
--> 正在处理依赖关系 httpd-tools = 2.4.6-97.el7.centos,它被软件包 httpd-2.4.6-97.el7.centos.x86_64 需要
---> 软件包 httpd.x86_64.0.2.4.6-99.el7.centos.1 将被 删除
--> 解决依赖关系完成
错误:软件包:httpd-2.4.6-97.el7.centos.x86_64 (updates)
          需要:httpd-tools = 2.4.6-97.el7.centos
          已安装: httpd-tools-2.4.6-99.el7.centos.1.x86_64 (@updates)
              httpd-tools = 2.4.6-99.el7.centos.1
          可用: httpd-tools-2.4.6-95.el7.centos.x86_64 (base)
              httpd-tools = 2.4.6-95.el7.centos
          可用: httpd-tools-2.4.6-97.el7.centos.x86_64 (updates)
              httpd-tools = 2.4.6-97.el7.centos
          可用: httpd-tools-2.4.6-97.el7.centos.1.x86_64 (updates)
              httpd-tools = 2.4.6-97.el7.centos.1
          可用: httpd-tools-2.4.6-97.el7.centos.2.x86_64 (updates)
              httpd-tools = 2.4.6-97.el7.centos.2
          可用: httpd-tools-2.4.6-97.el7.centos.4.x86_64 (updates)
              httpd-tools = 2.4.6-97.el7.centos.4
          可用: httpd-tools-2.4.6-97.el7.centos.5.x86_64 (updates)
              httpd-tools = 2.4.6-97.el7.centos.5
          可用: httpd-tools-2.4.6-98.el7.centos.6.x86_64 (updates)
              httpd-tools = 2.4.6-98.el7.centos.6
          可用: httpd-tools-2.4.6-98.el7.centos.7.x86_64 (updates)
              httpd-tools = 2.4.6-98.el7.centos.7
 您可以尝试添加 --skip-broken 选项来解决该问题
 您可以尝试执行:rpm -Va --nofiles --nodigest
 
# 解决方法:httpd-tools与httpd一起降级到相同版本
[root@server ~ 14:14:44]# yum downgrade -y httpd-tools-2.4.6-97.el7.centos httpd-2.4.6-97.el7.centos
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 httpd.x86_64.0.2.4.6-97.el7.centos 将被 降级
---> 软件包 httpd.x86_64.0.2.4.6-99.el7.centos.1 将被 删除
---> 软件包 httpd-tools.x86_64.0.2.4.6-97.el7.centos 将被 降级
---> 软件包 httpd-tools.x86_64.0.2.4.6-99.el7.centos.1 将被 删除
--> 解决依赖关系完成

依赖关系解决

==========================================================================================
 Package              架构            版本                         源                大小
==========================================================================================
正在降级:
 httpd                x86_64          2.4.6-97.el7.centos          updates          2.7 M
 httpd-tools          x86_64          2.4.6-97.el7.centos          updates           93 k

事务概要
==========================================================================================
降级  2 软件包

总下载量:2.8 M
Downloading packages:
(1/2): httpd-tools-2.4.6-97.el7.centos.x86_64.rpm                  |  93 kB  00:00:00     
(2/2): httpd-2.4.6-97.el7.centos.x86_64.rpm                        | 2.7 MB  00:00:06     
------------------------------------------------------------------------------------------
总计                                                      429 kB/s | 2.8 MB  00:00:06     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  正在安装    : httpd-tools-2.4.6-97.el7.centos.x86_64                                1/4 
  正在安装    : httpd-2.4.6-97.el7.centos.x86_64                                      2/4 
  清理        : httpd-2.4.6-99.el7.centos.1.x86_64                                    3/4 
  清理        : httpd-tools-2.4.6-99.el7.centos.1.x86_64                              4/4 
  验证中      : httpd-2.4.6-97.el7.centos.x86_64                                      1/4 
  验证中      : httpd-tools-2.4.6-97.el7.centos.x86_64                                2/4 
  验证中      : httpd-2.4.6-99.el7.centos.1.x86_64                                    3/4 
  验证中      : httpd-tools-2.4.6-99.el7.centos.1.x86_64                              4/4 

删除:
  httpd.x86_64 0:2.4.6-99.el7.centos.1     httpd-tools.x86_64 0:2.4.6-99.el7.centos.1    

已安装:
  httpd.x86_64 0:2.4.6-97.el7.centos       httpd-tools.x86_64 0:2.4.6-97.el7.centos      

完毕!
update

作用:软件包升级

# 升级 vsftpd 版本为 3.0.2-29.el7_9
[root@server ~ 14:17:58]# yum update vsftpd-3.0.2-29.el7_9 

# 升级系统中所有软件为最新版本
[root@server ~ 14:18:53]# yum update 
history 子命令
list

作用:查询yum事务历史记录

[root@server ~ 14:34:53]# 
[root@server ~ 14:34:53]# yum history list
已加载插件:fastestmirror, langpacks
ID     | 登录用户                 | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
    10 | cyw <cyw>                | 2026-07-28 14:19 | I, U           |  145 **
     9 | cyw <cyw>                | 2026-07-28 14:16 | Downgrade      |    2   
     8 | cyw <cyw>                | 2026-07-28 14:09 | Install        |    1   
     7 | cyw <cyw>                | 2026-07-28 14:08 | Erase          |    1   
     6 | cyw <cyw>                | 2026-07-28 14:05 | Install        |    1   
     5 | cyw <cyw>                | 2026-07-22 16:41 | Install        |    5   
     4 | cyw <cyw>                | 2026-07-22 16:40 | I, U           |    2   
     3 | cyw <cyw>                | 2026-07-22 16:39 | Install        |    1   
     2 | cyw <cyw>                | 2026-07-15 10:43 | Install        |    1   
     1 | 系统 <>                | 2026-07-14 10:28 | Install        | 1348 
 history list
 
 
 
 [root@server ~ 14:47:45]# yum install -y vsftpd
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
软件包 vsftpd-3.0.2-29.el7_9.x86_64 已安装并且是最新版本
无须任何处理
[root@server ~ 14:49:09]# yum downgrade -y vsftpd

# list 可以省略
[root@server ~ 14:49:48]# yum history 
已加载插件:fastestmirror, langpacks
ID     | 登录用户                 | 日期和时间       | 操作           | 变更数 
-------------------------------------------------------------------------------
    11 | cyw <cyw>                | 2026-07-28 14:49 | Downgrade      |    1 PP
    10 | cyw <cyw>                | 2026-07-28 14:19 | I, U           |  145 **
     9 | cyw <cyw>                | 2026-07-28 14:16 | Downgrade      |    2   
     8 | cyw <cyw>                | 2026-07-28 14:09 | Install        |    1   
     7 | cyw <cyw>                | 2026-07-28 14:08 | Erase          |    1   
     6 | cyw <cyw>                | 2026-07-28 14:05 | Install        |    1   
     5 | cyw <cyw>                | 2026-07-22 16:41 | Install        |    5   
     4 | cyw <cyw>                | 2026-07-22 16:40 | I, U           |    2   
     3 | cyw <cyw>                | 2026-07-22 16:39 | Install        |    1   
     2 | cyw <cyw>                | 2026-07-15 10:43 | Install        |    1   
     1 | 系统 <>                | 2026-07-14 10:28 | Install        | 1348   
history list

info

作用:特定yum事务详情

[root@server ~ 14:50:13]# yum history info 2
已加载插件:fastestmirror, langpacks
事务 ID: 2
起始时间    : Wed Jul 15 10:43:42 2026
启动 RPM 数据库     : 1348:3761ab1722c47075353e767c2f848644a1d92fb1
结束时间       :            10:43:43 2026 (1 秒)
结束 RPM 数据库      : 1349:d17e4eb1f41abacec12ce70b178ddf65b720aa26
用户           : cyw <cyw>
返回码    : 成功
命令行   : install -y tree
事务完成属主:
    已安装 rpm-4.11.3-48.el7_9.x86_64                      @anaconda
    已安装 yum-3.4.3-168.el7.centos.noarch                 @anaconda
    已安装 yum-plugin-fastestmirror-1.1.31-54.el7_8.noarch @anaconda
已变更的包:
    安装 tree-1.6.0-10.el7.x86_64 @base
history info

undo

作用:反向操作第4个事务

[root@server ~ 14:50:47]# yum history undo 4
redo

作用:重做操作第4个事务

[root@server ~ 14:51:33]# yum history redo  4

软件包组管理

# 查看仓库中软件包组清单
[root@server ~ 14:52:10]# yum group list
......
可用的环境分组:
   最小安装
   基础设施服务器
   ......
   带 GUI 的服务器
   GNOME 桌面
   KDE Plasma Workspaces
   开发及生成工作站
可用组:
   Cinnamon
   Fedora Packager
   Haskell
   ......
   通用桌面
完成

[root@server ~ 14:53:00]# yum group list -v
.....
可用的环境分组:
   最小安装 (minimal)
   基础设施服务器 (infrastructure-server-environment)
   ......
   带 GUI 的服务器 (graphical-server-environment)
   GNOME 桌面 (gnome-desktop-environment)
   KDE Plasma Workspaces (kde-desktop-environment)
   开发及生成工作站 (developer-workstation-environment)
可用组:
   Cinnamon (cinnamon-desktop)
   Fedora Packager (fedora-packager)
   Haskell (haskell)
   ......
   通用桌面 (general-desktop)
完成

#切换成英文模式
[root@server ~ 14:53:38]# unset LANG
[root@server ~ 14:53:59]# yum group list -v
......
Available Environment Groups:
   Minimal Install (minimal)
   Compute Node (compute-node-environment)
   ......
   Server with GUI (graphical-server-environment)
   GNOME Desktop (gnome-desktop-environment)
   KDE Plasma Workspaces (kde-desktop-environment)
   Development and Creative Workstation (developer-workstation-environment)
Available Groups:
   Cinnamon (cinnamon-desktop)
   Compatibility Libraries (compat-libraries)
   Console Internet Tools (console-internet)
   ......
   Xfce (xfce-desktop)
Done

# 查看仓库中软件包组信息
[root@server ~ 14:57:08]# yum group info <tab><tab> #<tab><tab>:连按两下tab键
Display all 100 possibilities? (y or n)
Additional Development                   Java Platform
Anaconda Tools                           KDE
Backup Client                            KDE Applications
Backup Server                            KDE Multimedia Support
Base                                     KVM platform specific packages
...

[root@server ~ 14:57:30]# yum group info 'Server with GUI'

# 安装仓库中软件包组
[root@server ~ 14:58:55]# yum group install 'Server with GUI'

# 卸载仓库中软件包组
[root@server ~ 15:01:02]# yum group remove 'Server with GUI' #尽量不要卸载Server with GUI

配置 yum 仓库

yum 仓库配置

yum 工具的配置文件是 /etc/yum.conf,该文件包括两部分:

  • 全局配置:main 块,提供每个仓库默认配置
  • 每个仓库的独立配置。
[root@server ~ 15:54:08]# 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

使用如下命令查看完整的配置内容:

[root@server ~ 16:09:47]# yum install -y yum-utils

# 导出 yum 完整配置
[root@server ~ 16:10:06]# yum-config-manager 
=================================== main =====================================
[main]
alwaysprompt = True
assumeno = False
assumeyes = False
......
================================== repo: base ==================================
[base]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
......

main 部分设置全局配置:

  • enabled = 1,仓库默认启用。
  • gpgcheck = 1,仓库默认启用gpg校验。
  • keepcache = 0,不保存缓存。
  • cachedir = /var/cache/yum,缓存文件保存的位置。
  • reposdir = /etc/yum.repos.d, /etc/yum/repos.d,yum仓库配置文件。

yum管理的软件包存放在yum仓库,yum仓库配置文件存放在/etc/yum.repos.d目录。

[root@server ~ 16:10:50]# ls /etc/yum.repos.d/
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo
CentOS-CR.repo         CentOS-Media.repo      CentOS-x86_64-kernel.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    epel.repo

[root@server ~ 16:11:47]# ls /etc/yum/repos.d /etc/distro.repos.d
ls: 无法访问/etc/yum/repos.d: 没有那个文件或目录
ls: 无法访问/etc/distro.repos.d: 没有那个文件或目录
[root@server ~ 16:12:57]# ls /etc/yum/repos.d /etc/yum.repos.d
ls: 无法访问/etc/yum/repos.d: 没有那个文件或目录
/etc/yum.repos.d:
CentOS-Base.repo       CentOS-fasttrack.repo  CentOS-Vault.repo
CentOS-CR.repo         CentOS-Media.repo      CentOS-x86_64-kernel.repo
CentOS-Debuginfo.repo  CentOS-Sources.repo    epel.repo

yum 仓库管理

查看 yum 仓库
# 查看启用的yum仓库
[root@server ~ 16:13:19]# yum repolist 
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识                     源名称                                                   状态
base/7/x86_64              CentOS-7 - Base - mirrors.aliyun.com                     10,072
epel/x86_64                Extra Packages for Enterprise Linux 7 - x86_64           13,791
extras/7/x86_64            CentOS-7 - Extras - mirrors.aliyun.com                      526
updates/7/x86_64           CentOS-7 - Updates - mirrors.aliyun.com                   6,173
repolist: 30,562

# 查看 yum 所有仓库,包括未启用的仓库
[root@server ~ 16:14:08]# yum repolist all
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
源标识                              源名称                                    状态
C7.0.1406-base/x86_64               CentOS-7.0.1406 - Base                    禁用
C7.0.1406-centosplus/x86_64         CentOS-7.0.1406 - CentOSPlus              禁用
C7.0.1406-extras/x86_64             CentOS-7.0.1406 - Extras                  禁用
C7.0.1406-fasttrack/x86_64          CentOS-7.0.1406 - Fasttrack               禁用
C7.0.1406-updates/x86_64            CentOS-7.0.1406 - Updates                 禁用
...
启用和禁用仓库
# 启用
[root@server ~ 16:14:31]# yum-config-manager --enable epel-debuginfo

# 禁用
[root@server ~ 16:15:35]# yum-config-manager --disable epel-debuginfo

也可以编辑仓库配置文件,将仓库中enabled值设置为1启用,设置为0禁用。

# 查看禁用的仓库清单
[root@server ~ 16:16:03]# vim /etc/yum.repos.d/epel.repo 
 1 [epel]
  2 name=Extra Packages for Enterprise Linux 7 - $basearch
  3 baseurl=http://mirrors.aliyun.com/epel/7/$basearch
  4 failovermethod=priority
  5 enabled=1      #将enabled设置为1启用,设置为0禁用
  6 gpgcheck=0
  7 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
  8 
  9 [epel-debuginfo]
 10 name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
 11 baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
 12 failovermethod=priority
 13 enabled=0
 14 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 15 gpgcheck=0
 16 
 17 [epel-source]
 18 name=Extra Packages for Enterprise Linux 7 - $basearch - Source
 19 baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
 20 failovermethod=priority
 21 enabled=0
 22 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
 23 gpgcheck=0

仓库缓存管理

更新缓存后,yum install命令可补全软件包名称。

# 清理缓存数据
[root@server ~ 16:17:46]# yum clean  <tab><tab>
all           dbcache       headers       packages      
cache         expire-cache  metadata 

# 清理所有缓存数据
[root@server ~ 16:19:37]# yum clean all

# 创建缓存数据
[root@server ~ 16:19:46]# yum makecache 
已加载插件:fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.aliyuncs.com
 * extras: mirrors.aliyuncs.com
 * updates: mirrors.aliyuncs.com
base                                                               | 3.6 kB  00:00:00     
epel                                                               | 4.3 kB  00:00:00     
extras                                                             | 2.9 kB  00:00:00     
updates                                                            | 2.9 kB  00:00:00     
(1/16): base/7/x86_64/group_gz                                     | 153 kB  00:00:02 
...
(16/16): updates/7/x86_64/primary_db                               |  27 MB  00:00:43     
元数据缓存已建立

添加 kubernetes 仓库
[root@server ~ 16:25:00]#  yum-config-manager --add-repo=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
已加载插件:fastestmirror, langpacks
adding repo from: https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/

[mirrors.aliyun.com_kubernetes_yum_repos_kubernetes-el7-x86_64_]
name=added from: https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
baseurl=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
enabled=1

# 安装 kubectl 包
[root@server ~ 16:36:40]# yum install kubectl --nogpgcheck

添加 docker-ce 仓库
[root@server ~ 16:38:10]#  cat << 'EOF' > /etc/yum.repos.d/docker-ce.repo
> [docker-ce-stable]
> name=Docker CE Stable - $basearch
> baseurl=https://mirrors.aliyun.com/docker-ce/linux/centos/$releasever/$basearch/stable
> enabled=1
> gpgcheck=0
> EOF

# 查看docker版本
[root@server ~ 16:38:45]# yum list docker-ce
已加载插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyuncs.com
 * extras: mirrors.aliyuncs.com
 * updates: mirrors.aliyuncs.com
docker-ce-stable                                                   | 3.5 kB  00:00:00     
(1/2): docker-ce-stable/7/x86_64/primary_db                        | 152 kB  00:00:00     
(2/2): docker-ce-stable/7/x86_64/updateinfo                        |   55 B  00:00:06     
可安装的软件包
docker-ce.x86_64                      3:26.1.4-1.el7                      docker-ce-stabl

epel 仓库

EPEL(Extra Packages for Enterprise Linux),是由Fedora Special Interest Group维护的Enterprise Linux(RHEL、CentOS)中经常用到的包。

# 直接使用aliyun的源
[root@server ~ 16:39:32]# curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

源码安装软件

源码安装 nginx

介绍

Nginx是一个高性能的HTTP和反向代理web服务器。

官方地址:https://nginx.org

安装
# 安装依赖
[root@server ~ 09:38:21]# yum install gcc make pcre-devel zlib-devel

# 下载
[root@server ~ 09:41:37]# wget https://nginx.org/download/nginx-1.24.0.tar.gz

# 解压
[root@server ~ 09:42:04]# tar -xf nginx-1.24.0.tar.gz 


# 配置
[root@server ~ 09:42:39]# cd nginx-1.24.0/ 
[root@server nginx-1.24.0 09:43:06]# ./configure --prefix=/usr/local/nginx
# 将所有的nginx相关文件存放在/usr/local/nginx

# 编译安装
[root@server nginx-1.24.0 09:45:39]# make && make install
[root@server nginx-1.24.0 09:45:44]# ls /usr/local/nginx/
conf  html  logs  sbin

# 配置环境变量
[root@server nginx-1.24.0 09:46:46]# export PATH=$PATH:/usr/local/nginx/sbin/
[root@server nginx-1.24.0 09:47:12]#  echo 'export PATH=$PATH:/usr/local/nginx/sbin/' >> ~/.bashrc

使用
# 启动服务
[root@server nginx-1.24.0 09:47:26]# nginx 
# 验证
[root@server nginx-1.24.0 09:47:48]# curl -s http://localhost | grep Thank
<p><em>Thank you for using nginx.</em></p>
[root@server nginx-1.24.0 09:48:40]# 

#在浏览器登录10.1.8.10,即可看到添加的内容(如下图)
#关闭防火墙
[root@server nginx-1.24.0 09:48:42]# systemctl disable firewalld.service --now
Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
#添加内容
[root@server nginx-1.24.0 10:02:35]#  echo 'cyw:welcome to my classroom'>/usr/local/nginx/html/index.html

#也可通过命令行查看
[root@server nginx-1.24.0 10:08:24]# curl 10.1.8.10
cyw:welcome to my classroom


# 退出服务
[root@server nginx-1.24.0 10:04:54]# nginx -s quit

在这里插入图片描述

命令总结:

  • nginx,启动服务
  • nginx -s quit,待nginx进程处理任务完毕进行停止。
  • nginx -s stop,查出nginx进程id再使用kill命令强制杀掉进程。
  • nginx -s reload,重新加载服务。
配置nginx服务
[root@server ~ 12:29:06]# cp /usr/lib/systemd/system/sshd.service /etc/systemd/system/nginx.service
[root@server ~ 12:29:13]# vim /etc/systemd/system/nginx.service

[Unit]
Description=Nginx server daemon

[Service]
Type=forking
ExecStart=/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
ExecReload=/usr/local/nginx/sbin/nginx -s reload
ExecStop=/usr/local/nginx/sbin/nginx -s quit

[Install]
WantedBy=multi-user.target

[root@server ~ 12:32:33]# systemctl daemon-reload
[root@server ~ 12:32:42]#  systemctl enable nginx.service --now
Created symlink from /etc/systemd/system/multi-user.target.wants/nginx.service to /etc/systemd/system/nginx.service.

源码安装 cmatrix

介绍

Cmatrix 是一款 Linux 环境下的炫酷屏保软件其效果类似于黑客帝国电影中的代码雨。

在这里插入图片描述

项目地址:https://github.com/abishekvashok/cmatrix

安装
# 安装依赖包
[root@server ~ 18:36:38]# yum -y install gcc make autoconf ncurses-devel

# 下载
[root@server ~ 18:42:42]# wget http://192.168.50.200/class/course-materials/softwares/stage01/cmatrix-1.2.tar.gz

# 解压
[root@server ~ 18:42:57]# tar -xf cmatrix-1.2.tar.gz 

# 配置软件
[root@server ~ 18:43:19]# cd cmatrix-1.2/
[root@server cmatrix-1.2 18:43:26]# ./configure --prefix=/usr/local/cmatrix

# 编译并安装
[root@server cmatrix-1.2 18:44:53]# make && make install

使用
# 配置环境变量
[root@server cmatrix-1.2 18:45:48]# export PATH=$PATH:/usr/local/cmatrix/bin

# 帮助信息
[root@server cmatrix-1.2 18:46:52]# cmatrix -h
 Usage: cmatrix -[abBfhlsVx] [-u delay] [-C color]
 -a: Asynchronous scroll
 -b: Bold characters on
 -B: All bold characters (overrides -b)
 -f: Force the linux $TERM type to be on
 -l: Linux mode (uses matrix console font)
 -o: Use old-style scrolling
 -h: Print usage and exit
 -n: No bold characters (overrides -b and -B, default)
 -s: "Screensaver" mode, exits on first keystroke
 -x: X window mode, use if your xterm is using mtx.pcf
 -V: Print version information and exit
 -u delay (0 - 10, default 4): Screen update delay
 -C [color]: Use this color for matrix (default green)

# 执行
[root@server cmatrix-1.2 18:47:17]# cmatrix 

在这里插入图片描述

[root@server cmatrix-1.2 18:48:08]# cmatrix -b -u 3 -C red
# -b 加粗字体
# -u 滚动速度
# -C 字体颜色 绿色(green)、红色(red)、蓝色(blue)、白色(white)、黄色(yellow)、青色(cyan)、洋红色(magenta)以及黑色(black)这些颜色。

在这里插入图片描述

随时改变颜色

当然,你无需重新启动程序,就可以随时改变显示的颜色。但需要记住,不同的键位对应着不同的颜色。在 Cmatrix 未关闭的情况下,如果你按下了存储在键位上的指令,显示的颜色将会直接变更。

颜色相应键位对应数字键
红色!shift+1
绿色@shift+2
黄色#shift+3
蓝色$shift+4
洋红色%shift+5
青色^shift+6
白色&shift+7
黑色)shift+8
自由调整速度

在 Cmatrix 运行的过程中,你可以按 09 的任何一位数字键来随意改变当前的更新速度。

自建仓库

自建仓库流程

  1. 准备软件包
  2. 创建仓库索引信息
  3. 发布仓库
  4. 客户端配置验证

详细操作步骤

  1. 准备软件包

    [root@server ~ 10:59:48]# mkdir rpms
    [root@server ~ 11:06:02]# cd rpms/
    # 下载软件包,以及依赖的软件包
    [root@server rpms 11:07:36]#  yum install --downloadonly --downloaddir . vim open-vm-tools vsftpd lrzsz bash-completion nginx httpd mariadb-server
    
    # 移动软件包到发布目录
    [root@server ~ 11:08:50]# mkdir /usr/local/nginx/html/tools 
    [root@server ~ 11:09:13]# mv rpms /usr/local/nginx/html/tools/Packages
    
    
  2. 创建仓库

    # 安装创建仓库软件包
    [root@server ~ 11:10:04]# yum install -y createrepo
    
    # 创建仓库索引信息
    [root@server ~ 11:11:01]# createrepo /usr/local/nginx/html/tools/
    
    
  3. 使用上一步源码安装的nginx服务器

    [root@server ~ 11:11:49]# vim /usr/local/nginx/conf/nginx.conf
    # 在http块中新增一行autoindex on
    # 作用:提供文件清单
    http {
        autoindex on;
    .....
    
    # 重启nginx服务
    [root@server ~ 11:23:08]#  systemctl reload nginx
    
    
  4. 客户端配置验证

    # 备份原有仓库
    [root@client ~ 09:20:04]# mkdir /etc/yum.repos.d/old
    [root@client ~ 11:24:12]# mv /etc/yum.repos.d/*repo /etc/yum.repos.d/old
    
    # 添加新仓库
    [root@client ~ 11:24:48]# cat << 'EOF' > /etc/yum.repos.d/tools.repo
    > [tools]
    > name=centos7 tools from server.cyw
    > baseurl=http://server.cyw/tools/
    > enabled=1
    > gpgcheck=0
    > EOF
    [root@client ~ 11:25:29]# ls /etc/yum.repos.d/
    old  tools.repo
    
    # 安装软件包
    [root@client ~ 11:26:04]# yum install -y httpd
    
    

同步仓库

# 将仓库中软件包和元数据全部同步到本地
[root@client ~ 13:40:01]#  reposync --repoid=tools --download-metadata
[root@client ~ 13:41:31]#  createrepo tools
Spawning worker 0 with 5 pkgs
Spawning worker 1 with 4 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete

[root@client ~ 13:42:00]# ls tools/
Packages  repodata

参考:yum-REPOSYNC(8)

CentOS 运维避坑实战

CentOS7.9 安装 Python3.8.16 后 yum 报错,快速修复方案

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值