一、问题描述
最近安装centos8.0在使用dnf安装boost的时候遇到一些问题,使用原来操作系统自带的repo安装总是很慢或者失败。按照网上的步骤更新了阿里云的repo
#备份好并删除/etc/yum.repos.d/里面内容之后
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
#然后执行
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发现有这样的信息
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/,我尝试用浏览器去打开,发现阿里云实际上支持的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。
继续debug,查看到repo里面的配置项如下
baseurl=https://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
这里多了一个$releaserver看起来是系统自己获取到的,然后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)
最后发现dnf有一个参数releaserver
#这样执行就成功了,不过后续还不知道怎么把这个参数固定下来,好像是和system-release的编号有关
dnf --releasever=8 makecache
dnf --releasever=8 install boost