Centos8.4 更新源

CentOS Linux 8 - AppStream 73 B/s | 38 B 00:00
Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist

这是因为centos8已经停止维护,需要更改软件包指向的地址

cd /etc/yum.repos.d/

使用官方源

把下面所有的文件中的

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

改成

mirrorlist=http://#mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=cr&infra=$infra
baseurl=http://vault.centos.org/$contentdir/$releasever/cr/$basearch/os/

就是去掉注释的#,然后把baseurl的mirror改成vault

使用国内源

目前支持的是8.5,可以下载8.5的版本,然后把下载文件中8.5.2111改为8.4.2105

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo

更改过的文件内容如下,也可以直接复制,编辑一个CentOS-Base.repo文件,粘贴进去

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-8.4.2105 - Base - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.4.2105/BaseOS/$basearch/os/
        http://mirrors.aliyuncs.com/centos-vault/8.4.2105/BaseOS/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos-vault/8.4.2105/BaseOS/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that may be useful
[extras]
name=CentOS-8.4.2105 - Extras - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.4.2105/extras/$basearch/os/
        http://mirrors.aliyuncs.com/centos-vault/8.4.2105/extras/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos-vault/8.4.2105/extras/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-8.4.2105 - Plus - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.4.2105/centosplus/$basearch/os/
        http://mirrors.aliyuncs.com/centos-vault/8.4.2105/centosplus/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos-vault/8.4.2105/centosplus/$basearch/os/
gpgcheck=0
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

[PowerTools]
name=CentOS-8.4.2105 - PowerTools - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.4.2105/PowerTools/$basearch/os/
        http://mirrors.aliyuncs.com/centos-vault/8.4.2105/PowerTools/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos-vault/8.4.2105/PowerTools/$basearch/os/
gpgcheck=0
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official


[AppStream]
name=CentOS-8.4.2105 - AppStream - mirrors.aliyun.com
baseurl=http://mirrors.aliyun.com/centos-vault/8.4.2105/AppStream/$basearch/os/
        http://mirrors.aliyuncs.com/centos-vault/8.4.2105/AppStream/$basearch/os/
        http://mirrors.cloud.aliyuncs.com/centos-vault/8.4.2105/AppStream/$basearch/os/
gpgcheck=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-Official

批量替换

如果上面的方法不行,也可以自己找到对应的路径,然后把/etc/yum.repos.d/下面的所有文件替换一下。如果觉着手动操作麻烦,可以用sed批量替换

sed -i 's/mirrorlist/#mirrorlist/g' /etc/yum.repos.d/CentOS-*
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://vault.centos.org|g' /etc/yum.repos.d/CentOS-*
或者使用国内的源,比如阿里的源
sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://mirrors.aliyun.com/centos-vault|g' /etc/yum.repos.d/CentOS-*
posted @ 2022-08-10 10:56  秋来叶黄  阅读(710)  评论(0编辑  收藏  举报