I. AlmaLinux#
1.1 阿里云镜像源#
官方地址:https://developer.aliyun.com/mirror/almalinux
1.1.1 备份原有镜像源#
1
| cp -avx /etc/yum.repos.d /etc/yum.repos.d.bak
|
1.1.2 替换官方地址#
将所有的官方主镜像地址替换为阿里云镜像站地址
1
2
3
4
| sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^# baseurl=https://repo.almalinux.org|baseurl=https://mirrors.aliyun.com|g' \
-i.bak \
/etc/yum.repos.d/almalinux*.repo
|
1.1.3 清理缓存#
1.1.4 更新缓存#
1.2 国内镜像源地址#
1
2
3
4
5
6
7
8
9
10
| 阿里云
https://mirrors.aliyun.com/almalinux/
腾讯云
https://mirrors.cloud.tencent.com/almalinux/
浙江大学
https://mirrors.zju.edu.cn/almalinux/
南京大学
https://mirrors.nju.edu.cn/almalinux/
大连东软
https://mirrors.neusoft.edu.cn/almalinux/
|
1.3 相关错误#
1.3.1 更新错误#
参考👉 解决 AlmaLinux 使用 dnf/yum 安装/更新错误
1、报错信息
执行 dnf update 时,dnf 首先提示从本地文件导入 GPG 公钥,导入成功后出现:
1
2
3
| ...
Import of key(s) didn't help, wrong key(s)?
...
|
错误,最终导致 dnf 指令无法正确安装对应的软件包。
2、原因分析
此处提示从本地文件导入 GPG 公钥,是为原公钥已过期,提示用户需要导入新的公钥,而系统原 /etc/pki/rpm-gpg/ 路径下存在公钥文件,所以提示是否导入该文件。但路径下的公钥文件也为过期的公钥文件,所以最终提示公钥错误。
AlmaLinux 8.5 在当前(2024 年 03 月 08 日)已属于过期已久的版本,AlmaLinux OS 基金会已于 2023 年 12 月 20 日发布博文告知用户 AlmaLinux 8 的 GPG 公钥已变更(查看对应文章:AlmaLinux 8 GPG key change
)的消息。
在博文内还提到,新的 GPG 公钥已内嵌在最早于 2023 年 10 月 16 日发布的 AlmaLinux OS 8.8-3.el8 中,所以,本错误只会发生在早于该版本的 AlmaLinux 中。
3、解决办法
在出现问题的 AlmaLinux 终端中执行以下命令以导入最新的 GPG 公钥:
1
| rpm --import https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux
|
并使用以下指令验证是否成功导入:
1
| rpm -q gpg-pubkey-ced7258b-6525146f
|
如若返回
1
| gpg-pubkey-ced7258b-6525146f
|
则代表公钥已存在,如若返回
1
| package gpg-pubkey-ced7258b-6525146f is not installed
|
则需要再次执行上方 rpm --import 命令导入 GPG 公钥。
II. Rocky Linux#
2.1 阿里云镜像源#
官方地址:https://developer.aliyun.com/mirror/rockylinux
2.1.1 备份原有镜像源#
1
| cp -avx /etc/yum.repos.d /etc/yum.repos.d.def
|
2.1.2 替换官方地址#
将所有的官方主镜像地址替换为阿里云镜像站地址
1
2
3
4
| sed -e 's|^mirrorlist=|#mirrorlist=|g' \
-e 's|^#baseurl=http://dl.rockylinux.org/$contentdir|baseurl=https://mirrors.aliyun.com/rockylinux|g' \
-i.bak \
/etc/yum.repos.d/[Rr]ocky*.repo
|
2.1.3 清理缓存#
2.1.4 更新缓存#
2.2 国内镜像地址#
1
2
3
4
5
6
7
8
9
10
11
12
| 阿里云
https://mirrors.aliyun.com/rockylinux/
腾讯云
https://mirrors.cloud.tencent.com/rocky/
中科大
https://mirrors.ustc.edu.cn/rocky/
浙江大学
https://mirrors.zju.edu.cn/docs/rocky/
南京大学
https://mirror.nju.edu.cn/rocky/
大连东软
https://mirrors.neusoft.edu.cn/rocky/
|
III. RHEL#
3.1 删除官方订阅#
3.1.1 禁用注册订阅提示#
两个文件,修改其中的 Enable=0 👇
1
2
| /etc/yum/pluginconf.d/product-id.conf
/etc/yum/pluginconf.d/subscription-manager.conf
|
3.1.2 删除官方订阅#
1
| yum remove subscription-manager
|
3.2 更换镜像源#
1、为了方便操作,先备份 /etc/yum.repos.d 目录下的 redhat.repo 文件(如果没有就不用管)
2、在 /etc/yum.repos.d 目录下,编辑 redhat.repo 文件
3.2.1 阿里云镜像源#
参考 AlmaLinux 或 Rocky Linux 替换。
IV. 参考文档#
AlmaLinux : AlmaLinux Mirrors
Rocky Linux : Rocky Linux Mirrors
阿里云:阿里巴巴开源镜像站
腾讯云:腾讯软件源
中科大:USTC Open Source Software Mirror
浙江大学:ZJU Mirror
南京大学:NJU Mirror
大连东软:大连东软信息学院-开源镜像站