首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> 更多程式語言 >> 程式設計疑難解答

CentOS yum 錯誤 [Errno 14] HTTP Error 404 解決:鏡像源失效與配置重複

     編輯:程式設計疑難解答

錯誤現象

https://mirrors.sohu.com/fedora/releases/$releasever/Everything/i386/os/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Repository updates is listed more than once in the configuration

兩大問題:

  1. 鏡像源 URL 失效 (搜狐鏡像已停止維護 Fedora 舊版本)
  2. Repository 配置重複 (updates, fedora 等出現多次)

解決方案一:替換為可用鏡像源 (推薦阿里雲/清華/中科大)

1. 備份原配置

cd /etc/yum.repos.d/
mkdir backup
mv *.repo backup/

2. 下載新 repo 檔案

# CentOS 7 (最常見)
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/CentOS-7.repo

# CentOS 8 / Stream
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/CentOS-8.repo

# 或使用清華源
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.tuna.tsinghua.edu.cn/help/centos/

3. 清理快取並重建

yum clean all
yum makecache

解決方案二:手動修改現有 repo 檔案

編輯 /etc/yum.repos.d/CentOS-Base.repo,將 mirrorlist 註釋,baseurl 指向鏡像:

[base]
name=CentOS-$releasever - Base
# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os
baseurl=https://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[updates]
name=CentOS-$releasever - Updates
# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates
baseurl=https://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

[extras]
name=CentOS-$releasever - Extras
# mirrorlist=https://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras
baseurl=https://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

解決方案三:修正 Repository 重複配置

檢查 /etc/yum.repos.d/ 下所有 .repo 檔案,刪除重複定義的區段:

# 查看所有 repo 定義
grep -r "^\[" /etc/yum.repos.d/

# 刪除多餘檔案 (如 fedora.repo, updates.repo 等非 CentOS 官方檔案)
rm -f /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/updates.repo

常用國內鏡像源對照

鏡像站CentOS 7 Base URL適用版本
阿里雲https://mirrors.aliyun.com/centos/CentOS 7/8/Stream
清華大學https://mirrors.tuna.tsinghua.edu.cn/centos/CentOS 7/8/Stream
中科大https://mirrors.ustc.edu.cn/centos/CentOS 7/8/Stream
網易https://mirrors.163.com/centos/CentOS 7/8
騰訊雲https://mirrors.cloud.tencent.com/centos/CentOS 7/8/Stream

進階:EPEL 源同步替換

# 安裝 EPEL
yum install -y epel-release

# 替換為阿里雲 EPEL
sed -i 's|^metalink=|#metalink=|g' /etc/yum.repos.d/epel.repo
sed -i 's|^#baseurl=https://download.fedoraproject.org/pub/epel|baseurl=https://mirrors.aliyun.com/epel|g' /etc/yum.repos.d/epel.repo

驗證修復

yum repolist all
yum install -y vim wget net-tools  # 測試安裝常用工具

注意事項

  • CentOS 8 已於 2021 年底停止維護,建議遷移至 CentOS Stream、Rocky Linux、AlmaLinux
  • 生產環境修改前請快照備份
  • 若使用 Docker,建議在 Dockerfile 中直接指定鏡像源
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved