Centos8升级或安装软件时报错的处理

    我的系统是 centos 8.0,升级使用 dnf update 时,提示:
    Failed to synchronize cache for repo appstream。

    1、先试试网络正常么:

    ping google.com

    有接收到数据,证明网络没问题。

    2、导致该问题原因常见的有3个:

    • 时间日期不正确
    • 老旧或失效的 DNF 缓存
    • CentOS baseURL

    第一个原因的解决:
    # timedatectl
    # timedatectl set-timezone "Asia/Shanghai"

    第二个的解决:
    # dnf clean all
    # rm -rf /var/cache/dnf

    第三个的解决:因为 centos 8 在 2021年底,更新就不支持了,所有找不到升级源。修改为 vault.centos.org 镜像。

    执行下面的命令:

    # cd /etc/yum.repos.d/
    # 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-*


    现在试试 dnf upgrade  可以找到更新源了。把 centos 8.0  升级到 8.5 了。

    # cat /etc/redhat-release
    CentOS Linux release 8.5.2111

    解决了。不过只是修改了缓冲区的url,要不,你重启后,再次跟新时,会出现:

    Error: Failed to download metadata for repo 'appstream': Cannot prepare internal mirrorlist: No URLs in mirrorlist。

    这样的错误的。

    要一直有效,就采用下面的修改文件方式:

    # cd /etc/yum.repos.d
    # vi CentOS-Linux-BaseOS.repo

    添加一行内容:
    baseurl=https://vault.centos.org/centos/$releasever/BaseOS/$basearch/os/

    保存退出。

    对  CentOS-Linux-AppStream.repo  也添加和上面同样的一行。

    对  CentOS-Linux-PowerTools.repo  添加下面这行:

    baseurl=https://vault.centos.org/centos/$releasever/PowerTools/$basearch/os/

    最后执行以下

    # dnf  clean all

    清理一下缓存,否则不生效的。


    还没有评论

    Please publish modules in offcanvas position.