Skip to content

Centos

镜像des
centos 7iso

查看版本

sh
cat /etc/redhat-release

lsb_release -d

默认仓库

sh
[BaseOS]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$releasever/BaseOS/$basearch/os/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial


清华大学镜像源 - https://mirrors.tuna.tsinghua.edu.cn/help/centos/
阿里云镜像源 - https://developer.aliyun.com/mirror
腾讯云镜像源 - http://mirrors.tencent.com/

镜像源

可用官方镜像

sh
sed -e 's|^mirrorlist=|#mirrorlist=|g' -e 's|^#baseurl=http://mirror.centos.org/centos|baseurl=https://vault.centos.org/centos|g' -i.bak /etc/yum.repos.d/CentOS-*.repo

阿里云镜像

sh
# 注意选择版本号 https://mirrors.aliyun.com/repo/

# 7
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo

# 8
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-8.repo

# 手动替换
sudo vi /etc/yum.repos.d/CentOS-Base.repo
[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
enabled=1
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

#clean and update
yum clean all && yum makecache

安装yum工具

sh
#yum-utils是一组实用的工具和脚本,旨在增强Yum包管理工具的功能,帮助用户更高效地管理软件包、清理缓存和处理存储库
yum install -y yum-utils

# 使用 yum groupinstall "Development Tools" 命令可以一次性安装多个开发工具,这些工具通常包括编译器、调试工具、文本编辑器等,能够满足大多数开发需求。
yum groupinstall -y "Development Tools"

yum-utils是一组实用的工具和脚本,旨在增强Yum包管理工具的功能,帮助用户更高效地管理软件包、清理缓存和处理存储库等‌‌

有其特定的用途:

  1. yum-config-manager‌:用于管理Yum配置文件和存储库。例如,可以启用或禁用特定的存储库‌。
  2. package-cleanup‌:用于清理无用的软件包和缓存。可以清理孤立的软件包和未使用的软件包‌。
  3. yum-complete-transaction‌:用于完成未完成的Yum事务,解决事务中断的问题‌。
  4. yumdownloader‌:用于下载RPM包到本地,而不需要安装它们,这对于下载依赖项特别有用‌。
  5. debuginfo-install‌:用于安装debuginfo包及其依赖‌。
  6. find-repos-of-install‌:查找安装软件包所需的存储库‌。
  7. needs-restarting‌:检查哪些服务需要重启‌。
  8. repoclosure‌:检查存储库的完整性‌。
  9. epodiff‌:比较两个存储库的差异‌。
  10. repo-graph‌:生成存储库的图形表示‌。
  11. repomanage‌:管理存储库的配置‌。
  12. repoquery‌:查询存储库中的软件包信息‌。
  13. repo-rss‌:生成存储库的RSS订阅源‌。
  14. reposync‌:同步远程存储库到本地‌。
  15. repotrack‌:跟踪存储库中的软件包变化‌。
  16. show-installed‌:显示已安装的软件包‌。
  17. show-changed-rco‌:显示已更改的软件包‌。
  18. verifytree‌:验证软件包的依赖关系树‌。
  19. yum-builddep‌:为构建依赖项下载和安装必要的开发包‌。
  20. yum-debug-dump‌和‌yum-debug-restore‌:用于调试Yum事务‌。
  21. yum-groups-manager‌:管理软件包组‌。

额外仓库

sh
yum install -y epel-release

配置:

yaml
[epel]
name = epel
baseurl = https://mirrors.aliyun.com/epel-archive/8.2/Everything/x86_64/
gpgcheck = 0

yum仓库管理 yum-config-manager

安装

yum-config-manager命令是对资源库(/etc/yum.repos.d/下的文件)进行增删改查,推荐使用yum-config-manager命令进行改动

系统默认没有安装这个命令,这个命令在yum-utils包里,可以通过yum install -y yum-utils安装

sh
yum repolist all # 显示所有资源库

yum repolist enabled # 显示所有已启动的资源库

yum repolist disabled # 显示所有被禁用的资源库

添加repository (添加yum仓库)

sh
yum-config-manager --add-repo repository_url

切换库中资源—禁用+启用

sh
yum-config-manager --disable itemName

yum-config-manager --enable itemName

# 或者直接编辑/etc/yum.repos.d/下的对应资源库文件

enabled=0 #禁用

enabled=1 #禁用

删除仓库

/etc/yum.repos.d/下手动删除对应repo文件即可,但请注意,这会使得该库中所有信息被删除

安装包

rmp:RHEL、Centos

sh
rmp -ivh package.rmp
rmp -e package

yum: Centos6-8

sh
yum install package
yum remove package

dnf: RHEL6 Centos8

sh
dnf install package
dnf remove package

查看软件包命令

sh
# 查看已经安装的软件包
yum list installed

检索包

sh
yum provides package

列出可用包

sh
yum -v repolist all

yum -v repolist all 命令的整体作用是在详细模式下显示系统中所有配置的软件源的信息。执行该命令后,yum 会输出每个软件源的详细信息,包括:

  • 软件源 ID:每个软件源的唯一标识符。
  • 软件源名称:软件源的描述性名称。
  • 状态:显示软件源是启用(enabled)还是禁用(disabled)。
  • 软件包数量:该软件源中包含的软件包数量。