【centos8 镜像修改】centos8 镜像修改阿里云

要将 CentOS 8 的镜像源修改为阿里云镜像,你需要编辑 /etc/yum.repos.d/ 目录下的 .repo 文件。以下是具体的步骤:

  1. 备份原始的 .repo 文件 :

    在编辑之前,建议备份原始的 .repo 文件,以便在出现问题时可以恢复。

    bash 复制代码
    sudo cp -a /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
    sudo cp -a /etc/yum.repos.d/CentOS-Stream-*.repo /etc/yum.repos.d/CentOS-Stream-*.repo.backup
  2. 编辑 .repo 文件 :

    使用文本编辑器打开每个 .repo 文件,并替换 mirrorlist 为 baseurl,使用阿里云的镜像地址。

    bash 复制代码
    sudo vi /etc/yum.repos.d/CentOS-Base.repo
    sudo vi /etc/yum.repos.d/CentOS-Stream-AppStream.repo
    sudo vi /etc/yum.repos.d/CentOS-Stream-BaseOS.repo

    对于每个文件,找到 [BaseOS] 和 [AppStream] 部分,并修改为:

    ini 复制代码
    [BaseOS]
    name=CentOS Stream $releasever - BaseOS
    baseurl=http://mirrors.aliyun.com/centos/$releasever/BaseOS/$basearch/os/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial
    
    [AppStream]
    name=CentOS Stream $releasever - AppStream
    baseurl=http://mirrors.aliyun.com/centos/$releasever/AppStream/$basearch/os/
    enabled=1
    gpgcheck=1
    gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-centosofficial

    确保每个 [BaseOS] 和 [AppStream] 部分都使用了 baseurl 而不是 mirrorlist,并且 baseurl 设置为阿里云的地址。

  3. 清除缓存并测试 :

    修改完 .repo 文件后,清除 YUM 缓存并尝试重新同步仓库:

    bash 复制代码
    sudo dnf clean all
    sudo dnf makecache
    sudo dnf update

    这将清除缓存,重新生成缓存,并尝试更新系统。

  4. 验证修改 :

    你可以使用以下命令来检查当前使用的仓库源:

    bash 复制代码
    sudo dnf repolist

    这将列出所有已启用的仓库及其URL,确保它们都是指向阿里云的地址。

通过以上步骤,你应该能够成功将 CentOS 8 的镜像源修改为阿里云镜像。如果遇到任何问题,请检查 .repo 文件的语法是否正确,以及网络连接是否正常。

相关推荐
大今野2 天前
专转本计算机·云计算核心考点精讲(概念·关键技术·服务模式)
大数据·云计算·big data·专转本
Johny_Zhao5 天前
Keepalived与Nginx架构选型
linux·nginx·信息安全·云计算·apache·shell·yum源·keepalive·系统运维
66IT6614 天前
Veeam ONE v13.1 发布:全新 HTML5 Web 客户端与 PostgreSQL 报告库
云计算·虚拟化·监控·数据保护·veeam
2601_9679801115 天前
Python 与云计算:AWS、GCP、Azure 实践
python·云计算·azure·aws·gcp