CentOS 镜像源配置指南

# CentOS 镜像源配置指南

## 简介
**CentOS** 是基于 Red Hat Linux 源代码构建的企业级 Linux 发行版,提供稳定、可预测、可管理和可复制的免费计算平台。

### 相关资源
- **下载地址**: [https://mirrors.aliyun.com/centos/](https://mirrors.aliyun.com/centos/)
- **仓库**:
- CentOS 过期源(centos-vault): [https://developer.aliyun.com/mirror/centos-vault](https://developer.aliyun.com/mirror/centos-vault)
- CentOS arm源(centos-altarch): [https://developer.aliyun.com/mirror/centos-altarch](https://developer.aliyun.com/mirror/centos-altarch)
- CentOS Stream源(centos-stream): [https://developer.aliyun.com/mirror/centos-stream](https://developer.aliyun.com/mirror/centos-stream)
- CentOS debuginfo源(centos-debuginfo): [https://developer.aliyun.com/mirror/centos-debuginfo](https://developer.aliyun.com/mirror/centos-debuginfo)

---

## 配置方法

### 注意事项
- **CentOS 8 已结束生命周期(EOL)**,建议迁移至 Anolis 或 Alinux。若需临时使用 CentOS 8 安装包,请按以下步骤切换源。

---

### 通用配置步骤
1. **备份原有源配置**
```bash
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
```

2. **下载新版源配置**
- **CentOS 8(需切换至 vault 源)**
```bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
# 或
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
```
- **CentOS 6(需切换至 vault 源)**
```bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
# 或
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo
```
- **CentOS 7**
```bash
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 或
curl -o /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
```

3. **生成缓存**
```bash
yum makecache
```

---

### 其他配置说明
- **非阿里云 ECS 用户**:若出现 `Couldn't resolve host 'mirrors.cloud.aliyuncs.com'` 错误,可执行以下命令修复:
```bash
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
```

---

## CentOS 8 生命周期结束后的源切换

### 公网用户操作
```bash
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo
yum clean all && yum makecache
</code></pre>

<h3>阿里云 ECS 用户操作</h3>

<pre><code class="language-bash">mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.cloud.aliyuncs.com/repo/Centos-vault-8.5.2111.repo
sed -i 's/mirrors.cloud.aliyuncs.com/url_tmp/g' /etc/yum.repos.d/CentOS-Base.repo && \
sed -i 's/mirrors.aliyun.com/mirrors.cloud.aliyuncs.com/g' /etc/yum.repos.d/CentOS-Base.repo && \
sed -i 's/url_tmp/mirrors.aliyun.com/g' /etc/yum.repos.d/CentOS-Base.repo
yum clean all && yum makecache
</code></pre>

<hr />

<blockquote>
<strong>提示</strong>: 配置完成后,建议验证源是否生效(如 <code>yum update</code> 测试)。若遇到网络问题,可尝试更换就近区域的镜像地址。
```

点赞

发表回复

电子邮件地址不会被公开。必填项已用 * 标注