Loading

CentOS 8 / CentOS Stream 换源,设置dnf / yum镜像

centos 8 默认是会读取centos.org的mirrorlist的,所以一般来说是不需要配置镜像的。
如果你的网络访问mirrorlist有问题,才需要另外配置
相关镜像配置,请参考各镜像站的相关帮助
https://developer.aliyun.com/mirror/centos
https://mirrors.tuna.tsinghua.edu.cn/help/centos/
http://mirrors.ustc.edu.cn/help/centos.html
https://mirrors.huaweicloud.com/

aliyun镜像

update 2021-5-18:
阿里云镜像的帮助站点挂了很久了,一直提示正在升级。但是目前仅影响帮助页面,实际的地址还是可以用的。本教程中mirrors.aliyun.com地址也可替换为其他镜像源地址,一般来说区别不大,如:mirrors.tuna.tsinghua.edu.cn / repo.huaweicloud.com

update 2021-7-15: 阿里云镜像的帮助站点于今日恢复

官方教程如下,注意此处下载的不是Stream版本的repo

curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo

需要注意的此处下载的Base.repo中附带了AppStream等其他源地址,而CentOS 8原版是分拆为多个文件分别管理的。
阿里云还新增了PowerTools、centosplus等仓储地址。并将本地gpgkey路径改为了网络地址https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

sed自行修改

自行更改能够更好的保持原有的repo文件结构

# `sed`的 `-i.bak`参数会自动备份所替换的文件,可放心使用。
# 出现问题可通过 `rename -- .bak '' *.bak` 进行批量还原

sudo sed -i.bak \
-e 's|^mirrorlist=|#mirrorlist=|' \
-e 's|^#baseurl=|baseurl=|' \
-e 's|http://mirror.centos.org|https://mirrors.aliyun.com|' \
/etc/yum.repos.d/CentOS-*.repo

sudo dnf makecache

EPEL

https://developer.aliyun.com/mirror/epel

epel库安装后,软件源地址也是未修改过的,同样需要修改。

sudo dnf install epel-release

sudo sed -i.bak \
-e 's|^metalink|#metalink|' \
-e 's|^#baseurl=|baseurl=|' \
-e 's|download.fedoraproject.org/pub|mirrors.aliyun.com|' \
/etc/yum.repos.d/epel*.repo

sudo dnf makecache

dnf fastest mirror

如果你不希望像上文那样固定配置某一个镜像地址,也可以使用fastest mirror功能,由dnf自动搜索使用最快的镜像地址。
centos8的dnf中已集成了此功能,在centos7的yum中这是需要单独安装插件使用的。
可以先ping一下mirrorlist.centos.org看能否ping通

#修改配置
vi /etc/dnf/dnf.conf
#新增
fastestmirror=True


#使用
sudo dnf makecache

CentOS镜像配置默认地址

记录一下8 Stream修改前的BaseOS.repo原始地址

mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo=BaseOS&infra=$infra
#baseurl=http://mirror.centos.org/$contentdir/$stream/BaseOS/$basearch/os/

docker-ce

centos 8 安装docker及兼容性问题处理,请见另一篇文章:https://www.cnblogs.com/wswind/p/centos-8-install-docker.html

CentOS Stream

CentOS 8 宣布21年底停止支持,升级至CentOS Stream: https://www.cnblogs.com/wswind/p/14109290.html

可替代CentOS的发行版

基于RHEL的其他分支版本汇总:https://www.cnblogs.com/wswind/p/14630346.html

posted @ 2019-10-28 13:58  wswind  阅读(40212)  评论(1编辑  收藏  举报