测试云服务器使用了一个很小的idc,基础设施做得不好,问题很多,镜像也只有centos8以下并且不少基础问题,这里记录一下。不过是测试服,也无所谓了,记录一下以后便于操作。
说明
- CentOS 8 全系列官方已于 2021 年底停止维护,官方主源永久失效,只能使用
centos-vault归档源; - EPEL 8 同步下线,必须使用
epel-archive归档地址,路径缺少Everything会报 404; - 系统无
wget,全程使用curl; - 包含:系统 Base/AppStream 基础源 + EPEL 主源 + EPEL-Modular 模块化源,全部阿里云国内镜像。
一、备份原有系统源文件
bash
运行
# 进入源目录
cd /etc/yum.repos.d
# 创建备份文件夹
mkdir bak
# 将所有原生repo移入备份(原有配置全部保留)
mv *.repo bak/
二、配置 CentOS8 阿里云 Vault 基础源(BaseOS+AppStream+PowerTools+Extras)
bash
运行
cat > CentOS-Base.repo <<'EOF'
[BaseOS]
name=CentOS-8.5.2111 - BaseOS
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/BaseOS/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-Official
[AppStream]
name=CentOS-8.5.2111 - AppStream
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/AppStream/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-Official
[PowerTools]
name=CentOS-8.5.2111 - PowerTools
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/PowerTools/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-Official
[Extras]
name=CentOS-8.5.2111 - Extras
baseurl=https://mirrors.aliyun.com/centos-vault/8.5.2111/extras/$basearch/os/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos-vault/RPM-GPG-KEY-CentOS-Official
EOF
三、配置阿里云 EPEL 归档主源(修复 404,路径带 Everything)
bash
运行
cat > epel.repo <<'EOF'
[epel]
name=Extra Packages for Enterprise Linux 8 - $basearch
baseurl=https://mirrors.aliyun.com/epel-archive/8/Everything/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
[epel-debuginfo]
name=Extra Packages for Enterprise Linux 8 - $basearch - Debug
baseurl=https://mirrors.aliyun.com/epel-archive/8/Everything/$basearch/debug
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
[epel-source]
name=Extra Packages for Enterprise Linux 8 - $basearch - Source
baseurl=https://mirrors.aliyun.com/epel-archive/8/Everything/SRPMS
failovermethod=priority
enabled=0
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
EOF
四、单独配置 EPEL-Modular 模块化源(PHP/NodeJS 多版本模块依赖)
bash
运行
cat > epel-modular.repo <<'EOF'
[epel-modular]
name=Extra Packages for Enterprise Linux Modular 8 - $basearch
baseurl=https://mirrors.aliyun.com/epel-archive/8/Modular/$basearch
failovermethod=priority
enabled=1
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
EOF
五、清理旧缓存,重建仓库元数据
bash
运行
# 清空原有缓存
dnf clean all
# 拉取阿里云源元数据
dnf makecache
六、校验源是否全部加载成功
1. 查看 EPEL 相关仓库
bash
运行
dnf repolist | grep epel
正常输出结果:
plaintext
epel Extra Packages for Enterprise Linux 8 - x86_64
epel-modular Extra Packages for Enterprise Linux Modular 8 - x86_64
2. 查看系统基础仓库
bash
运行
dnf repolist | grep CentOS
正常输出:BaseOS、AppStream、PowerTools、Extras
七、常用配套操作命令
1. 导入 EPEL 密钥(GPG 校验失败时执行)
bash
运行
rpm --import https://mirrors.aliyun.com/epel/RPM-GPG-KEY-EPEL-8
2. 安装 wget 工具(后续下载文件方便)
bash
运行
dnf install wget -y
3. 关闭 epel-modular(不需要多版本软件时,提速)
bash
运行
sed -i 's/enabled=1/enabled=0/' epel-modular.repo
dnf clean all && dnf makecache
4. 查看模块化软件列表(php/node 等)
bash
运行
dnf module list --repo epel-modular
八、关键避坑总结
- CentOS8 基础源必须使用
centos-vault/8.5.2111,不能用普通 centos/8; - EPEL 主源地址必须带
/Everything/,缺失直接 404; - epel-modular 路径不带 Everything,单独创建 repo 文件;
- CentOS8 无安全更新,仅临时过渡,长期生产建议迁移 RockyLinux9/AlmaLinux9。