1. Cockpit 管理服务器
Cockpit 是一个开源工具,通过Web Console管理Linux服务器。
部署 Cockpit
bash
# 安装软件包
[root@server ~]# yum -y install cockpit
# 启用并启动服务
[root@server ~]# systemctl enable cockpit.socket --now
# 配置防火墙放行 cockpit 服务
[root@server ~]# firewall-cmd --add-service=cockpit
success
[root@server ~]# firewall-cmd --add-service=cockpit --permanent
success
使用 Cockpit
登录 Cockpit
打开浏览器,访问Cockpit界面:https://hostname:9090
hostname是一个可以解析的域名或者直接使用IP地址。
windows 配置解析位置:C:\Windows\System32\drivers\etc\hosts
添加对应记录:
10.1.8.10 server.laoma.cloud
在Cockpit上,操作均为可视化图像操作
扩展 Cockpit
安装Cockpit扩展包
查看Cockpit扩展包:
外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传
部分扩展包说明:
-
cockpit-dashboard,提供管理多个Linux界面。
-
cockpit-docker,管理docker容器。
-
cockpit-composer,管理容器镜像。
-
cockpit-kubernetes,管理kubernetes。
-
cockpit-machines,管理kvm虚拟机。
-
cockpit-packagekit,管理软件包。
-
cockpit-storaged,管理存储。
-
cockpit-doc,Cockpit说明文档。
bash
[root@server ~]# yum install -y cockpit-composer cockpit-dashboard cockpit-doc cockpit-docker cockpit-kubernetes cockpit-machines cockpit-packagekit cockpit-storaged
安装完成后,注销账户重新登录。
2. Linux 软件包管理
分析 RPM 包
Linux 发行版本
-
以 RHEL 为代表的发行版本,使用rpm包管理系统:
- RHEL (Red Hat Enterprise Linux)
- Fedora(由原来的RedHat桌面版本发展而来,免费版本)
- CentOS(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软件包进行数字签名。 RPM系统通过确认包由相应的GPG密钥签名来验证包的完整性。 如果GPG签名不匹配,RPM系统拒绝安装包。
非对称加密:有一对公钥和私钥。
- 公钥:分享给别人,用来加密数据。
- 私钥:自己保留,用来解密公钥加密的数据。
Linux中rpm包会被私钥签名,客户端使用公钥验证签名,确保文件的完整性。
复习私钥和公钥及其交互性
一、公钥与私钥的区分(对应流程中的文件)
在整个 SSH 密钥对生成与使用过程中,公钥和私钥是成对生成、用途完全不同的两个文件,具体对应如下:
| 类型 | 文件名 | 存储位置 | 核心特征(如何区分) | 用途 |
|---|---|---|---|---|
| 私钥 | id_rsa |
仅客户端(~/.ssh/) |
1. 无.pub后缀;2. 权限默认600(仅所有者可读可写);3. 系统提示 "Your identification has been saved in..."(identification即私钥) |
客户端保留,用于解密服务器用公钥加密的信息,是免密登录的 "身份凭证",绝对不能泄露。 |
| 公钥 | id_rsa.pub |
客户端生成 + 服务器存储 | 1. 有.pub后缀(pub即 "public",公开);2. 内容以ssh-rsa开头(RSA 算法标识);3. 系统提示 "Your public key has been saved in..." |
可公开分享,推送到服务器后存入~/.ssh/authorized_keys,用于加密服务器生成的随机字符串,验证客户端身份。 |
| 服务器端公钥存储 | authorized_keys |
仅服务器(目标用户~/.ssh/) |
1. 无固定后缀,是文本文件;2. 内容是客户端id_rsa.pub的完整内容(可多个客户端公钥追加) |
服务器查询此文件,确认客户端公钥是否已授权,是免密登录的 "授权列表"。 |
二、交互式与非交互式的判定(对应流程中的操作)
"交互式" 指操作过程中需要手动输入信息(如路径、密码)才能继续 ;"非交互式" 指操作无需人工干预,通过预设参数或脚本自动完成。你提供的流程中,核心操作均为 "交互式",具体分析如下:
1. 关键交互式操作(需手动输入 / 确认)
注意密钥 : 在server上完成相应操作,能够登陆另一个账号
bash
#一直按回车
[root@server ~ 18:30:53]# ssh-keygen
#输入的密码为另一个账号的密码
[root@server ~ 19:05:05]# ssh-copy-id root@client
配置名称解析 :可以用ssh快捷登陆
bash
[root@server ~ 18:58:14]# vim /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.1.8.10 server.lzh.cloud server
10.1.8.11 client.lzh.cloud client
整个流程中,以下步骤需要你主动输入或回车确认,符合 "交互式" 的定义:
-
步骤 1:
ssh-keygen生成密钥对时执行
ssh-keygen后,系统会弹出 3 次交互提示,必须手动响应才能继续:-
Enter file in which to save the key:确认私钥保存路径(你选择回车用默认路径); -
Enter passphrase (empty for no passphrase):设置私钥加密密码(你选择回车不设置); -
Enter same passphrase again:重复确认密码(你再次回车)。bash[root@server ~ 18:30:53]# ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/root/.ssh/id_rsa): Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /root/.ssh/id_rsa. Your public key has been saved in /root/.ssh/id_rsa.pub. The key fingerprint is: SHA256:V0UhXWOD5wuUPi6U3M2Y2sqFcSpMn434rRe2dzPR7PU root@server.lzh.cloud The key's randomart image is: +---[RSA 2048]----+ | .o**.| | *o.o| | . * B | | . * O + | | S = % o.o| | = O B o+| | + * o.+| | + + +E| | .o . +| +----[SHA256]-----+
-
-
步骤 2:
ssh-copy-id liuzihang@server推送公钥时首次推送公钥到服务器,系统会:
-
提示 "Are you sure you want to continue connecting (yes/no/[fingerprint])?"(确认信任服务器,需输入
yes); -
提示输入服务器目标用户(
liuzihang)的登录密码(验证你有权限向该用户目录写入公钥);以上均需手动输入,属于交互式。
bash[root@server ~ 19:05:05]# ssh-copy-id root@client /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/root/.ssh/id_rsa.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root@client's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'root@client'" and check to make sure that only the key(s) you wanted were added.
-
-
步骤 3:
ssh liuzihang@server hostname验证登录时若私钥设置了密码(你未设置),首次登录会提示 "Enter passphrase for key '/home/liuzihang/.ssh/id_rsa'"(输入私钥密码),也属于交互式;即使你未设私钥密码,首次登录仍需确认服务器指纹(已在
ssh-copy-id时确认过,后续可免)。bash[root@server ~ 19:05:55]# ssh client Last login: Wed Nov 12 18:30:55 2025 from 10.1.8.1 [root@client ~ 19:06:40]# l
2. 非交互式的对比(补充说明)
若想将上述操作改为 "非交互式",需通过预设参数跳过手动输入,例如:
-
非交互式生成密钥对(指定路径、无密码):
bash# ssh-keygen -t rsa是用于生成 RSA 算法的 SSH 密钥对的命令 # -f 指定路径,-N "" 设空密码,无任何交互提示 ssh-keygen -t rsa -f ~/.ssh/id_rsa -N "" -
非交互式推送公钥(需提前用
ssh-keyscan信任服务器指纹,且服务器开启免密 sudo 等):bash# 先信任服务器指纹,再推送公钥(需提前知道服务器密码,用管道输入) ssh-keyscan server >> ~/.ssh/known_hosts && echo "服务器密码" | sshpass -p "服务器密码" ssh-copy-id liuzihang@server但你的实操流程中未使用任何预设参数,全程依赖手动响应,因此不属于非交互式。
总结
- 公钥 / 私钥 :客户端
id_rsa是私钥(保密),id_rsa.pub是公钥(可分享),服务器authorized_keys是公钥的 "授权集合"; - 交互性 :你提供的所有操作(
ssh-keygen、ssh-copy-id、ssh登录)均为交互式,核心特征是需要手动输入确认信息。
RPM 包安装和更新
- 如果同一个软件有多个版本,只需安装最高版本。
- 在大多数情况下,一个软件只能安装一个版本。 kernel是个例外。如果构建包的文件名没有冲突,则可以安装多个版本。 由于只能通过引导到该内核来测试新内核,因此特定设计了包,以便可以一次安装多个版本。如果内核无法启动,则旧内核仍然可用且可引导。
- 软件包升级只需要安装最新版本,不需要逐步升级。
- 升级RPM包将删除旧版本的软件包并安装新版本,通常会保留配置文件。
RPM 命令查询功能速查表(重点)
基于 rpm {-q|--query} 核心语法,按「查询范围」「查询内容」「高频示例」分类整理,简洁易懂,覆盖日常运维核心场景。
一、查询范围(select-options):指定「查哪个包」
| 选项 | 完整写法 | 功能说明 | 适用场景 |
|---|---|---|---|
| 无 | - | 直接跟随已安装包名(如 nginx、python3) |
查询单个已安装包 |
-a |
--all |
查询所有已安装的 RPM 软件包 | 批量排查已安装软件 |
-f |
--file |
后跟文件路径(如 /usr/bin/ls),查询该文件所属的已安装包 |
定位文件归属 |
-g |
--group |
后跟软件包组(如 Development Tools、System Tools),按组查询已安装包 |
按功能分类查包 |
-p |
--package |
后跟未安装的 RPM 文件路径(如 nginx-1.24.0-1.el9.x86_64.rpm) |
安装前检查未安装包信息 |
| - | --whatprovides |
后跟「能力」(如 libssl.so.3、vim),查询提供该能力的已安装包 |
解决依赖缺失问题 |
| - | --whatrequires |
后跟「能力」(如 libc.so.6),查询依赖该能力的已安装包 |
评估删除包的影响 |
二、查询内容(query-options):指定「查包的什么信息」
| 选项 | 完整写法 | 功能说明 | 关键场景 |
|---|---|---|---|
-i |
--info |
显示包的基本信息(版本、安装时间、开发者、包描述、发布版本等) | 快速了解包详情 |
-l |
--list |
列出包的所有已安装文件路径(二进制文件、配置文件、日志目录等) | 查找包安装位置 |
-c |
--configfiles |
仅列出包的配置文件路径 (如 /etc/nginx/nginx.conf) |
备份/修改配置文件 |
-d |
--docfiles |
仅列出包的文档文件路径(手册、README、示例代码等) | 查找官方文档 |
-R |
--requires |
列出包运行时依赖的能力(依赖的库文件、命令、其他软件包等) | 解决安装/运行依赖问题 |
| - | --provides |
列出包提供的能力(命令、库文件、自定义依赖能力等) | 确认是否满足其他依赖 |
| - | --changelog |
显示包的更新日志(版本迭代记录、修复的 Bug、新增功能、安全补丁等) | 排查版本变更问题 |
| - | --scripts |
显示包的脚本片段(安装前 preinstall、安装后 postinstall、卸载脚本等) |
分析包自动操作逻辑 |
-s |
--state |
显示包文件状态(正常 normal、缺失 missing、修改 modified 等) |
检查文件是否篡改/丢失 |
三、高频查询示例(组合用法)
| 需求场景 | 命令 | 说明 |
|---|---|---|
查看已安装 nginx 的基本信息 |
rpm -qi nginx |
确认 nginx 是否安装、安装版本、发布版本等核心信息 |
定位 /usr/bin/ls 所属包 |
rpm -qf /usr/bin/ls |
通常返回 coreutils-xxx(ls 是 coreutils 包的核心命令) |
列出 nginx 所有安装文件 |
rpm -ql nginx |
快速找到 nginx 的二进制文件、配置目录、日志目录等路径 |
仅查看 nginx 的配置文件 |
rpm -qc nginx |
直接定位可修改的配置文件(无需遍历所有安装文件) |
| 检查未安装 RPM 包的依赖 | rpm -qpR nginx-1.24.0-1.el9.x86_64.rpm |
安装前确认需提前安装的依赖包,避免安装失败 |
查询依赖 libc.so.6 的包 |
rpm -q --whatrequires libc.so.6 |
评估删除 libc.so.6 相关包的影响(避免误删导致系统故障) |
查看 nginx 的版本更新日志 |
rpm -q --changelog nginx |
了解 nginx 版本迭代记录,排查是否因版本更新导致功能异常 |
检查 nginx 配置文件是否修改 |
rpm -qs nginx |
查看 nginx 所有文件状态,重点关注配置文件是否被篡改(状态为 modified) |
示例:
bash
# 查询系统中安装了哪些软件包
[root@centos7 ~]# 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@centos7 ~]# rpm -q httpd
未安装软件包 httpd
[root@centos7 ~]# rpm -q kernel
kernel-3.10.0-1160.71.1.el7.x86_64
# 查询系统中某个已安装的软件包元数据信息
[root@centos7 ~]# rpm -q coreutils -i
Name : coreutils
Version : 8.22
Release : 24.el7_9.2
Architecture: x86_64
Install Date: 2025年07月18日 星期五 10时29分40秒
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@centos7 ~]# 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@centos7 ~]# rpm -q openssh-server -c
/etc/pam.d/sshd
/etc/ssh/sshd_config
/etc/sysconfig/sshd
# 查询系统中某个已安装的软件包"包涵哪些文档文件"
[root@centos7 ~]# 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@centos7 ~]# rpm -q -f /etc/ssh/sshd_config
openssh-server-7.4p1-22.el7_9.x86_64
# 查询系统中某个已安装的软件包"包涵的脚本"
[root@centos7 ~]# rpm -q openssh-server --scripts
preinstall scriptlet (using /bin/sh):
......
postinstall scriptlet (using /bin/sh):
......
preuninstall scriptlet (using /bin/sh):
......
postuninstall scriptlet (using /bin/sh):
......
# 查询系统中某个已安装的软件包变更日志
[root@centos7 ~]# rpm -q openssh-server --changelog
* 四 9月 30 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)
......
# 下载 httpd 软件包,以及依赖的其他软件包
[root@centos7 ~]# yumdownloader httpd
[root@centos7 ~]# ls httpd-*
httpd-2.4.6-99.el7.centos.1.x86_64.rpm
# 查询系统中某个软件包(package)文件包涵哪些配置文件
[root@centos7 ~]# 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
......
# 同样-l -d -i也可以配置-p使用
# 查询系统中某个软件包组中包涵哪些软件包
[root@centos7 ~]# rpm -qg 'System Environment/Base'
grub2-common-2.02-0.87.0.1.el7.centos.9.noarch
centos-release-7-9.2009.1.el7.centos.x86_64
setup-2.8.71-11.el7.noarch
filesystem-3.2-25.el7.x86_64
......
扩展
bash
# 查看软件包所在仓库精确位置
[root@centos7 ~]# 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@centos7 ~]# wget \
http://mirrors.aliyun.com/centos/7/updates/x86_64/Packages/httpd-2.4.6-99.el7.centos.1.x86_64.rpm
验证
基本语法:
ini
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]
示例:
bash
# 查看openssh-server软件安装是否有问题
[root@centos7 ~]# rpm -V openssh-server
# 修改(change)
[root@centos7 ~]# sed -i 's/PermitRootLogin yes/PermitRootLogin no/g' /etc/ssh/sshd_config
[root@centos7 ~]# rpm -V openssh-server
S.5....T. c /etc/ssh/sshd_config
[root@centos7 ~]# sed -i 's/PermitRootLogin no/PermitRootLogin yes/g' /etc/ssh/sshd_config
# 移走 /etc/ssh/sshd_config 文件,再次查看
[root@centos7 ~]# mv /etc/ssh/sshd_config .
[root@centos7 ~]# rpm -V openssh-server
遗漏 c /etc/ssh/sshd_config
# 恢复该文件到原来位置
[root@centos7 ~]# mv sshd_config /etc/ssh/sshd_config
安装和卸载
示例:
bash
# 查询下载软件包地址
[root@centos7 ~]# repoquery --location lrzsz
http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm
#根据地址下载软件包
[root@centos7 ~]# wget http://mirrors.aliyun.com/centos/7/os/x86_64/Packages/lrzsz-0.12.20-36.el7.x86_64.rpm
lrzsz-0.12.20-36.el7.x86_64.rpm
# 安装
[root@centos7 ~]# rpm -i lrzsz-0.12.20-36.el7.x86_64.rpm
[root@centos7 ~]# rpm -q lrzsz
lrzsz-0.12.20-36.el7.x86_64
# 卸载
[root@centos7 ~]# rpm -e lrzsz
[root@centos7 ~]# rpm -q lrzsz
未安装软件包 lrzsz
# 友好方式安装
[root@centos7 ~]# rpm -ivh lrzsz-0.12.20-36.el7.x86_64.rpm
Verifying... ################################ [100%]
准备中... ################################ [100%]
正在升级/安装...
1:lrzsz-0.12.20-36.el7 ################################ [100%]
# 友好方式卸载
[root@centos7 ~]# rpm -evh lrzsz
准备中... ################################ [100%]
正在清理/删除...
1:lrzsz-0.12.20-36.el7 ################################ [100%]
# 安装 httpd,报错如下,下一节讲解如下解决
# 安装准备:确保系统中没有提供httpd需要的依赖包
[root@centos7 ~]# rpm -e apr apr-util httpd-tools mailcap
[root@centos7 ~]# 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 需要
重新安装
bash
[root@centos7 ~]# rpm --reinstall -vh lrzsz*
Verifying... ################################ [100%]
准备中... ################################ [100%]
正在升级/安装...
1:lrzsz-0.12.20-36.el7 ################################ [100%]
提取 RPM 包中文件
Windows 提取
使用压缩工具(例如360压缩)打开rpm包,浏览和提取。
Linux 提取
-
方法一:分步骤提取
bash# 将文件转换为cpio格式 [root@centos7 ~]# 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@centos7 ~]# 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@centos7 ~]# 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 19331 blocks # 提取所有文件,-d选项指明提取过程中创建对应的目录分层结构 [root@centos7 ~]# cpio -id '*' < httpd-2.4.6-99.el7.centos.1.x86_64.cpio # 提取特定文件 [root@centos7 ~]# cpio -id ./etc/httpd/conf/httpd.conf < httpd-2.4.6-99.el7.centos.1.x86_64.cpio -
方法二:一步提取所有文件
bash[root@centos7 ~]# rpm2cpio httpd-2.4.6-99.el7.centos.1.x86_64.rpm | cpio -id '*'
使用 yum 管理软件包
yum 介绍
- rpm 命令是一个管理软件包的工具,不适用于软件包存储库或自动解决来自多个源的依赖项。
- Yum(Yellowdog Updater Modified)旨在成为管理基于RPM的软件安装和更新的更好系统。yum命令允许安装,更新,删除和获取有关软件包及其依赖项的信息。
yum 命令
bash
# 查看yum命令帮助信息
[root@centos7 ~]# yum help
# 查看仓库中httpd包信息
[root@server ~ 19:51:15]# yum list 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.
# 查看仓库中http开头的包有哪些
[root@server ~ 19:51:41]# 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
http-parser-devel.i686 2.7.1-9.el7 base
......
# 查看仓库中httpd包有哪些版本
[root@server ~ 19:51:46]# 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
# 查看简介包含关键字的软件包
[root@centos7 ~]# yum search 'web server'
# 查看描述和简介包含关键字的软件包
[root@centos7 ~]# yum search all 'web server'
# 查看仓库中哪个包可以提供文件sar程序
[root@centos7 ~]# yum provides 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
sysstat-10.1.5-20.el7_9.x86_64 : Collection of performance monitoring tools for Linux
源 :updates
匹配来源:
文件名 :/usr/bin/sar
# 安装sar工具对应的软件包
[root@centos7 ~]# yum install -y sysstat
# 只下载不安装
[root@centos7 ~]# yum install vsftpd --downloadonly --downloaddir=/root/
[root@centos7 ~]# ls vsftpd-*
vsftpd-3.0.2-29.el7_9.x86_64.rpm
# 安装本地文件系统中vsftpd包
[root@centos7 ~]# yum localinstall ./vsftpd-3.0.2-29.el7_9.x86_64.rpm
# 降级 vsftpd 版本为 3.0.2-28.el7
[root@centos7 ~]# yum downgrade -y vsftpd-3.0.2-28.el7
# 升级 vsftpd 版本为 3.0.2-29.el7_9
[root@centos7 ~]# yum update vsftpd-3.0.2-29.el7_9
# 升级系统中所有软件为最新版本
[root@centos7 ~]# yum update
# 卸载软件包
[root@centos7 ~]# yum remove -y vsftpd
依赖降级示例:
bash
# 环境准备:安装最新版httpd
[root@centos7 ~]# yum install -y httpd
# 降级到特定版本:降级失败,因为已安装的 httpd-tools 无法满足当前httpd版本
[root@centos7 ~]# 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-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@centos7 ~]# yum downgrade -y httpd-tools-2.4.6-97.el7.centos httpd-2.4.6-97.el7.centos
软件包组管理
bash
# 查看仓库中软件包组清单
[root@centos7 ~]# yum grouplist
......
可用的环境分组:
最小安装
基础设施服务器
......
带 GUI 的服务器
GNOME 桌面
KDE Plasma Workspaces
开发及生成工作站
可用组:
Cinnamon
Fedora Packager
Haskell
......
通用桌面
完成
[root@centos7 ~]# yum grouplist -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@centos7 ~]# unset LANG
[root@centos7 ~]# 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@centos7 ~]# yum groupinfo <tab><tab>
[root@centos7 ~]# yum groupinfo 'Server with GUI'
# 安装仓库中软件包组
[root@centos7 ~]# yum groupinstall 'Server with GUI'
# 卸载仓库中软件包组
[root@centos7 ~]# yum groupremove 'Server with GUI'
配置 yum 仓库
yum 仓库配置
yum 工具的配置文件是 /etc/yum/yum.conf,该文件包括两部分:
- main,yum全局配置,提供每个仓库部分参数默认值。
- 每个仓库的独立配置。
bash
[root@server ~ 13:40:42]# 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
使用如下命令查看完整的配置内容:
bash
[root@server ~ 13:42:29]# yum install -y yum-utils
# 导出 yum 完整配置
[root@server ~ 13:42:52]# yum-config-manager
Loaded plugins: fastestmirror, langpacks
=================================== 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目录。
bash
[root@server ~ 13:46:05]# 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 ~ 13:47:29]# ls /etc/yum/repos.d /etc/distro.repos.d
ls: 无法访问/etc/yum/repos.d: 没有那个文件或目录
ls: 无法访问/etc/distro.repos.d: 没有那个文件或目录
yum 仓库管理
查看 yum 仓库
bash
# 查看启用的yum仓库
[root@server ~ 13:47:49]# yum repolist
源标识 源名称 状态
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 ~ 13:48:49]# yum repolist all
启用和禁用仓库
bash
# 启用
[root@server ~ 13:54:24]# yum-config-manager --enable epel-debuginfo
# 禁用
[root@server ~ 13:55:23]# yum-config-manager --disable epel-debuginfo
也可以编辑仓库配置文件,将仓库中enabled值设置为1启用,设置为0禁用。
bash
# 查看禁用的仓库清单
[root@server ~ 13:55:42]# vim /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
baseurl=http://mirrors.aliyun.com/epel/7/$basearch
failovermethod=priority
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 7 - $basearch - Debug
baseurl=http://mirrors.aliyun.com/epel/7/$basearch/debug
failovermethod=priority
# 将enabled设置为1启用,设置为0禁用
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
[epel-source]
name=Extra Packages for Enterprise Linux 7 - $basearch - Source
baseurl=http://mirrors.aliyun.com/epel/7/SRPMS
failovermethod=priority
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7
gpgcheck=0
仓库缓存管理
更新缓存后,yum install命令可补全软件包名称。
bash
# 清理缓存数据
[root@server ~ 13:57:18]# yum clean <tab><tab>
all dbcache headers packages
cache expire-cache metadata
# 清理所有缓存数据
[root@server ~ 13:57:18]# yum clean all
# 创建缓存数据
[root@server ~ 13:58:20]# yum makecache
base | 3.6 kB 00:00:00
epel | 4.3 kB 00:00:00
epel-debuginfo | 3.0 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
元数据缓存已建立
添加 kubernetes 仓库
bash
[root@centos7 ~]# yum-config-manager --add-repo=https://mirrors.aliyun.com/kubernetes/yum/repos/kubernetes-el7-x86_64/
[root@centos7 ~]# cat /etc/yum.repos.d/mirrors.aliyun.com_kubernetes_yum_repos_kubernetes-el7-x86_64_.repo
[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@centos7 ~]# yum install kubectl --nogpgcheck
添加 docker-ce 仓库
bash
[root@centos7 ~]# 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@centos7 ~]# yum list docker-ce
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.ustc.edu.cn
* extras: mirrors.ustc.edu.cn
* updates: mirrors.ustc.edu.cn
Available Packages
docker-ce.x86_64 3:20.10.22-3.el7 docker-ce-stabl
epel 仓库
EPEL(Extra Packages for Enterprise Linux),是由Fedora Special Interest Group维护的Enterprise Linux(RHEL、CentOS)中经常用到的包。
bash
# 直接使用aliyun的源
[root@centos7 ~]# curl -s -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
其他问题
关闭执行yum命令时,开头的Loading 提示信息。
编辑 /etc/yum.conf 文件,在其中添加或修改 plugins 参数,使其值为 0。
bash
[root@centos7 ~]# sudo sed -i 's/plugins=1/plugins=0/g' /etc/yum.conf
源码安装软件
源码安装:
1.下载
# 1.下载
# 2.查看安装手册
# 3.安装依赖包
yum install gcc make
# 4.生成makefile文件
./configure --prefix=/user/local/nginx
在编译过程中发现还缺少pcre2-devel 和 zlib-devel
# 5.编译成二进制文件
make
# 6.安装到对应位置
make install
# 7.验证
cd /usr/local/nginx/
ls
./nginx
ss -lntp
curl localhost
$PATH(注意:如果nginx因为在/usr/local/ 的路径下,导致无法用TAB键补全)
bash
[root@server ~ 19:57:40]#cd /usr/local/nginx/sbin
[root@server sbin 19:57:49]#ls
nginx
[root@server ~ 19:57:59]#export PATH=$PATH:/usr/local/nginx/sbin

源码安装 nginx
介绍
Nginx是一个高性能的HTTP和反向代理web服务器。
官方地址:https://nginx.org
源码安装的核心适用场景
当你遇到以下情况时,源码安装的优势会尤为突出:
- 项目需要软件的特定版本(最新版、旧版);
- 需自定义软件功能、优化性能或指定安装路径;
- 系统存在依赖冲突,预编译包无法安装;
- 对软件安全性有审计或加固需求。
安装
bash
# 安装依赖
[root@server ~ 20:01:36]# yum install gcc make pcre-devel zlib-devel
# 下载
[root@server ~ 20:04:37]# wget https://nginx.org/download/nginx-1.24.0.tar.gz
# 解压
[root@server ~ 20:04:42]# tar -xf nginx-1.24.0.tar.gz
# 配置
[root@server ~ 20:04:59]# cd nginx-1.24.0/
[root@server nginx-1.24.0 20:05:12]# ./configure --prefix=/usr/local/nginx
# 编译安装
[root@server nginx-1.24.0 20:05:36]# make && make install
[root@centos7 ~]# ls /usr/local/nginx/
conf html logs sbin
# 配置环境变量
[root@centos7 nginx-1.24.0]# export PATH=$PATH:/usr/local/nginx/sbin/
[root@centos7 nginx-1.24.0]# echo 'export PATH=$PATH:/usr/local/nginx/sbin/' >> ~/.bashrc
使用
bash
# 启动服务
[root@centos7 ~]# nginx
# 验证(开网页)
[root@centos7 ~]# curl -s http://localhost | grep Thank
<p><em>Thank you for using nginx.</em></p>
命令总结:
- nginx,启动服务
- nginx -s quit,待nginx进程处理任务完毕进行停止。
- nginx -s stop,查出nginx进程id再使用kill命令强制杀掉进程。
- nginx -s reload,重新加载服务。
配置nginx服务
bash
[root@centos7 ~]# cp /usr/lib/systemd/system/sshd.service /etc/systemd/system/nginx.service
[root@centos7 ~]# vim /etc/systemd/system/nginx.service
ini
[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
bash
[root@centos7 ~]# systemctl daemon-reload
[root@centos7 ~]# systemctl enable nginx.service --now
源码安装 cmatrix
介绍
Cmatrix 是一款 Linux 环境下的炫酷屏保软件其效果类似于黑客帝国电影中的代码雨。
项目地址:https://github.com/abishekvashok/cmatrix
安装
bash
# 安装依赖包
[root@centos7 ~]# yum -y install gcc make autoconf ncurses-devel
# 下载
[root@centos7 ~]# wget https://jaist.dl.sourceforge.net/project/cmatrix/cmatrix/1.2a/cmatrix-1.2a.tar.gz
# 解压
[root@centos7 ~]# tar -xf cmatrix-1.2a.tar.gz
# 配置软件
[root@centos7 ~]# cd cmatrix-1.2a/
[root@centos7 cmatrix-1.2a]# ./configure --prefix=/usr/local/cmatrix
# 编译并安装
[root@centos7 cmatrix-1.2a]# make && make install
使用
bash
# 配置环境变量
[root@centos7 ~]# export PATH=$PATH:/usr/local/cmatrix/bin
# 帮助信息
[root@centos7 ~]# cmatrix --help
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@centos7 ~]# cmatrix
# 效果如下:

bash
[root@centos7 ~]# 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 运行的过程中,你可以按 0 到 9 的任何一位数字键来随意改变当前的更新速度。
自建仓库
自建仓库流程
- 准备软件包
- 创建仓库索引信息
- 发布仓库
- 客户端配置验证
详细操作步骤
-
准备软件包
bash[root@server ~]# mkdir rpms [root@server ~]# cd rpms # 下载软件包,以及依赖的软件包 [root@server rpms]# yumdownloader vim open-vm-tools vsftpd lrzsz bash-completion # 注意: # 如果使用yum download 下载,则不会下载依赖的软件包。 # 此时不要执行yum相关命令,否则这里软件包会被清理掉。 # 移动软件包到发布目录 [root@server ~]# mkdir -p /var/www/html/tools [root@server ~]# mv rpms /var/www/html/tools/Packages -
创建仓库
bash# 安装创建仓库软件包 [root@server ~]# yum install -y createrepo # 创建仓库索引信息 [root@server ~]# createrepo /var/www/html/tools/ -
通过 web 服务器发布仓库
bash# 部署 web 服务器 [root@server ~]# yum install -y httpd [root@server ~]# systemctl enable httpd --now #关闭防火墙和 SELinux [root@server ~]# systemctl disable firewalld.service --now [root@server ~]# setenforce 0 -
客户端配置验证
bash# 备份原有仓库 [root@server ~]# mkdir /etc/yum.repos.d/old [root@server ~]# mv /etc/yum.repos.d/*repo /etc/yum.repos.d/old # 添加新仓库 [root@server ~]# cat << 'EOF' > /etc/yum.repos.d/tools.repo [tools] name=centos7 tools from server.laoma.cloud baseurl=http://server.laoma.cloud/tools/ enabled=1 gpgcheck=0 EOF [root@server ~]# ls /etc/yum.repos.d/ old tools.repo # 安装软件包 [root@server ~]# yum install -y vim
同步仓库
bash
# 将仓库中软件包和元数据全部同步到本地
[root@server ~]# reposync --repoid=tools --download-metadata
[root@server ~]# createrepo tools
[root@server ~]# ls tools/
Packages repodata
m download 下载,则不会下载依赖的软件包。
此时不要执行yum相关命令,否则这里软件包会被清理掉。
移动软件包到发布目录
root@server \~\]# mkdir -p /var/www/html/tools \[root@server \~\]# mv rpms /var/www/html/tools/Packages 2. 创建仓库 ```bash # 安装创建仓库软件包 [root@server ~]# yum install -y createrepo # 创建仓库索引信息 [root@server ~]# createrepo /var/www/html/tools/ 3. 通过 web 服务器发布仓库 ```bash # 部署 web 服务器 [root@server ~]# yum install -y httpd [root@server ~]# systemctl enable httpd --now #关闭防火墙和 SELinux [root@server ~]# systemctl disable firewalld.service --now [root@server ~]# setenforce 0 ``` 4. 客户端配置验证 ```bash # 备份原有仓库 [root@server ~]# mkdir /etc/yum.repos.d/old [root@server ~]# mv /etc/yum.repos.d/*repo /etc/yum.repos.d/old # 添加新仓库 [root@server ~]# cat << 'EOF' > /etc/yum.repos.d/tools.repo [tools] name=centos7 tools from server.laoma.cloud baseurl=http://server.laoma.cloud/tools/ enabled=1 gpgcheck=0 EOF [root@server ~]# ls /etc/yum.repos.d/ old tools.repo # 安装软件包 [root@server ~]# yum install -y vim ``` ### 同步仓库 ```bash # 将仓库中软件包和元数据全部同步到本地 [root@server ~]# reposync --repoid=tools --download-metadata [root@server ~]# createrepo tools [root@server ~]# ls tools/ Packages repodata ``` 参考:`yum-REPOSYNC(8)`。