CentOS8.0 切換到aliyun repo dnf makecache失敗的問題

一、問題描述

最近安裝centos8.0在使用dnf安裝boost的時候遇到一些問題,使用原來操作系統(tǒng)自帶的repo安裝總是很慢或者失敗。按照網上的步驟更新了阿里云的repo

#備份好并刪除/etc/yum.repos.d/里面內容之后
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo

#然后執(zhí)行
dnf clean all
dnf makecache

#報錯
CentOS-8.0 - AppStream - mirrors.aliyun.com  
CentOS-8.0 - Base - mirrors.aliyun.com 
CentOS-8.0 - Extras - mirrors.aliyun.com 
Failed to synchronize cache for repo 'AppStream', ignoring this repo.
Failed to synchronize cache for repo 'base', ignoring this repo.
Failed to synchronize cache for repo 'extras', ignoring this repo.
Metadata cache created.

二、Debug過程

查看/var/log/dnf.log發(fā)現(xiàn)有這樣的信息

2020-02-25T08:52:17Z DEBUG AppStream: has expired and will be refreshed.
2020-02-25T08:52:17Z DEBUG base: has expired and will be refreshed.
2020-02-25T08:52:17Z DEBUG extras: has expired and will be refreshed.
2020-02-25T08:52:17Z DEBUG repo: downloading from remote: AppStream
2020-02-25T08:52:53Z DEBUG Cannot download 'https://mirrors.aliyun.com/centos/8.0/AppStream/x86_64/os/, http://mirrors.aliyuncs.com/centos/8.0/AppStream/x86_64/os/, http://mirrors.cloud.aliyuncs.com/centos/8.0/AppStream/x86_64/os/': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried.
2020-02-25T08:52:53Z DEBUG repo: downloading from remote: base
2020-02-25T08:53:34Z DEBUG Cannot download 'https://mirrors.aliyun.com/centos/8.0/BaseOS/x86_64/os/, http://mirrors.aliyuncs.com/centos/8.0/BaseOS/x86_64/os/, http://mirrors.cloud.aliyuncs.com/centos/8.0/BaseOS/x86_64/os/': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried.
2020-02-25T08:53:34Z DEBUG repo: downloading from remote: extras
2020-02-25T08:54:07Z DEBUG Cannot download 'https://mirrors.aliyun.com/centos/8.0/extras/x86_64/os/, http://mirrors.aliyuncs.com/centos/8.0/extras/x86_64/os/, http://mirrors.cloud.aliyuncs.com/centos/8.0/extras/x86_64/os/': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried.
2020-02-25T08:54:07Z WARNING Failed to synchronize cache for repo 'AppStream', ignoring this repo.
2020-02-25T08:54:07Z WARNING Failed to synchronize cache for repo 'base', ignoring this repo.
2020-02-25T08:54:07Z WARNING Failed to synchronize cache for repo 'extras', ignoring this repo.

顯然有一些鏈接是打不開的,比如https://mirrors.aliyun.com/centos/8.0/BaseOS/x86_64/os/,我嘗試用瀏覽器去打開,發(fā)現(xiàn)阿里云實際上支持的url是這兩個

這個是有的
http://mirrors.aliyun.com/centos/8/BaseOS/x86_64/os/
這個也是有的
http://mirrors.aliyun.com/centos/8.0.1905/BaseOS/x86_64/os/

差別很簡單,我的repo里面的路徑是8.0,但是aliyun上的是8。
繼續(xù)debug,查看到repo里面的配置項如下

baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/

這里多了一個$releaserver看起來是系統(tǒng)自己獲取到的,然后dnf是python寫的,我就嘗試debug了源碼,中間過程略過不表

#記錄一下中間的思路,比較雜
python3 -c 'import dnf, pprint; db = dnf.dnf.Base(); pprint.pprint(db.conf.substitutions,width=1)'
/usr/lib/python3.6/site-packages/dnf
base.py-->substitions.py
dnf.rpm.detect_releasever(conf.installroot)
releasever = hdr['version']
distroverpkg   system-release(releasever)

最后發(fā)現(xiàn)dnf有一個參數(shù)releaserver

#這樣執(zhí)行就成功了,不過后續(xù)還不知道怎么把這個參數(shù)固定下來,好像是和system-release的編號有關
dnf --releasever=8 makecache
dnf --releasever=8 install boost
?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
【社區(qū)內容提示】社區(qū)部分內容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發(fā)布,文章內容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內容

友情鏈接更多精彩內容