centos 7.8更换成阿里源

原创 淹不死的狗  2026-09-09 17:22:03  阅读 12 次 评论 0 条
摘要:

一键将CentOs的yum源更换为国内阿里yum源因为在近期centos官方停止维护官方yum源,所以我们需要把yum更改为国内的yum源,比如说阿里云一键复制即可,因为官方源已经停止维护,所以没必要备份wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repowget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com

一键将CentOs的yum源更换为国内阿里yum源

图片.png centos 7.8更换成阿里源 操作系统

因为在近期centos官方停止维护官方yum源,所以我们需要把yum更改为国内的yum源,比如说阿里云

一键复制即可,因为官方源已经停止维护,所以没必要备份

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
wget -O /etc/yum.repos.d/epel.repo https://mirrors.aliyun.com/repo/epel-7.repo
yum clean all && yum makecache

CentOS 7.8 换阿里源,核心就是下载阿里的 repo 文件替换默认源,然后清理缓存。‌ 因为 CentOS 7 官方源已经停止维护,继续用默认源会报错或无法解析,所以换源这一步是必须的。‌‌

操作前先确保有 root 权限,然后按下面几步来:
1️⃣ 备份默认源

mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup

2️⃣ 下载阿里源文件

wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

如果系统里没装 wget,也可以用 curl:


curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo

3️⃣ 顺便装一下 EPEL 扩展源(可选但推荐)

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo

4️⃣ 清理缓存并生成新缓存

yum clean all
yum makecache

5️⃣ 验证一下是否生效

yum repolist


更新内核

CentOS 7 官方源已停止维护,需先将 YUM 源切换至 Vault 归档源或国内镜像站的 Vault 目录,解决依赖冲突后通过 ELRepo 安装新内核。

1. 修复 YUM 源(以阿里云 Vault 源为例)

备份原配置并替换为指向 centos-vault 的源,确保路径包含具体版本号(如 7.9.2009)。

查看版本号:
# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)

编辑源配置文件

使用 vi 或其他文本编辑器打开配置文件:

vi /etc/yum.repos.d/CentOS-Base.repo

vi 编辑器操作提示:

    按 i 键进入编辑模式
    按 Esc 键退出编辑模式
    在命令模式下输入 :%d 清空文件内容
    输入 :wq 保存并退出

第三步:写入新的源配置

清空原文件内容后,将以下配置粘贴进去:
使用阿里云镜像源(推荐)

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-vault/7.8.2003/os/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-vault/7.8.2003/updates/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-vault/7.8.2003/extras/$basearch/
gpgcheck=1
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
baseurl=https://mirrors.aliyun.com/centos-vault/7.8.2003/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=https://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

第四步:清理并重建缓存

保存配置文件后,执行以下命令清理旧缓存并生成新的缓存

# 清理所有 yum 缓存
yum clean all
# 重建缓存
yum makecache

2. 安装 ELRepo 源

ELRepo 提供比官方源更新的内核版本(kernel-lt 为长期支持版,kernel-ml 为主线最新版)。

# 导入 ELRepo GPG 密钥
rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org
# 安装 ELRepo 仓库释放包
yum install -y https://www.elrepo.org/elrepo-release-7.el7.elrepo.noarch.rpm

3. 安装新内核

推荐生产环境使用 LTS 内核(kernel-lt),测试环境可使用主线内核(kernel-ml)。

# 查看可用内核版本
yum list available --disablerepo='*' --enablerepo='elrepo-kernel' | grep kernel

# 安装 LTS 内核 (推荐)
yum --enablerepo=elrepo-kernel install -y kernel-lt

# 或者安装主线内核 (最新特性)
# yum --enablerepo=elrepo-kernel install -y kernel-ml

4. 设置默认启动项并重启

# 重新生成 GRUB 配置
grub2-mkconfig -o /boot/grub2/grub.cfg

# 设置默认启动第一个内核(通常是最新安装的)
grub2-set-default 0

# 重启系统
reboot

5. 验证内核版本

重启后登录系统,检查当前运行的内核版本。

uname -r


本文地址:https://tugouli.exiu.org/3756.html
版权声明:本文为原创文章,版权归 淹不死的狗 所有,欢迎分享本文,转载请保留出处!
NEXT:已经是最新一篇了

评论已关闭!